aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergio Martins <smartins@kde.org>2018-10-09 11:37:05 +0100
committerSergio Martins <smartins@kde.org>2018-10-09 11:37:05 +0100
commit6e5fee3730ad2e443d9ec93eb88f06ee7f8b33e2 (patch)
treeb183032eb69b1a094d2538c7f395964ff2757405
parentc417ff22f57915f8e1409519a41402c93f1cf5ea (diff)
empty-qstringliteral: Don't warn for uic generated files
Since 5.12 this is no longer an issue, since QStringLiteral was abolished from ui_*.h files. BUG: 399544
-rw-r--r--src/checks/level0/empty-qstringliteral.cpp17
-rw-r--r--src/checks/level0/empty-qstringliteral.h1
-rw-r--r--tests/empty-qstringliteral/main.cpp2
-rw-r--r--tests/empty-qstringliteral/ui_qstringliteral.h50
4 files changed, 69 insertions, 1 deletions
diff --git a/src/checks/level0/empty-qstringliteral.cpp b/src/checks/level0/empty-qstringliteral.cpp
index 359ccd03..492c9073 100644
--- a/src/checks/level0/empty-qstringliteral.cpp
+++ b/src/checks/level0/empty-qstringliteral.cpp
@@ -24,6 +24,9 @@
#include "HierarchyUtils.h"
#include "QtUtils.h"
#include "TypeUtils.h"
+#include "SourceCompatibilityHelpers.h"
+#include "PreProcessorVisitor.h"
+#include "ClazyContext.h"
#include <clang/AST/AST.h>
@@ -59,5 +62,19 @@ void EmptyQStringliteral::VisitStmt(clang::Stmt *stmt)
if (!getLocStart(stmt).isMacroID())
return;
+ if (maybeIgnoreUic(getLocStart(stmt)))
+ return;
+
emitWarning(stmt, "Use QString instead of an empty QStringLiteral");
}
+
+bool EmptyQStringliteral::maybeIgnoreUic(SourceLocation loc) const
+{
+ PreProcessorVisitor *preProcessorVisitor = m_context->preprocessorVisitor;
+
+ // Since 5.12 uic no longer uses QStringLiteral("")
+ if (preProcessorVisitor && preProcessorVisitor->qtVersion() >= 051200)
+ return false;
+
+ return clazy::isUIFile(loc, sm());
+}
diff --git a/src/checks/level0/empty-qstringliteral.h b/src/checks/level0/empty-qstringliteral.h
index d1acf6a2..c8155e2b 100644
--- a/src/checks/level0/empty-qstringliteral.h
+++ b/src/checks/level0/empty-qstringliteral.h
@@ -32,6 +32,7 @@ class EmptyQStringliteral : public CheckBase
public:
explicit EmptyQStringliteral(const std::string &name, ClazyContext *context);
void VisitStmt(clang::Stmt *) override;
+ bool maybeIgnoreUic(clang::SourceLocation) const;
private:
};
diff --git a/tests/empty-qstringliteral/main.cpp b/tests/empty-qstringliteral/main.cpp
index 0429205e..3439f1fb 100644
--- a/tests/empty-qstringliteral/main.cpp
+++ b/tests/empty-qstringliteral/main.cpp
@@ -1,6 +1,6 @@
#include <QtCore/QObject>
#include <QtCore/QString>
-
+#include "ui_qstringliteral.h" // OK
void test()
{
QStringLiteral("foo");
diff --git a/tests/empty-qstringliteral/ui_qstringliteral.h b/tests/empty-qstringliteral/ui_qstringliteral.h
new file mode 100644
index 00000000..0fb2675c
--- /dev/null
+++ b/tests/empty-qstringliteral/ui_qstringliteral.h
@@ -0,0 +1,50 @@
+/********************************************************************************
+** Form generated from reading UI file 'untitled.ui'
+**
+** Created by: Qt User Interface Compiler version 5.9.7
+**
+** WARNING! All changes made in this file will be lost when recompiling UI file!
+********************************************************************************/
+
+#ifndef UNTITLED_H
+#define UNTITLED_H
+
+#include <QtCore/QVariant>
+#include <QtWidgets/QAction>
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QButtonGroup>
+#include <QtWidgets/QHeaderView>
+#include <QtWidgets/QWidget>
+
+QT_BEGIN_NAMESPACE
+
+class Ui_Form
+{
+public:
+
+ void setupUi(QWidget *Form)
+ {
+ if (Form->objectName().isEmpty())
+ Form->setObjectName(QStringLiteral("Form"));
+ Form->resize(400, 300);
+ Form->setStyleSheet(QStringLiteral(""));
+
+ retranslateUi(Form);
+
+ QMetaObject::connectSlotsByName(Form);
+ } // setupUi
+
+ void retranslateUi(QWidget *Form)
+ {
+ Form->setWindowTitle(QApplication::translate("Form", "Form", Q_NULLPTR));
+ } // retranslateUi
+
+};
+
+namespace Ui {
+ class Form: public Ui_Form {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // UNTITLED_H