diff --git a/clang/lib/Tooling/Syntax/BuildTree.cpp b/clang/lib/Tooling/Syntax/BuildTree.cpp index 2e9e74401e71e0..a9f326439a2a57 100644 --- a/clang/lib/Tooling/Syntax/BuildTree.cpp +++ b/clang/lib/Tooling/Syntax/BuildTree.cpp @@ -200,6 +200,7 @@ static syntax::NodeKind getOperatorNodeKind(const CXXOperatorCallExpr &E) { /// Get the start of the qualified name. In the examples below it gives the /// location of the `^`: /// `int ^a;` +/// `int *^a;` /// `int ^a::S::f(){}` static SourceLocation getQualifiedNameStart(NamedDecl *D) { assert((isa(D)) && @@ -242,7 +243,7 @@ static SourceRange getInitializerRange(Decl *D) { /// `int a[1][2][3];` -> range of `a[1][2][3]`, /// `int *a = nullptr` -> range of `*a = nullptr`. /// `int S::f(){}` -> range of `S::f()`. -/// FIXME: \p Name must be a source range, e.g. for `operator+`. +/// FIXME: \p Name must be a source range. static SourceRange getDeclaratorRange(const SourceManager &SM, TypeLoc T, SourceLocation Name, SourceRange Initializer) { diff --git a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp index a07187e22e930c..aab20008a49748 100644 --- a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp +++ b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp @@ -3123,6 +3123,35 @@ SimpleDeclaration )txt"})); } +TEST_P(SyntaxTreeTest, OutOfLineMemberFunctionDefinition) { + if (!GetParam().isCXX11OrLater()) { + return; + } + EXPECT_TRUE(treeDumpEqualOnAnnotations( + R"cpp( +struct S { + void f(); +}; +[[void S::f(){}]] +)cpp", + {R"txt( +SimpleDeclaration +|-'void' +|-SimpleDeclarator Declarator +| |-NestedNameSpecifier +| | |-IdentifierNameSpecifier ListElement +| | | `-'S' +| | `-'::' ListDelimiter +| |-'f' +| `-ParametersAndQualifiers +| |-'(' OpenParen +| `-')' CloseParen +`-CompoundStatement + |-'{' OpenParen + `-'}' CloseParen +)txt"})); +} + TEST_P(SyntaxTreeTest, ConversionMemberFunction) { if (!GetParam().isCXX()) { return; @@ -3792,6 +3821,53 @@ TranslationUnit Detached )txt")); } +TEST_P(SyntaxTreeTest, InitDeclarator_Brace) { + if (!GetParam().isCXX11OrLater()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +int a {}; +)cpp", + R"txt( +TranslationUnit Detached +`-SimpleDeclaration + |-'int' + |-SimpleDeclarator Declarator + | |-'a' + | `-UnknownExpression + | `-UnknownExpression + | |-'{' + | `-'}' + `-';' +)txt")); +} + +TEST_P(SyntaxTreeTest, InitDeclarator_Paren) { + if (!GetParam().isCXX()) { + return; + } + EXPECT_TRUE(treeDumpEqualOnAnnotations( + R"cpp( +struct S { + S(int); +}; +[[S s(1);]] +)cpp", + {R"txt( +SimpleDeclaration +|-'S' +|-SimpleDeclarator Declarator +| `-UnknownExpression +| |-'s' +| |-'(' +| |-IntegerLiteralExpression +| | `-'1' LiteralToken +| `-')' +`-';' +)txt"})); +} + TEST_P(SyntaxTreeTest, ArrayDeclarator_Simple) { EXPECT_TRUE(treeDumpEqual( R"cpp(