summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tools/moc/moc.cpp7
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp8
2 files changed, 15 insertions, 0 deletions
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp
index f5700899fa..91aa97a443 100644
--- a/src/tools/moc/moc.cpp
+++ b/src/tools/moc/moc.cpp
@@ -1552,10 +1552,17 @@ void Moc::checkProperties(ClassDef *cdef)
// specify get function, for compatibiliy we accept functions
// returning pointers, or const char * for QByteArray.
//
+ QSet<QByteArray> definedProperties;
for (int i = 0; i < cdef->propertyList.count(); ++i) {
PropertyDef &p = cdef->propertyList[i];
if (p.read.isEmpty() && p.member.isEmpty())
continue;
+ if (definedProperties.contains(p.name)) {
+ QByteArray msg = "The property '" + p.name + "' is defined multiple times in class " + cdef->classname + ".";
+ warning(msg.constData());
+ }
+ definedProperties.insert(p.name);
+
for (int j = 0; j < cdef->publicList.count(); ++j) {
const FunctionDef &f = cdef->publicList.at(j);
if (f.name != p.read)
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index 9a737ef96b..97a2f366c5 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -1792,6 +1792,14 @@ void tst_Moc::warnings_data()
<< QString("IGNORE_ALL_STDOUT")
<< QString("standard input:1: Warning: Property declaration x has no READ accessor function or associated MEMBER variable. The property will be invalid.");
+ // This should output a warning
+ QTest::newRow("Duplicate property warning")
+ << QByteArray("class X : public QObject { Q_OBJECT Q_PROPERTY(int x READ x) Q_PROPERTY(int x READ y) };")
+ << QStringList()
+ << 0
+ << QString("IGNORE_ALL_STDOUT")
+ << QString("standard input:1: Warning: The property 'x' is defined multiple times in class X.");
+
// Passing "-nn" should NOT suppress the warning
QTest::newRow("Invalid property warning with -nn")
<< QByteArray("class X : public QObject { Q_OBJECT Q_PROPERTY(int x) };")