diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 0afef106821d9..12bedae05f6f3 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -18050,7 +18050,8 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, } } } else if (auto *RD = dyn_cast(PrevDecl); - RD && RD->isInjectedClassName()) { + TUK == TagUseKind::Reference && RD && + RD->isInjectedClassName()) { // If lookup found the injected class name, the previous declaration is // the class being injected into. PrevDecl = cast(RD->getDeclContext()); diff --git a/clang/test/AST/ast-dump-decl.cpp b/clang/test/AST/ast-dump-decl.cpp index 849bfbee2ab21..afb507833d869 100644 --- a/clang/test/AST/ast-dump-decl.cpp +++ b/clang/test/AST/ast-dump-decl.cpp @@ -990,3 +990,18 @@ namespace TestInjectedClassName { // CHECK-NEXT: `-RecordType [[TestInjectedClassName_RT]] 'A' injected // CHECK-NEXT: `-CXXRecord [[TestInjectedClassName_RD]] 'A' } // namespace InjectedClassName + +namespace TestGH155936 { + struct Foo { + struct A { + struct Foo {}; + }; + }; + // CHECK-LABEL: Dumping TestGH155936: + // CHECK: CXXRecordDecl 0x{{.+}} <{{.+}}> line:[[@LINE-6]]:10 struct Foo definition + // CHECK: CXXRecordDecl 0x{{.+}} col:10 implicit struct Foo + // CHECK: CXXRecordDecl 0x{{.+}} <{{.+}}> line:[[@LINE-7]]:12 struct A definition + // CHECK: CXXRecordDecl 0x{{.+}} col:12 implicit struct A + // CHECK: CXXRecordDecl 0x{{.+}} col:14 struct Foo definition + // CHECH: CXXRecordDecl 0x{{.+}} col:16 implicit struct Foo +} // namspace GH155936