diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-09-26 10:27:17 +0200 |
---|---|---|
committer | Daniel Smith <Daniel.Smith@qt.io> | 2022-11-17 11:19:11 +0000 |
commit | c2750da3431fa6e2e000526d399fd6427dbd11ac (patch) | |
tree | 77c8f7b3a9b4e042960b1bc120f4b9656907d8eb | |
parent | 0d6bff7d0f3dc04839deaa88300482c9e923535d (diff) | |
download | qtbase-c2750da3431fa6e2e000526d399fd6427dbd11ac.tar.gz |
moc: Add basic support for nested inline namespaces
This improves moc's support for nested inline namespaces, so that code
containing them will not break compilation.
For simplicity, we allow nested inline namespaces even in C++17 mode
(the actual C++ compiler will reject the code anyway, and probably with
a better error message than moc could output).
moc still has no real awareness how inline namespaces work, but that is
a preexisting issue.
Fixes: QTBUG-106920
Change-Id: I7b415a99133575f101bc81d01d4670a5f752917f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 5222df2be7d10bf44dfc2971774eadcb526b7a13)
Reviewed-by: Daniel Smith <Daniel.Smith@qt.io>
-rw-r--r-- | src/tools/moc/moc.cpp | 6 | ||||
-rw-r--r-- | tests/auto/tools/moc/tst_moc.cpp | 9 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index a8a1fb372c..461382092e 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -595,6 +595,12 @@ void Moc::parse() QByteArray nsName = lexem(); QByteArrayList nested; while (test(SCOPE)) { + /* treat (C++20's) namespace A::inline B {} as A::B + this is mostly to not break compilation when encountering such + a construct in a header; the interaction of Qt's meta-macros with + inline namespaces is still rather poor. + */ + test(INLINE); next(IDENTIFIER); nested.append(nsName); nsName = lexem(); diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index 7dc4f2ccdc..8862b0daf2 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -64,6 +64,15 @@ const char *string_hash_hash = STRING_HASH_HASH("baz"); #endif +#if defined(Q_MOC_RUN) || __cplusplus > 202002L +/* Check that nested inline namespaces are at least not causing moc to break. + Check it even outside of C++20 mode as moc gets passed the wrong __cplusplus version + and also to increase coverage, given how few C++20 configurations exist in the CI at the time + of writing this comment. +*/ +namespace A::inline B {} +#endif + Q_DECLARE_METATYPE(const QMetaObject*); #define TESTEXPORTMACRO Q_DECL_EXPORT |