summaryrefslogtreecommitdiff
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
commitd07517f0237f9eef0a426e6fabb668665a96461e (patch)
tree5ace9a5087e55ac3c82ef0356deefd5614e6e4fb
parent855be5f4a2462e64992c7414a6d77e283c872e0a (diff)
downloadqttools-d07517f0237f9eef0a426e6fabb668665a96461e.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.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 22891c6aa..21be8ddd1 100644
--- a/src/linguist/lupdate/cpp.cpp
+++ b/src/linguist/lupdate/cpp.cpp
@@ -886,7 +886,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;
}
@@ -904,7 +904,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;
+};