From 1989dbe0d7e3691f8bb903003204c2921b32f2ac Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 27 May 2020 15:09:04 +0200 Subject: Built-in lexer: Recognize also reserved user-defined literals Otherwise, we trip over uses of operators from the standard library such as std::chrono's operator"" ms(), potentially breaking basic code navigation. Amends 425811291d. Fixes: QTCREATORBUG-24067 Change-Id: I3b2863ce88ee3787414e7a1acdf25f368041cdb4 Reviewed-by: Nikolai Kosjar --- src/libs/3rdparty/cplusplus/Lexer.cpp | 2 +- tests/auto/cplusplus/cxx11/data/userDefinedLiterals.1.cpp | 2 +- tests/auto/cplusplus/lexer/tst_lexer.cpp | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/3rdparty/cplusplus/Lexer.cpp b/src/libs/3rdparty/cplusplus/Lexer.cpp index dc24f5e96c..89e0ce512d 100644 --- a/src/libs/3rdparty/cplusplus/Lexer.cpp +++ b/src/libs/3rdparty/cplusplus/Lexer.cpp @@ -939,7 +939,7 @@ bool Lexer::scanOptionalIntegerSuffix(bool allowU) void Lexer::scanOptionalUserDefinedLiteral(Token *tok) { - if (_languageFeatures.cxx11Enabled && _yychar == '_') { + if (_languageFeatures.cxx11Enabled && (_yychar == '_' || std::isalpha(_yychar))) { tok->f.userDefinedLiteral = true; while (std::isalnum(_yychar) || _yychar == '_' || isByteOfMultiByteCodePoint(_yychar)) yyinp(); diff --git a/tests/auto/cplusplus/cxx11/data/userDefinedLiterals.1.cpp b/tests/auto/cplusplus/cxx11/data/userDefinedLiterals.1.cpp index f194b3ed51..6352a82a28 100644 --- a/tests/auto/cplusplus/cxx11/data/userDefinedLiterals.1.cpp +++ b/tests/auto/cplusplus/cxx11/data/userDefinedLiterals.1.cpp @@ -3,5 +3,5 @@ constexpr long double operator"" _inv(long double value) { } int main() { auto foo = operator"" _inv(2.3); - return 12_km + 0.5_Pa + 'c'_X + "abd"_L + u"xyz"_M; + return 12_km + 0.5_Pa + 'c'_X + "abd"_L + u"xyz"_M + 10ms; } diff --git a/tests/auto/cplusplus/lexer/tst_lexer.cpp b/tests/auto/cplusplus/lexer/tst_lexer.cpp index 79548e6fd4..90a36c510c 100644 --- a/tests/auto/cplusplus/lexer/tst_lexer.cpp +++ b/tests/auto/cplusplus/lexer/tst_lexer.cpp @@ -619,6 +619,8 @@ void tst_SimpleLexer::user_defined_literals_data() << _("11_udl") << createToken(T_NUMERIC_LITERAL, 6, 6, true); QTest::newRow("numeric user-defined literal with decimal part") << _("11.1_udl") << createToken(T_NUMERIC_LITERAL, 8, 8, true); + QTest::newRow("numeric user-defined reserved literal") + << _("11ms") << createToken(T_NUMERIC_LITERAL, 4, 4, true); } static Token createToken(unsigned kind, unsigned byteOffset, unsigned bytes, -- cgit v1.2.1