diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp --- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -1300,6 +1300,19 @@ "text[Typedef]", }, { + R"cpp(// Typedef with embedded definition + typedef struct Bar {} Foo; + int main() { + ^Foo bar; + } + )cpp", + "text[Declared in]code[global namespace]\n" + "codeblock(cpp) [\n" + "typedef struct Bar Foo\n" + "]\n" + "text[Typedef with embedded definition]", + }, + { R"cpp(// Namespace namespace ns { struct Foo { static void bar(); } diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -163,7 +163,9 @@ if (isa(D) || isa(D) || isa(D) || isa(D) || - isa(D)) + isa(D) || + // Allow association with Y across {} in `typedef struct X {} Y`. + isa(D)) return D->getBeginLoc(); else { const SourceLocation DeclLoc = D->getLocation(); diff --git a/clang/test/Index/annotate-comments-typedef.m b/clang/test/Index/annotate-comments-typedef.m --- a/clang/test/Index/annotate-comments-typedef.m +++ b/clang/test/Index/annotate-comments-typedef.m @@ -17,7 +17,7 @@ MyEnumBar, /**< value Bar */ MyEnumBaz, /**< value Baz */ } MyEnum; -// CHECK: TypedefDecl=MyEnum:[[@LINE-1]]:3 (Definition) FullCommentAsHTML=[

Documentation for MyEnum

] FullCommentAsXML=[<anonymous>c:@EA@MyEnumtypedef enum MyEnum MyEnum Documentation for MyEnum ] +// CHECK: TypedefDecl=MyEnum:[[@LINE-1]]:3 (Definition) {{.*}} FullCommentAsHTML=[

Documentation for MyEnum

] FullCommentAsXML=[MyEnumc:@T@MyEnumtypedef enum MyEnum MyEnum Documentation for MyEnum ] /** Documentation for E */ @@ -35,7 +35,7 @@ typedef struct { int iii; } Foo; -// CHECK: TypedefDecl=Foo:[[@LINE-1]]:11 (Definition) FullCommentAsHTML=[

Comment about Foo

] FullCommentAsXML=[<anonymous>c:@SA@Footypedef struct Foo Foo Comment about Foo ] +// CHECK: TypedefDecl=Foo:[[@LINE-1]]:11 (Definition) {{.*}} FullCommentAsHTML=[

Comment about Foo

] FullCommentAsXML=[Fooc:@T@Footypedef struct Foo Foo Comment about Foo ] // CHECK: StructDecl=:[[@LINE-4]]:9 (Definition) {{.*}} BriefComment=[Comment about Foo] FullCommentAsHTML=[

Comment about Foo

] FullCommentAsXML=[<anonymous>c:@SA@Foostruct {} Comment about Foo ] diff --git a/clang/test/Sema/warn-documentation.cpp b/clang/test/Sema/warn-documentation.cpp --- a/clang/test/Sema/warn-documentation.cpp +++ b/clang/test/Sema/warn-documentation.cpp @@ -868,7 +868,7 @@ /// \brief\author Aaa typedef struct test_noattach14 *test_attach15; -// expected-warning@+1 {{empty paragraph passed to '\brief' command}} +// expected-warning@+1 + {{empty paragraph passed to '\brief' command}} /// \brief\author Aaa typedef struct test_attach16 { int a; } test_attach17; @@ -886,7 +886,7 @@ /// \brief\author Aaa struct test_attach20; -// expected-warning@+1 {{empty paragraph passed to '\brief' command}} +// expected-warning@+1 + {{empty paragraph passed to '\brief' command}} /// \brief\author Aaa typedef struct test_attach21 { // expected-warning@+1 {{empty paragraph passed to '\brief' command}}