summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2022-01-06 13:12:24 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-01-19 11:13:57 +0000
commite51b322f167bf663258a67dc0904595430429366 (patch)
tree4653c204c12d16d97016eaa2849eff546b88e25f
parent1e863772d902254afe80a629034cdc18f47bf486 (diff)
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.cpp4
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp2/main.cpp7
2 files changed, 9 insertions, 2 deletions
diff --git a/src/linguist/lupdate/cpp.cpp b/src/linguist/lupdate/cpp.cpp
index d434cf123..8c9e72b06 100644
--- a/src/linguist/lupdate/cpp.cpp
+++ b/src/linguist/lupdate/cpp.cpp
@@ -889,7 +889,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;
}
@@ -907,7 +907,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 efaac791f..0372de39a 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;
+};