diff --git a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp index 5b1630eb00cb1..217305a7c60c2 100644 --- a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp +++ b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp @@ -106,7 +106,7 @@ TEST(WorkspaceSymbols, Unnamed) { ElementsAre(AllOf(qName("UnnamedStruct"), withKind(SymbolKind::Variable)))); EXPECT_THAT(getSymbols(TU, "InUnnamed"), - ElementsAre(AllOf(qName("(anonymous struct)::InUnnamed"), + ElementsAre(AllOf(qName("(unnamed struct)::InUnnamed"), withKind(SymbolKind::Field)))); } diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp index 1ce28c91a420c..94116fca3cbb2 100644 --- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -1470,8 +1470,8 @@ TEST_F(SymbolCollectorTest, NamelessSymbols) { } Foo; )"; runSymbolCollector(Header, /*Main=*/""); - EXPECT_THAT(Symbols, UnorderedElementsAre(qName("Foo"), - qName("(anonymous struct)::a"))); + EXPECT_THAT(Symbols, + UnorderedElementsAre(qName("Foo"), qName("(unnamed struct)::a"))); } TEST_F(SymbolCollectorTest, SymbolFormedFromRegisteredSchemeFromMacro) { diff --git a/clang/include/clang/AST/TypeBase.h b/clang/include/clang/AST/TypeBase.h index f07861f50fe8c..2f27deda2cd66 100644 --- a/clang/include/clang/AST/TypeBase.h +++ b/clang/include/clang/AST/TypeBase.h @@ -7374,6 +7374,10 @@ bool isSubstitutedDefaultArgument(ASTContext &Ctx, TemplateArgument Arg, ArrayRef Args, unsigned Depth); +void printAnonymousTagDecl(llvm::raw_ostream &OS, const TagDecl *D, + const PrintingPolicy &Policy, + bool PrintKindDecoration, bool PrintTagLocations); + /// Represents a qualified type name for which the type name is /// dependent. /// diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 591457b1d66b4..c9bb414a9a1de 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -35,6 +35,7 @@ #include "clang/AST/Stmt.h" #include "clang/AST/TemplateBase.h" #include "clang/AST/Type.h" +#include "clang/AST/TypeBase.h" #include "clang/AST/TypeLoc.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/IdentifierTable.h" @@ -1793,7 +1794,9 @@ void NamedDecl::printNestedNameSpecifier(raw_ostream &OS, if (TypedefNameDecl *TD = RD->getTypedefNameForAnonDecl()) OS << *TD; else if (!RD->getIdentifier()) - OS << "(anonymous " << RD->getKindName() << ')'; + printAnonymousTagDecl(OS, llvm::cast(RD), P, + /*PrintKindDecoration=*/true, + /*AllowSourceLocations=*/false); else OS << *RD; } else if (const auto *FD = dyn_cast(DC)) { diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index d2881d5ac518a..93bd068ccee08 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -23,6 +23,7 @@ #include "clang/AST/TemplateBase.h" #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" +#include "clang/AST/TypeBase.h" #include "clang/Basic/AddressSpaces.h" #include "clang/Basic/AttrKinds.h" #include "clang/Basic/ExceptionSpecificationType.h" @@ -1518,11 +1519,11 @@ void TypePrinter::printTagType(const TagType *T, raw_ostream &OS) { return; } - bool HasKindDecoration = false; + bool PrintKindDecoration = Policy.AnonymousTagLocations; if (T->isCanonicalUnqualified()) { if (!Policy.SuppressTagKeyword && !D->getTypedefNameForAnonDecl()) { - HasKindDecoration = true; + PrintKindDecoration = false; OS << D->getKindName(); OS << ' '; } @@ -1546,51 +1547,10 @@ void TypePrinter::printTagType(const TagType *T, raw_ostream &OS) { else if (TypedefNameDecl *Typedef = D->getTypedefNameForAnonDecl()) { assert(Typedef->getIdentifier() && "Typedef without identifier?"); OS << Typedef->getIdentifier()->getName(); - } else { - // Make an unambiguous representation for anonymous types, e.g. - // (anonymous enum at /usr/include/string.h:120:9) - OS << (Policy.MSVCFormatting ? '`' : '('); - - if (isa(D) && cast(D)->isLambda()) { - OS << "lambda"; - HasKindDecoration = true; - } else if ((isa(D) && cast(D)->isAnonymousStructOrUnion())) { - OS << "anonymous"; - } else { - OS << "unnamed"; - } - - if (Policy.AnonymousTagLocations) { - // Suppress the redundant tag keyword if we just printed one. - // We don't have to worry about ElaboratedTypes here because you can't - // refer to an anonymous type with one. - if (!HasKindDecoration) - OS << " " << D->getKindName(); - - PresumedLoc PLoc = D->getASTContext().getSourceManager().getPresumedLoc( - D->getLocation()); - if (PLoc.isValid()) { - OS << " at "; - StringRef File = PLoc.getFilename(); - llvm::SmallString<1024> WrittenFile(File); - if (auto *Callbacks = Policy.Callbacks) - WrittenFile = Callbacks->remapPath(File); - // Fix inconsistent path separator created by - // clang::DirectoryLookup::LookupFile when the file path is relative - // path. - llvm::sys::path::Style Style = - llvm::sys::path::is_absolute(WrittenFile) - ? llvm::sys::path::Style::native - : (Policy.MSVCFormatting - ? llvm::sys::path::Style::windows_backslash - : llvm::sys::path::Style::posix); - llvm::sys::path::native(WrittenFile, Style); - OS << WrittenFile << ':' << PLoc.getLine() << ':' << PLoc.getColumn(); - } - } - - OS << (Policy.MSVCFormatting ? '\'' : ')'); - } + } else + printAnonymousTagDecl(OS, D, Policy, + /*PrintKindDecoration=*/PrintKindDecoration, + /*PrintTagLocations=*/Policy.AnonymousTagLocations); // If this is a class template specialization, print the template // arguments. @@ -2469,6 +2429,58 @@ static bool isSubstitutedTemplateArgument(ASTContext &Ctx, TemplateArgument Arg, return false; } +void clang::printAnonymousTagDecl(llvm::raw_ostream &OS, const TagDecl *D, + const PrintingPolicy &Policy, + bool PrintKindDecoration, + bool PrintTagLocations) { + assert(D); + + // Make an unambiguous representation for anonymous types, e.g. + // (anonymous enum at /usr/include/string.h:120:9) + OS << (Policy.MSVCFormatting ? '`' : '('); + + if (isa(D) && cast(D)->isLambda()) { + PrintKindDecoration = false; + OS << "lambda"; + } else if ((isa(D) && + cast(D)->isAnonymousStructOrUnion())) { + OS << "anonymous"; + } else { + OS << "unnamed"; + } + + // Suppress the redundant tag keyword if we just printed one. + // We don't have to worry about ElaboratedTypes here because you can't + // refer to an anonymous type with one. + if (PrintKindDecoration) + OS << " " << D->getKindName(); + + if (PrintTagLocations) { + PresumedLoc PLoc = + D->getASTContext().getSourceManager().getPresumedLoc(D->getLocation()); + if (PLoc.isValid()) { + OS << " at "; + StringRef File = PLoc.getFilename(); + llvm::SmallString<1024> WrittenFile(File); + if (auto *Callbacks = Policy.Callbacks) + WrittenFile = Callbacks->remapPath(File); + // Fix inconsistent path separator created by + // clang::DirectoryLookup::LookupFile when the file path is relative + // path. + llvm::sys::path::Style Style = + llvm::sys::path::is_absolute(WrittenFile) + ? llvm::sys::path::Style::native + : (Policy.MSVCFormatting + ? llvm::sys::path::Style::windows_backslash + : llvm::sys::path::Style::posix); + llvm::sys::path::native(WrittenFile, Style); + OS << WrittenFile << ':' << PLoc.getLine() << ':' << PLoc.getColumn(); + } + } + + OS << (Policy.MSVCFormatting ? '\'' : ')'); +} + bool clang::isSubstitutedDefaultArgument(ASTContext &Ctx, TemplateArgument Arg, const NamedDecl *Param, ArrayRef Args, diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp index 0874b3d0c45f5..e83a6e97ec638 100644 --- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp +++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -18,6 +18,7 @@ #include "clang/AST/ExprConcepts.h" #include "clang/AST/ParentMapContext.h" #include "clang/AST/PrettyPrinter.h" +#include "clang/AST/TypeBase.h" #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Basic/LLVM.h" #include "clang/Lex/Lexer.h" @@ -514,7 +515,14 @@ static StringRef getNodeName(const RecordDecl &Node, return Node.getName(); } Scratch.clear(); - return ("(anonymous " + Node.getKindName() + ")").toStringRef(Scratch); + + llvm::raw_svector_ostream OS(Scratch); + + printAnonymousTagDecl( + OS, llvm::cast(&Node), Node.getASTContext().getPrintingPolicy(), + /*PrintKindDecoration=*/true, /*PrintTagLocations=*/false); + + return OS.str(); } static StringRef getNodeName(const NamespaceDecl &Node, diff --git a/clang/test/ASTMerge/struct/test.c b/clang/test/ASTMerge/struct/test.c index d11234472ef29..fe500e6b1ba82 100644 --- a/clang/test/ASTMerge/struct/test.c +++ b/clang/test/ASTMerge/struct/test.c @@ -44,10 +44,10 @@ // CHECK: struct2.c:72:7: note: field 'i' has type 'int' here // CHECK: struct2.c:76:5: warning: external variable 'x13' declared with incompatible types in different translation units ('S13' vs. 'S13') // CHECK: struct1.c:79:5: note: declared here with type 'S13' -// CHECK: struct1.c:130:7: warning: type 'struct DeepUnnamedError::(anonymous union)::(anonymous union)::(unnamed at [[PATH_TO_INPUTS:.+]]struct1.c:130:7)' has incompatible definitions in different translation units +// CHECK: struct1.c:130:7: warning: type 'struct DeepUnnamedError::(unnamed union)::(unnamed union)::(unnamed at [[PATH_TO_INPUTS:.+]]struct1.c:130:7)' has incompatible definitions in different translation units // CHECK: struct1.c:131:14: note: field 'i' has type 'long' here // CHECK: struct2.c:128:15: note: field 'i' has type 'float' here -// CHECK: struct1.c:129:5: warning: type 'union DeepUnnamedError::(anonymous union)::(unnamed at [[PATH_TO_INPUTS]]struct1.c:129:5)' has incompatible definitions in different translation units +// CHECK: struct1.c:129:5: warning: type 'union DeepUnnamedError::(unnamed union)::(unnamed at [[PATH_TO_INPUTS]]struct1.c:129:5)' has incompatible definitions in different translation units // CHECK: struct1.c:132:9: note: field 'S' has type 'struct (unnamed struct at [[PATH_TO_INPUTS]]struct1.c:130:7)' here // CHECK: struct2.c:129:9: note: field 'S' has type 'struct (unnamed struct at [[PATH_TO_INPUTS]]struct2.c:127:7)' here // CHECK: struct2.c:138:3: warning: external variable 'x16' declared with incompatible types in different translation units ('struct DeepUnnamedError' vs. 'struct DeepUnnamedError') diff --git a/clang/test/Analysis/Inputs/expected-plists/lambda-notes.cpp.plist b/clang/test/Analysis/Inputs/expected-plists/lambda-notes.cpp.plist index 5c7768cb97ef4..d5859dca9630b 100644 --- a/clang/test/Analysis/Inputs/expected-plists/lambda-notes.cpp.plist +++ b/clang/test/Analysis/Inputs/expected-plists/lambda-notes.cpp.plist @@ -174,7 +174,7 @@ typeDivision by zero check_namecore.DivideZero - issue_hash_content_of_line_in_contextbd4eed3234018edced5efc2ed5562a74 + issue_hash_content_of_line_in_contextd3cd158ad0fd8ce44df89c6779a1faec issue_context_kindC++ method issue_contextoperator() issue_hash_function_offset1 diff --git a/clang/test/Analysis/analyzer-note-analysis-entry-points.cpp b/clang/test/Analysis/analyzer-note-analysis-entry-points.cpp index 7d321bfae61c9..d0cf3a334e647 100644 --- a/clang/test/Analysis/analyzer-note-analysis-entry-points.cpp +++ b/clang/test/Analysis/analyzer-note-analysis-entry-points.cpp @@ -51,10 +51,10 @@ void checkASTCodeBodyHasAnalysisEntryPoints() { } void notInvokedLambdaScope() { - // CHECK: note: [debug] analyzing from notInvokedLambdaScope()::(anonymous class)::operator()() + // CHECK: note: [debug] analyzing from notInvokedLambdaScope()::(lambda)::operator()() // CHECK-NEXT: | auto notInvokedLambda = []() { // CHECK-NEXT: | ^ - // textout-note@+1 {{[debug] analyzing from notInvokedLambdaScope()::(anonymous class)::operator()()}} + // textout-note@+1 {{[debug] analyzing from notInvokedLambdaScope()::(lambda)::operator()()}} auto notInvokedLambda = []() { // common-warning@+1 {{REACHABLE}} textout-note@+1 {{REACHABLE}} clang_analyzer_warnIfReached(); @@ -72,4 +72,4 @@ void invokedLambdaScope() { clang_analyzer_warnIfReached(); }; invokedLambda(); // textout-note {{Calling 'operator()'}} -} \ No newline at end of file +} diff --git a/clang/test/Analysis/bug_hash_test.cpp b/clang/test/Analysis/bug_hash_test.cpp index 7b812a76558dd..184d3a9dce255 100644 --- a/clang/test/Analysis/bug_hash_test.cpp +++ b/clang/test/Analysis/bug_hash_test.cpp @@ -65,7 +65,7 @@ void AA::X::OutOfLine() { void testLambda() { []() { - clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void testLambda()::(anonymous class)::operator()() const$29$clang_analyzer_hashDump(5);$Category}} + clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void testLambda()::(lambda)::operator()() const$29$clang_analyzer_hashDump(5);$Category}} }(); } diff --git a/clang/test/Analysis/debug-CallGraph.cpp b/clang/test/Analysis/debug-CallGraph.cpp index 120bb38d3bb33..04d6e5f14f963 100644 --- a/clang/test/Analysis/debug-CallGraph.cpp +++ b/clang/test/Analysis/debug-CallGraph.cpp @@ -97,14 +97,14 @@ namespace CallDecl { } // CHECK:--- Call graph Dump --- -// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > bbb ddd ccc eee fff do_nothing test_single_call SomeNS::templ SomeNS::templ SomeNS::templUser Lambdas::Callee Lambdas::f1 Lambdas::f1\(\)::\(anonymous class\)::operator\(\) Lambdas::f1\(\)::\(anonymous class\)::operator\(\) CallDecl::SomeDef CallDecl::Caller CallDecl::SomeDecl CallDecl::SomeOtherDecl $}} +// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > bbb ddd ccc eee fff do_nothing test_single_call SomeNS::templ SomeNS::templ SomeNS::templUser Lambdas::Callee Lambdas::f1 Lambdas::f1\(\)::\(lambda\)::operator\(\) Lambdas::f1\(\)::\(lambda\)::operator\(\) CallDecl::SomeDef CallDecl::Caller CallDecl::SomeDecl CallDecl::SomeOtherDecl $}} // CHECK-NEXT: {{Function: CallDecl::Caller calls: CallDecl::SomeDecl CallDecl::SomeOtherDecl $}} // CHECK-NEXT: {{Function: CallDecl::SomeOtherDecl calls: CallDecl::SomeDef $}} // CHECK-NEXT: {{Function: CallDecl::SomeDecl calls: $}} // CHECK-NEXT: {{Function: CallDecl::SomeDef calls: $}} -// CHECK-NEXT: {{Function: Lambdas::f1 calls: Lambdas::f1\(\)::\(anonymous class\)::operator\(\) Lambdas::f1\(\)::\(anonymous class\)::operator\(\) $}} -// CHECK-NEXT: {{Function: Lambdas::f1\(\)::\(anonymous class\)::operator\(\) calls: Lambdas::Callee $}} -// CHECK-NEXT: {{Function: Lambdas::f1\(\)::\(anonymous class\)::operator\(\) calls: Lambdas::Callee $}} +// CHECK-NEXT: {{Function: Lambdas::f1 calls: Lambdas::f1\(\)::\(lambda\)::operator\(\) Lambdas::f1\(\)::\(lambda\)::operator\(\) $}} +// CHECK-NEXT: {{Function: Lambdas::f1\(\)::\(lambda\)::operator\(\) calls: Lambdas::Callee $}} +// CHECK-NEXT: {{Function: Lambdas::f1\(\)::\(lambda\)::operator\(\) calls: Lambdas::Callee $}} // CHECK-NEXT: {{Function: Lambdas::Callee calls: $}} // CHECK-NEXT: {{Function: SomeNS::templUser calls: SomeNS::templ SomeNS::templ $}} // CHECK-NEXT: {{Function: SomeNS::templ calls: eee $}} diff --git a/clang/test/Analysis/inlining/Inputs/expected-plists/path-notes.cpp.plist b/clang/test/Analysis/inlining/Inputs/expected-plists/path-notes.cpp.plist index 6215d48ebd2c8..62aaf0fe8e2d5 100644 --- a/clang/test/Analysis/inlining/Inputs/expected-plists/path-notes.cpp.plist +++ b/clang/test/Analysis/inlining/Inputs/expected-plists/path-notes.cpp.plist @@ -722,7 +722,7 @@ typeDereference of null pointer check_namecore.NullDereference - issue_hash_content_of_line_in_contextefde323086a985fe1e8ccc6cd0123c12 + issue_hash_content_of_line_in_contextc13b0c1fd27df0a9d9c0b4c125ade016 issue_context_kindC++ method issue_contextmethod issue_hash_function_offset1 diff --git a/clang/test/CodeGen/block-with-perdefinedexpr.cpp b/clang/test/CodeGen/block-with-perdefinedexpr.cpp index 890c2d6358569..597971e6fb6be 100644 --- a/clang/test/CodeGen/block-with-perdefinedexpr.cpp +++ b/clang/test/CodeGen/block-with-perdefinedexpr.cpp @@ -67,11 +67,11 @@ class Foo { } void inside_lambda() { auto lambda = []() { - // CHECK-DAG: @__PRETTY_FUNCTION__.___ZZN12foonamespace3Foo13inside_lambdaEvENKUlvE_clEv_block_invoke = private unnamed_addr constant [92 x i8] c"auto foonamespace::Foo::inside_lambda()::(anonymous class)::operator()() const_block_invoke\00", align 1 + // CHECK-DAG: @__PRETTY_FUNCTION__.___ZZN12foonamespace3Foo13inside_lambdaEvENKUlvE_clEv_block_invoke = private unnamed_addr constant [83 x i8] c"auto foonamespace::Foo::inside_lambda()::(lambda)::operator()() const_block_invoke\00", align 1 const char * (^block1)() = ^() { return __PRETTY_FUNCTION__; }; - // CHECK-DAG: @__PRETTY_FUNCTION__.___ZZN12foonamespace3Foo13inside_lambdaEvENKUlvE_clEv_block_invoke_2 = private unnamed_addr constant [94 x i8] c"auto foonamespace::Foo::inside_lambda()::(anonymous class)::operator()() const_block_invoke_2\00", align 1 + // CHECK-DAG: @__PRETTY_FUNCTION__.___ZZN12foonamespace3Foo13inside_lambdaEvENKUlvE_clEv_block_invoke_2 = private unnamed_addr constant [85 x i8] c"auto foonamespace::Foo::inside_lambda()::(lambda)::operator()() const_block_invoke_2\00", align 1 const char * (^block2)() = ^() { return __PRETTY_FUNCTION__; }; diff --git a/clang/test/CodeGenCXX/predefined-expr.cpp b/clang/test/CodeGenCXX/predefined-expr.cpp index 815bcbb3bd899..1f036c5d520c9 100644 --- a/clang/test/CodeGenCXX/predefined-expr.cpp +++ b/clang/test/CodeGenCXX/predefined-expr.cpp @@ -10,7 +10,7 @@ // CHECK-DAG: private unnamed_addr constant [103 x i8] c"static void ClassWithTemplateTemplateParam::staticMember() [T = char, Param = NS::ClassTemplate]\00" // CHECK-DAG: private unnamed_addr constant [106 x i8] c"void OuterClass::MiddleClass::InnerClass::memberFunction(T, U) const [T = int *, U = float]\00" // CHECK-DAG: private unnamed_addr constant [51 x i8] c"void functionTemplateWithCapturedStmt(T) [T = int]\00" -// CHECK-DAG: private unnamed_addr constant [76 x i8] c"auto functionTemplateWithLambda(int)::(anonymous class)::operator()() const\00" +// CHECK-DAG: private unnamed_addr constant [67 x i8] c"auto functionTemplateWithLambda(int)::(lambda)::operator()() const\00" // CHECK-DAG: private unnamed_addr constant [65 x i8] c"void functionTemplateWithUnnamedTemplateParameter(T) [T = float]\00" // CHECK-DAG: private unnamed_addr constant [60 x i8] c"void functionTemplateExplicitSpecialization(T) [T = double]\00" @@ -28,13 +28,13 @@ // CHECK-DAG: private unnamed_addr constant [46 x i8] c"void NS::Base::functionTemplate1(T) [T = int]\00" // CHECK-DAG: private unnamed_addr constant [23 x i8] c"anonymousUnionFunction\00" -// CHECK-DAG: private unnamed_addr constant [83 x i8] c"void NS::ContainerForAnonymousRecords::(anonymous union)::anonymousUnionFunction()\00" +// CHECK-DAG: private unnamed_addr constant [81 x i8] c"void NS::ContainerForAnonymousRecords::(unnamed union)::anonymousUnionFunction()\00" // CHECK-DAG: private unnamed_addr constant [24 x i8] c"anonymousStructFunction\00" -// CHECK-DAG: private unnamed_addr constant [85 x i8] c"void NS::ContainerForAnonymousRecords::(anonymous struct)::anonymousStructFunction()\00" +// CHECK-DAG: private unnamed_addr constant [83 x i8] c"void NS::ContainerForAnonymousRecords::(unnamed struct)::anonymousStructFunction()\00" // CHECK-DAG: private unnamed_addr constant [23 x i8] c"anonymousClassFunction\00" -// CHECK-DAG: private unnamed_addr constant [83 x i8] c"void NS::ContainerForAnonymousRecords::(anonymous class)::anonymousClassFunction()\00" +// CHECK-DAG: private unnamed_addr constant [81 x i8] c"void NS::ContainerForAnonymousRecords::(unnamed class)::anonymousClassFunction()\00" // CHECK-DAG: private unnamed_addr constant [12 x i8] c"~Destructor\00" // CHECK-DAG: private unnamed_addr constant [30 x i8] c"NS::Destructor::~Destructor()\00" diff --git a/clang/test/Index/print-type.c b/clang/test/Index/print-type.c index 9fb85f8da4e66..3ceecbd90b250 100644 --- a/clang/test/Index/print-type.c +++ b/clang/test/Index/print-type.c @@ -71,7 +71,7 @@ _Atomic(unsigned long) aul; // CHECK: TypeRef=struct Struct:16:8 [type=struct Struct] [typekind=Record] [isPOD=1] // CHECK: StructDecl=struct (unnamed at {{.*}}):18:1 (Definition) [type=struct (unnamed at {{.*}}print-type.c:18:1)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=0] // CHECK: StructDecl=struct (unnamed at {{.*}}):23:1 (Definition) [type=struct (unnamed at {{.*}}print-type.c:23:1)] [typekind=Record] [isPOD=1] [nbFields=1] [isAnon=1] [isAnonRecDecl=0] -// CHECK: StructDecl=struct (anonymous at {{.*}}):24:3 (Definition) [type=struct (anonymous struct)::(anonymous at {{.*}}print-type.c:24:3)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=1] +// CHECK: StructDecl=struct (anonymous at {{.*}}):24:3 (Definition) [type=struct (unnamed struct)::(anonymous at {{.*}}print-type.c:24:3)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=1] // CHECK: FieldDecl=x:25:17 (Definition) [type=_Atomic(int)] [typekind=Atomic] [valuetype=int] [valuetypekind=Int] [isPOD=0] [isAnonRecDecl=0] // CHECK: FieldDecl=y:26:9 (Definition) [type=int] [typekind=Int] [isPOD=1] [isAnonRecDecl=0] // CHECK: StructDecl=struct (unnamed at {{.*}}):30:10 (Definition) [type=struct (unnamed at {{.*}}print-type.c:30:10)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=0] diff --git a/clang/test/Layout/ms-x86-alias-avoidance-padding.cpp b/clang/test/Layout/ms-x86-alias-avoidance-padding.cpp index bc6a56ef37538..a83810e28741b 100644 --- a/clang/test/Layout/ms-x86-alias-avoidance-padding.cpp +++ b/clang/test/Layout/ms-x86-alias-avoidance-padding.cpp @@ -49,7 +49,7 @@ struct AT3 : AT2, AT1 { // CHECK-NEXT: 0 | struct AT2 (base) // CHECK-NEXT: 0 | struct AT0 t // CHECK-NEXT: 0 | union AT0::(unnamed at {{.*}} x -// CHECK-NEXT: 0 | struct AT0::(anonymous union)::(unnamed at {{.*}} y +// CHECK-NEXT: 0 | struct AT0::(unnamed union)::(unnamed at {{.*}} y // CHECK-NEXT: 0 | int a // CHECK-NEXT: 4 | struct AT t (empty) // CHECK: 0 | int b @@ -66,7 +66,7 @@ struct AT3 : AT2, AT1 { // CHECK-X64-NEXT: 0 | struct AT2 (base) // CHECK-X64-NEXT: 0 | struct AT0 t // CHECK-X64-NEXT: 0 | union AT0::(unnamed at {{.*}} x -// CHECK-X64-NEXT: 0 | struct AT0::(anonymous union)::(unnamed at {{.*}} y +// CHECK-X64-NEXT: 0 | struct AT0::(unnamed union)::(unnamed at {{.*}} y // CHECK-X64-NEXT: 0 | int a // CHECK-X64-NEXT: 4 | struct AT t (empty) // CHECK-X64: 0 | int b diff --git a/clang/test/SemaCXX/builtin-bswapg.cpp b/clang/test/SemaCXX/builtin-bswapg.cpp index 9d8d103e77c51..539390fa9b606 100644 --- a/clang/test/SemaCXX/builtin-bswapg.cpp +++ b/clang/test/SemaCXX/builtin-bswapg.cpp @@ -135,13 +135,13 @@ void test_lambda_errors() { lambda(1.0f); // expected-error@#lambda_use {{1st argument must be a scalar integer type (was 'float')}} - // expected-note@-2 {{in instantiation of function template specialization 'test_lambda_errors()::(anonymous class)::operator()' requested here}} + // expected-note@-2 {{in instantiation of function template specialization 'test_lambda_errors()::(lambda)::operator()' requested here}} lambda(1.0l); // expected-error@#lambda_use {{1st argument must be a scalar integer type (was 'long double')}} - // expected-note@-2 {{in instantiation of function template specialization 'test_lambda_errors()::(anonymous class)::operator()' requested here}} + // expected-note@-2 {{in instantiation of function template specialization 'test_lambda_errors()::(lambda)::operator()' requested here}} lambda("hello"); // expected-error@#lambda_use {{1st argument must be a scalar integer type (was 'const char *')}} - // expected-note@-2 {{in instantiation of function template specialization 'test_lambda_errors()::(anonymous class)::operator()' requested here}} + // expected-note@-2 {{in instantiation of function template specialization 'test_lambda_errors()::(lambda)::operator()' requested here}} } template void test_variadic_template_argument_count(Args... args) { diff --git a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp index ff104243a9735..6da589dcf1b25 100644 --- a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp +++ b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp @@ -636,7 +636,7 @@ template struct scope_exit { T t; constexpr ~scope_exit() { t(); } - // expected-error@-1 {{call to immediate function 'GH109096::(anonymous class)::operator()' is not a constant expression}} \ + // expected-error@-1 {{call to immediate function 'GH109096::(lambda)::operator()' is not a constant expression}} \ // expected-note@-1 {{implicit use of 'this' pointer is only allowed within the evaluation}} }; diff --git a/clang/test/SemaCXX/predefined-expr.cpp b/clang/test/SemaCXX/predefined-expr.cpp index 8cba0d41a2997..ea41f0b505d31 100644 --- a/clang/test/SemaCXX/predefined-expr.cpp +++ b/clang/test/SemaCXX/predefined-expr.cpp @@ -26,8 +26,8 @@ int baz() { []() { static_assert(sizeof(__func__) == 11, "operator()"); static_assert(sizeof(__FUNCTION__) == 11, "operator()"); - static_assert(sizeof(__PRETTY_FUNCTION__) == 50, - "auto baz()::::operator()() const"); + static_assert(sizeof(__PRETTY_FUNCTION__) == 41, + "auto baz()::::operator()() const"); return 0; } (); @@ -56,8 +56,8 @@ int main() { []() { static_assert(sizeof(__func__) == 11, "operator()"); static_assert(sizeof(__FUNCTION__) == 11, "operator()"); - static_assert(sizeof(__PRETTY_FUNCTION__) == 51, - "auto main()::::operator()() const"); + static_assert(sizeof(__PRETTY_FUNCTION__) == 42, + "auto main()::::operator()() const"); return 0; } (); @@ -87,8 +87,8 @@ int main() { { static_assert(sizeof(__func__) == 11, "operator()"); static_assert(sizeof(__FUNCTION__) == 11, "operator()"); - static_assert(sizeof(__PRETTY_FUNCTION__) == 51, - "auto main()::::operator()() const"); + static_assert(sizeof(__PRETTY_FUNCTION__) == 42, + "auto main()::::operator()() const"); } } (); diff --git a/clang/test/SemaCXX/undefined-internal.cpp b/clang/test/SemaCXX/undefined-internal.cpp index 9745f097c76b7..9cd27ee2c981b 100644 --- a/clang/test/SemaCXX/undefined-internal.cpp +++ b/clang/test/SemaCXX/undefined-internal.cpp @@ -227,7 +227,7 @@ namespace test7 { namespace test8 { typedef struct { - void bar(); // expected-warning {{function 'test8::(anonymous struct)::bar' has internal linkage but is not defined}} + void bar(); // expected-warning {{function 'test8::(unnamed struct)::bar' has internal linkage but is not defined}} void foo() { bar(); // expected-note {{used here}} } diff --git a/clang/test/SemaObjCXX/arc-0x.mm b/clang/test/SemaObjCXX/arc-0x.mm index a7418eceb244b..dd8b8e80c2817 100644 --- a/clang/test/SemaObjCXX/arc-0x.mm +++ b/clang/test/SemaObjCXX/arc-0x.mm @@ -195,8 +195,8 @@ void test() { }; static union { // expected-error {{call to implicitly-deleted default constructor of}} - union { // expected-note-re {{default constructor of '(unnamed union at {{.*}}' is implicitly deleted because field 'test_union::(anonymous union)::(anonymous union at {{.*}})' has a deleted default constructor}} - union { // expected-note-re {{default constructor of '(anonymous union at {{.*}}' is implicitly deleted because field 'test_union::(anonymous union)::(anonymous union)::(anonymous union at {{.*}})' has a deleted default constructor}} + union { // expected-note-re {{default constructor of '(unnamed union at {{.*}}' is implicitly deleted because field 'test_union::(unnamed union)::(anonymous union at {{.*}})' has a deleted default constructor}} + union { // expected-note-re {{default constructor of '(anonymous union at {{.*}}' is implicitly deleted because field 'test_union::(unnamed union)::(anonymous union)::(anonymous union at {{.*}})' has a deleted default constructor}} __weak id g1; // expected-note-re {{default constructor of '(anonymous union at {{.*}}' is implicitly deleted because variant field 'g1' is an ObjC pointer}} int g2; }; diff --git a/clang/unittests/AST/NamedDeclPrinterTest.cpp b/clang/unittests/AST/NamedDeclPrinterTest.cpp index cd833725b448d..599ccd7f06fc6 100644 --- a/clang/unittests/AST/NamedDeclPrinterTest.cpp +++ b/clang/unittests/AST/NamedDeclPrinterTest.cpp @@ -265,3 +265,32 @@ TEST(NamedDeclPrinter, NestedNameSpecifierTemplateArgs) { ASSERT_TRUE( PrintedNestedNameSpecifierMatches(Code, "method", "vector::")); } + +TEST(NamedDeclPrinter, NestedNameSpecifierLambda) { + const char *Code = + R"( + auto l = [] { + struct Foo { + void method(); + }; + }; +)"; + ASSERT_TRUE(PrintedNestedNameSpecifierMatches( + Code, "method", "(lambda)::operator()()::Foo::")); +} + +TEST(NamedDeclPrinter, NestedNameSpecifierAnonymousTags) { + const char *Code = + R"( + struct Foo { + class { + public: + struct { + void method(); + } i; + }; + }; +)"; + ASSERT_TRUE(PrintedNestedNameSpecifierMatches( + Code, "method", "Foo::(anonymous class)::(unnamed struct)::")); +} diff --git a/clang/unittests/AST/TypePrinterTest.cpp b/clang/unittests/AST/TypePrinterTest.cpp index 3cadf9b265bd1..de4cfa4074eba 100644 --- a/clang/unittests/AST/TypePrinterTest.cpp +++ b/clang/unittests/AST/TypePrinterTest.cpp @@ -328,7 +328,7 @@ TEST(TypePrinter, NestedNameSpecifiers) { // Further levels of nesting print the entire scope. ASSERT_TRUE(PrintedTypeMatches( Code, {}, fieldDecl(hasName("u"), hasType(qualType().bind("id"))), - "union level1()::Inner::Inner(int)::(anonymous struct)::(unnamed)", + "union level1()::Inner::Inner(int)::(unnamed struct)::(unnamed)", [](PrintingPolicy &Policy) { Policy.FullyQualifiedName = true; Policy.AnonymousTagLocations = false; diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp index 5d452355d0e43..697623c8a48e8 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -2709,25 +2709,48 @@ TEST_P(ASTMatchersTest, HasName_MatchesAnonymousNamespaces) { EXPECT_TRUE(matches(code, recordDecl(hasName("::a::C")))); } -TEST_P(ASTMatchersTest, HasName_MatchesAnonymousOuterClasses) { +TEST_P(ASTMatchersTest, HasName_MatchesUnnamedOuterClasses) { if (!GetParam().isCXX()) { return; } EXPECT_TRUE(matches("class A { class { class C; } x; };", - recordDecl(hasName("A::(anonymous class)::C")))); + recordDecl(hasName("A::(unnamed class)::C")))); EXPECT_TRUE(matches("class A { class { class C; } x; };", - recordDecl(hasName("::A::(anonymous class)::C")))); + recordDecl(hasName("::A::(unnamed class)::C")))); EXPECT_FALSE(matches("class A { class { class C; } x; };", recordDecl(hasName("::A::C")))); EXPECT_TRUE(matches("class A { struct { class C; } x; };", - recordDecl(hasName("A::(anonymous struct)::C")))); + recordDecl(hasName("A::(unnamed struct)::C")))); EXPECT_TRUE(matches("class A { struct { class C; } x; };", - recordDecl(hasName("::A::(anonymous struct)::C")))); + recordDecl(hasName("::A::(unnamed struct)::C")))); EXPECT_FALSE(matches("class A { struct { class C; } x; };", recordDecl(hasName("::A::C")))); } +TEST_P(ASTMatchersTest, HasName_MatchesAnonymousOuterClasses) { + if (!GetParam().isCXX()) { + return; + } + + EXPECT_TRUE(matches( + "class A { struct { struct { class C; } x; }; };", + recordDecl(hasName("A::(anonymous struct)::(unnamed struct)::C")))); + EXPECT_TRUE(matches( + "class A { struct { struct { class C; } x; }; };", + recordDecl(hasName("::A::(anonymous struct)::(unnamed struct)::C")))); + EXPECT_FALSE(matches("class A { struct { struct { class C; } x; }; };", + recordDecl(hasName("A::(unnamed struct)::C")))); + EXPECT_TRUE(matches( + "class A { class { public: struct { class C; } x; }; };", + recordDecl(hasName("A::(anonymous class)::(unnamed struct)::C")))); + EXPECT_TRUE(matches( + "class A { class { public: struct { class C; } x; }; };", + recordDecl(hasName("::A::(anonymous class)::(unnamed struct)::C")))); + EXPECT_FALSE(matches("class A { class { public: struct { class C; } x; }; };", + recordDecl(hasName("A::(unnamed struct)::C")))); +} + TEST_P(ASTMatchersTest, HasName_MatchesFunctionScope) { if (!GetParam().isCXX()) { return;