diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2022-01-06 13:12:24 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-01-19 11:28:57 +0000 |
commit | b1eb97e3658fd153bd3742039b7fb62fa74aafba (patch) | |
tree | ab7dbe6fc103e243c88f5d88d4dad79cfe991d2f | |
parent | 6a05c1ac8b73bc009da6cef62eb1ff180811f5f7 (diff) | |
download | qttools-b1eb97e3658fd153bd3742039b7fb62fa74aafba.tar.gz |
lupdate: Support numeric literal separators
Numeric literals that use apostrophes were introduced in C++14 so this
adds support for cases like:
int d = 10'000'00;
int x = 0xAF'FE;
This patch allows just any number and combination of apostrophes in
numeric literals and doesn't attempt to detect ill-formed literals. We
assume, lupdate runs on code that has been accepted by a C++ compiler.
Task-number: QTBUG-53326
Change-Id: I23bd9b4c676694dc69199e4a17a612a011449e61
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
(cherry picked from commit c2d1163004078b98abc86318f45a6796aef18811)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/linguist/lupdate/cpp.cpp | 4 | ||||
-rw-r--r-- | tests/auto/linguist/lupdate/testdata/good/parsecpp2/main.cpp | 7 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/linguist/lupdate/cpp.cpp b/src/linguist/lupdate/cpp.cpp index 07ffd49ae..068273cda 100644 --- a/src/linguist/lupdate/cpp.cpp +++ b/src/linguist/lupdate/cpp.cpp @@ -887,7 +887,7 @@ CppParser::TokenType CppParser::getToken() if (yyCh == 'x') { do { yyCh = getChar(); - } while ((yyCh >= '0' && yyCh <= '9') + } while ((yyCh >= '0' && yyCh <= '9') || yyCh == '\'' || (yyCh >= 'a' && yyCh <= 'f') || (yyCh >= 'A' && yyCh <= 'F')); return Tok_Integer; } @@ -905,7 +905,7 @@ CppParser::TokenType CppParser::getToken() case '9': do { yyCh = getChar(); - } while (yyCh >= '0' && yyCh <= '9'); + } while ((yyCh >= '0' && yyCh <= '9') || yyCh == '\''); return Tok_Integer; default: yyCh = getChar(); diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp2/main.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp2/main.cpp index dec5232fc..9e0136258 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsecpp2/main.cpp +++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp2/main.cpp @@ -139,3 +139,10 @@ const QString nodelimiter(QObject::tr(R"( const Qstring withdelimiter = QObject::tr(R"delim( This is a test string )delim"); + + +// New in C++14: integer literals may contain single quotes as separator. +struct IntLiteralsWithSeparators { + long d = 10'000'000'0'00; + int x = 0x1'AF'FE; +}; |