Fix moc'ing of enum class flags

Keep the original class name around for a little longer so we can
generate the correct scoped enum in the moc output.

Task-number: QTBUG-47652
Change-Id: Ib5934316fa786cc475335b03c86b8ec2dc239055
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Allan Sandfeld Jensen 2018-07-25 18:02:09 +02:00
parent 89f784757e
commit 9ce4006565
4 changed files with 12 additions and 1 deletions

View File

@ -202,6 +202,7 @@ void Generator::generateCode()
}
QByteArray alias = cdef->flagAliases.value(def.name);
if (cdef->enumDeclarations.contains(alias)) {
def.className = def.name;
def.name = alias;
enumList += def;
}
@ -922,7 +923,7 @@ void Generator::generateEnums(int index)
const QByteArray &val = e.values.at(j);
QByteArray code = cdef->qualified.constData();
if (e.isEnumClass)
code += "::" + e.name;
code += "::" + (e.className.isNull() ? e.name : e.className);
code += "::" + val;
fprintf(out, " %4d, uint(%s),\n",
stridx(val), code.constData());

View File

@ -64,6 +64,7 @@ Q_DECLARE_TYPEINFO(Type, Q_MOVABLE_TYPE);
struct EnumDef
{
QByteArray name;
QByteArray className;
QList<QByteArray> values;
bool isEnumClass; // c++11 enum class
EnumDef() : isEnumClass(false) {}

View File

@ -39,10 +39,14 @@ public:
enum TypedEnum : char { B0, B1 , B2, B3 };
enum class TypedEnumClass : char { C0, C1, C2, C3 };
enum NormalEnum { D2 = 2, D3, D0 =0 , D1 };
enum class ClassFlag { F0, F1, F2, F3 };
Q_DECLARE_FLAGS(ClassFlags, ClassFlag)
Q_ENUM(EnumClass)
Q_ENUM(TypedEnum)
Q_ENUM(TypedEnumClass)
Q_ENUM(NormalEnum)
Q_FLAG(ClassFlags)
};
// Also test the Q_ENUMS macro
@ -54,7 +58,10 @@ public:
enum TypedEnum : char { B0, B1 , B2, B3 };
enum class TypedEnumClass : char { C0, C1, C2, C3 };
enum NormalEnum { D2 = 2, D3, D0 =0 , D1 };
enum class ClassFlag { F0, F1, F2, F3 };
Q_DECLARE_FLAGS(ClassFlags, ClassFlag)
Q_ENUMS(EnumClass TypedEnum TypedEnumClass NormalEnum)
Q_FLAGS(ClassFlags)
};
#else

View File

@ -2263,6 +2263,8 @@ void tst_Moc::cxx11Enums_data()
QTest::newRow("TypedEnumClass 2") << meta2 << QByteArray("TypedEnumClass") << 'C' << true;
QTest::newRow("NormalEnum") << meta1 << QByteArray("NormalEnum") << 'D' << false;
QTest::newRow("NormalEnum 2") << meta2 << QByteArray("NormalEnum") << 'D' << false;
QTest::newRow("ClassFlags") << meta1 << QByteArray("ClassFlags") << 'F' << true;
QTest::newRow("ClassFlags 2") << meta2 << QByteArray("ClassFlags") << 'F' << true;
}
void tst_Moc::cxx11Enums()