diff --git a/clang/lib/Tooling/Syntax/BuildTree.cpp b/clang/lib/Tooling/Syntax/BuildTree.cpp --- a/clang/lib/Tooling/Syntax/BuildTree.cpp +++ b/clang/lib/Tooling/Syntax/BuildTree.cpp @@ -624,6 +624,9 @@ } bool WalkUpFromDeclRefExpr(DeclRefExpr *S) { + if (S->getNameInfo().getName().getNameKind() == + clang::DeclarationName::CXXLiteralOperatorName) + return true; if (auto *NNS = BuildNestedNameSpecifier(S->getQualifierLoc())) Builder.markChild(NNS, syntax::NodeRole::IdExpression_qualifier); diff --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp --- a/clang/unittests/Tooling/Syntax/TreeTest.cpp +++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp @@ -1228,6 +1228,95 @@ )txt")); } +TEST_P(SyntaxTreeTest, UserDefinedLiteral) { + if (!GetParam().isCXX11OrLater()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +long double operator "" _w(long double); +unsigned operator "" _w(const char*); +template unsigned operator "" _x(); +int main() { + 1.2_w; // calls operator "" _w(1.2L) + 12_w; // calls operator "" _w("12") + 12_x; // calls operator<'1', '2'> "" _x() +} + )cpp", + R"txt( +*: TranslationUnit +|-SimpleDeclaration +| |-long +| |-double +| |-SimpleDeclarator +| | |-operator +| | |-"" +| | |-_w +| | `-ParametersAndQualifiers +| | |-( +| | |-SimpleDeclaration +| | | |-long +| | | `-double +| | `-) +| `-; +|-SimpleDeclaration +| |-unsigned +| |-SimpleDeclarator +| | |-operator +| | |-"" +| | |-_w +| | `-ParametersAndQualifiers +| | |-( +| | |-SimpleDeclaration +| | | |-const +| | | |-char +| | | `-SimpleDeclarator +| | | `-* +| | `-) +| `-; +|-TemplateDeclaration +| |-template +| |-< +| |-SimpleDeclaration +| | `-char +| |-... +| |-> +| `-SimpleDeclaration +| |-unsigned +| |-SimpleDeclarator +| | |-operator +| | |-"" +| | |-_x +| | `-ParametersAndQualifiers +| | |-( +| | `-) +| `-; +`-SimpleDeclaration + |-int + |-SimpleDeclarator + | |-main + | `-ParametersAndQualifiers + | |-( + | `-) + `-CompoundStatement + |-{ + |-ExpressionStatement + | |-UnknownExpression + | | `-UnknownExpression + | | `-1.2_w + | `-; + |-ExpressionStatement + | |-UnknownExpression + | | `-UnknownExpression + | | `-12_w + | `-; + |-ExpressionStatement + | |-UnknownExpression + | | `-12_x + | `-; + `-} +)txt")); +} TEST_P(SyntaxTreeTest, IntegerLiteral) { EXPECT_TRUE(treeDumpEqual( R"cpp(