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 <nikolai.kosjar@qt.io>
This commit is contained in:
Christian Kandeler
2020-05-27 15:09:04 +02:00
parent 45b96d12e5
commit 1989dbe0d7
3 changed files with 4 additions and 2 deletions

View File

@@ -939,7 +939,7 @@ bool Lexer::scanOptionalIntegerSuffix(bool allowU)
void Lexer::scanOptionalUserDefinedLiteral(Token *tok) void Lexer::scanOptionalUserDefinedLiteral(Token *tok)
{ {
if (_languageFeatures.cxx11Enabled && _yychar == '_') { if (_languageFeatures.cxx11Enabled && (_yychar == '_' || std::isalpha(_yychar))) {
tok->f.userDefinedLiteral = true; tok->f.userDefinedLiteral = true;
while (std::isalnum(_yychar) || _yychar == '_' || isByteOfMultiByteCodePoint(_yychar)) while (std::isalnum(_yychar) || _yychar == '_' || isByteOfMultiByteCodePoint(_yychar))
yyinp(); yyinp();

View File

@@ -3,5 +3,5 @@ constexpr long double operator"" _inv(long double value) {
} }
int main() { int main() {
auto foo = operator"" _inv(2.3); 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;
} }

View File

@@ -619,6 +619,8 @@ void tst_SimpleLexer::user_defined_literals_data()
<< _("11_udl") << createToken(T_NUMERIC_LITERAL, 6, 6, true); << _("11_udl") << createToken(T_NUMERIC_LITERAL, 6, 6, true);
QTest::newRow("numeric user-defined literal with decimal part") QTest::newRow("numeric user-defined literal with decimal part")
<< _("11.1_udl") << createToken(T_NUMERIC_LITERAL, 8, 8, true); << _("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, static Token createToken(unsigned kind, unsigned byteOffset, unsigned bytes,