Check the context of Q_ENUM[_NS] and Q_FLAG[_NS]

Change-Id: Ifc8cb50efe3b07a79c8afbb382fba12649b602b2
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
BogDan Vatra 2016-08-19 16:58:49 +03:00
parent 0a4d3a9218
commit bee70b24c1
2 changed files with 40 additions and 0 deletions

View File

@ -570,10 +570,16 @@ void Moc::parse()
case Q_ENUM_NS_TOKEN: case Q_ENUM_NS_TOKEN:
parseEnumOrFlag(&def, false); parseEnumOrFlag(&def, false);
break; break;
case Q_ENUM_TOKEN:
error("Q_ENUM can't be used in a Q_NAMESPACE, use Q_ENUM_NS instead");
break;
case Q_FLAGS_TOKEN: case Q_FLAGS_TOKEN:
case Q_FLAG_NS_TOKEN: case Q_FLAG_NS_TOKEN:
parseEnumOrFlag(&def, true); parseEnumOrFlag(&def, true);
break; break;
case Q_FLAG_TOKEN:
error("Q_FLAG can't be used in a Q_NAMESPACE, use Q_FLAG_NS instead");
break;
case Q_DECLARE_FLAGS_TOKEN: case Q_DECLARE_FLAGS_TOKEN:
parseFlag(&def); parseFlag(&def);
break; break;
@ -736,10 +742,16 @@ void Moc::parse()
case Q_ENUM_TOKEN: case Q_ENUM_TOKEN:
parseEnumOrFlag(&def, false); parseEnumOrFlag(&def, false);
break; break;
case Q_ENUM_NS_TOKEN:
error("Q_ENUM_NS can't be used in a Q_OBJECT/Q_GADGET, use Q_ENUM instead");
break;
case Q_FLAGS_TOKEN: case Q_FLAGS_TOKEN:
case Q_FLAG_TOKEN: case Q_FLAG_TOKEN:
parseEnumOrFlag(&def, true); parseEnumOrFlag(&def, true);
break; break;
case Q_FLAG_NS_TOKEN:
error("Q_FLAG_NS can't be used in a Q_OBJECT/Q_GADGET, use Q_FLAG instead");
break;
case Q_DECLARE_FLAGS_TOKEN: case Q_DECLARE_FLAGS_TOKEN:
parseFlag(&def); parseFlag(&def);
break; break;

View File

@ -2083,6 +2083,34 @@ void tst_Moc::warnings_data()
<< QString() << QString()
<< QString("standard input:1: Error: Namespace declaration lacks Q_NAMESPACE macro."); << QString("standard input:1: Error: Namespace declaration lacks Q_NAMESPACE macro.");
QTest::newRow("Wrong Q_ENUM context.")
<< QByteArray("namespace X {\nQ_NAMESPACE\n\nenum class MyEnum {Key1 = 1}\nQ_ENUM(MyEnum)\n}\n")
<< QStringList()
<< 1
<< QString()
<< QString("standard input:5: Error: Q_ENUM can't be used in a Q_NAMESPACE, use Q_ENUM_NS instead");
QTest::newRow("Wrong Q_FLAG context.")
<< QByteArray("namespace X {\nQ_NAMESPACE\n\nenum class MyEnum {Key1 = 1}\nQ_FLAG(MyEnum)\n}\n")
<< QStringList()
<< 1
<< QString()
<< QString("standard input:5: Error: Q_FLAG can't be used in a Q_NAMESPACE, use Q_FLAG_NS instead");
QTest::newRow("Wrong Q_ENUM_NS context.")
<< QByteArray("class X {\nQ_GADGET\n\nenum class MyEnum {Key1 = 1}\nQ_ENUM_NS(MyEnum)\n};\n")
<< QStringList()
<< 1
<< QString()
<< QString("standard input:5: Error: Q_ENUM_NS can't be used in a Q_OBJECT/Q_GADGET, use Q_ENUM instead");
QTest::newRow("Wrong Q_FLAG_NS context.")
<< QByteArray("class X {\nQ_GADGET\n\nenum class MyEnum {Key1 = 1}\nQ_FLAG_NS(MyEnum)\n};\n")
<< QStringList()
<< 1
<< QString()
<< QString("standard input:5: Error: Q_FLAG_NS can't be used in a Q_OBJECT/Q_GADGET, use Q_FLAG instead");
QTest::newRow("Invalid macro definition") QTest::newRow("Invalid macro definition")
<< QByteArray("#define Foo(a, b, c) a b c #a #b #c a##b##c #d\n Foo(45, 42, 39);") << QByteArray("#define Foo(a, b, c) a b c #a #b #c a##b##c #d\n Foo(45, 42, 39);")
<< QStringList() << QStringList()