diff options
author | Fabian Kosmale <[email protected]> | 2023-07-25 10:33:25 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <[email protected]> | 2023-07-28 12:40:59 +0000 |
commit | ef8019af7db1abbdb686ce3599c76c8e8df4681b (patch) | |
tree | e1fd638ba022848737306ffe760fbbdd443d392f | |
parent | 0694496b62e6cc3316668aef7c05562ba2b88422 (diff) |
moc: handle "L" integer suffix
This commit adds some initial support for handling the 'L' suffix after
numbers. This one is especially important given that the __cplusplus
define is using it.
Other suffixes will be handled in some later commit, which should also
unify the already divergent parse behavior between DIGIT and PP_DIGIT
parsing (e.g. when it comes to byte prefixes).
Task-number: QTBUG-83160
Task-number: QTBUG-115558
Change-Id: Ie61eae49c468abfaee80e7e4f7097917a254dc0e
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: Thiago Macieira <[email protected]>
(cherry picked from commit f0039bd5170ad84d972a023316e8d153b89f841a)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
-rw-r--r-- | src/tools/moc/preprocessor.cpp | 12 | ||||
-rw-r--r-- | tests/auto/tools/moc/tst_moc.cpp | 5 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp index 647440425d0..486c969798f 100644 --- a/src/tools/moc/preprocessor.cpp +++ b/src/tools/moc/preprocessor.cpp @@ -223,7 +223,8 @@ Symbols Preprocessor::tokenize(const QByteArray& input, int lineNum, Preprocesso ++data; while (is_hex_char(*data) || *data == '\'') ++data; - } + } else if (*data == 'L') // TODO: handle other suffixes + ++data; break; } token = FLOATING_LITERAL; @@ -400,7 +401,8 @@ Symbols Preprocessor::tokenize(const QByteArray& input, int lineNum, Preprocesso ++data; while (is_hex_char(*data) || *data == '\'') ++data; - } + } else if (*data == 'L') // TODO: handle other suffixes + ++data; break; } token = PP_FLOATING_LITERAL; @@ -930,7 +932,11 @@ int PP_Expression::primary_expression() test(PP_RPAREN); } else { next(); - value = lexem().toInt(nullptr, 0); + const QByteArray &lex = lexem(); + auto lexView = QByteArrayView(lex); + if (lex.endsWith('L')) + lexView.chop(1); + value = lexView.toInt(nullptr, 0); } return value; } diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index a988579f890..ea65e40e144 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -592,6 +592,10 @@ private slots: QT_WARNING_POP +// quick test to verify that moc handles the L suffix +// correctly in the preprocessor +#if 2000L < 1 +#else class PropertyTestClass : public QObject { Q_OBJECT @@ -601,6 +605,7 @@ public: Q_ENUM(TestEnum) }; +#endif class PropertyUseClass : public QObject { |