forked from qt-creator/qt-creator
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:
2
src/libs/3rdparty/cplusplus/Lexer.cpp
vendored
2
src/libs/3rdparty/cplusplus/Lexer.cpp
vendored
@@ -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();
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user