Author: Haojian Wu Date: 2023-01-26T11:37:41+01:00 New Revision: e400c63cc39680538a3726a7736baf6b7844c3a8
URL: https://github.com/llvm/llvm-project/commit/e400c63cc39680538a3726a7736baf6b7844c3a8 DIFF: https://github.com/llvm/llvm-project/commit/e400c63cc39680538a3726a7736baf6b7844c3a8.diff LOG: Revert "[clang] Build UsingType for elaborated type specifiers." This reverts commit e70ca7b35319a3621f9d9c6475926428f8c5c000 and the followup patch "[clang] Fix the location of UsingTypeLoc" (ebbeb164c25a40cb6ba9c6b18dce5dcd06c0bb07). The patch causes an incorrect lookup result: ``` namespace ns { struct Foo { };} using ns::Foo; void test() { struct Foo { } k; // the type of k refers to ns::Foo, rather than the local Foo! } ``` Added: Modified: clang-tools-extra/clangd/unittests/SelectionTests.cpp clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp clang/include/clang/Sema/DeclSpec.h clang/include/clang/Sema/Sema.h clang/lib/Parse/ParseDecl.cpp clang/lib/Parse/ParseDeclCXX.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaTemplate.cpp clang/lib/Sema/SemaType.cpp clang/test/CXX/drs/dr2xx.cpp clang/test/CXX/drs/dr4xx.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp b/clang-tools-extra/clangd/unittests/SelectionTests.cpp index 4e5c3774c1655..d7ea34c3c7054 100644 --- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp +++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp @@ -520,13 +520,6 @@ TEST(SelectionTest, CommonAncestor) { )cpp", "TypedefTypeLoc"}, - {R"cpp( - namespace ns { class Foo {}; } - using ns::Foo; - class [[^Foo]] foo; - )cpp", - "UsingTypeLoc"}, - // lambda captured var-decl {R"cpp( void test(int bar) { diff --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp index e5b99ef9a3a00..3b97cc8cdfd55 100644 --- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp @@ -150,9 +150,6 @@ TEST(WalkAST, Using) { } using ns::$explicit^Y;)cpp", "^Y<int> x;"); - testWalk(R"cpp( - namespace ns { class Foo {}; } - )cpp", "using ns::$explicit^Foo; class ^Foo foo;"); } TEST(WalkAST, Namespaces) { diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h index a95fe5686009b..69fe2c541607b 100644 --- a/clang/include/clang/Sema/DeclSpec.h +++ b/clang/include/clang/Sema/DeclSpec.h @@ -506,16 +506,8 @@ class DeclSpec { assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type"); return TypeRep; } - // Returns the underlying decl, if any. Decl *getRepAsDecl() const { - auto *D = getRepAsFoundDecl(); - if (const auto *Using = dyn_cast_or_null<UsingShadowDecl>(D)) - return Using->getTargetDecl(); - return D; - } - // Returns the originally found decl, if any. - Decl *getRepAsFoundDecl() const { - assert(isDeclRep((TST)TypeSpecType) && "DeclSpec does not store a decl"); + assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl"); return DeclRep; } Expr *getRepAsExpr() const { diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 3e3fb2b0cc56d..e52e853e1df86 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -3327,9 +3327,7 @@ class Sema final { SourceLocation ScopedEnumKWLoc, bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, bool IsTypeSpecifier, bool IsTemplateParamOrArg, - OffsetOfKind OOK, - UsingShadowDecl*& FoundUsingShadow, - SkipBodyInfo *SkipBody = nullptr); + OffsetOfKind OOK, SkipBodyInfo *SkipBody = nullptr); DeclResult ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, unsigned TagSpec, SourceLocation TagLoc, diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index c7fd1156928ca..e6812ac72c885 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4965,7 +4965,6 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, bool IsDependent = false; const char *PrevSpec = nullptr; unsigned DiagID; - UsingShadowDecl* FoundUsing = nullptr; Decl *TagDecl = Actions.ActOnTag(getCurScope(), DeclSpec::TST_enum, TUK, StartLoc, SS, Name, NameLoc, attrs, AS, DS.getModulePrivateSpecLoc(), @@ -4974,7 +4973,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, BaseType, DSC == DeclSpecContext::DSC_type_specifier, DSC == DeclSpecContext::DSC_template_param || DSC == DeclSpecContext::DSC_template_type_arg, - OffsetOfState, FoundUsing, &SkipBody).get(); + OffsetOfState, &SkipBody).get(); if (SkipBody.ShouldSkip) { assert(TUK == Sema::TUK_Definition && "can only skip a definition"); @@ -4984,8 +4983,8 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, T.skipToEnd(); if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, - NameLoc.isValid() ? NameLoc : StartLoc, PrevSpec, - DiagID, FoundUsing ? FoundUsing : TagDecl, Owned, + NameLoc.isValid() ? NameLoc : StartLoc, + PrevSpec, DiagID, TagDecl, Owned, Actions.getASTContext().getPrintingPolicy())) Diag(StartLoc, DiagID) << PrevSpec; return; @@ -5039,8 +5038,8 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, } if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, - NameLoc.isValid() ? NameLoc : StartLoc, PrevSpec, - DiagID, FoundUsing ? FoundUsing : TagDecl, Owned, + NameLoc.isValid() ? NameLoc : StartLoc, + PrevSpec, DiagID, TagDecl, Owned, Actions.getASTContext().getPrintingPolicy())) Diag(StartLoc, DiagID) << PrevSpec; } diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index b26ec00cfedf3..227c1df2bdddd 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -1934,7 +1934,6 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, // Create the tag portion of the class or class template. DeclResult TagOrTempResult = true; // invalid TypeResult TypeResult = true; // invalid - UsingShadowDecl *FoundUsing = nullptr; bool Owned = false; Sema::SkipBodyInfo SkipBody; @@ -2075,7 +2074,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, DSC == DeclSpecContext::DSC_type_specifier, DSC == DeclSpecContext::DSC_template_param || DSC == DeclSpecContext::DSC_template_type_arg, - OffsetOfState, FoundUsing, &SkipBody); + OffsetOfState, &SkipBody); // If ActOnTag said the type was dependent, try again with the // less common call. @@ -2134,7 +2133,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, } else if (!TagOrTempResult.isInvalid()) { Result = DS.SetTypeSpecType( TagType, StartLoc, NameLoc.isValid() ? NameLoc : StartLoc, PrevSpec, - DiagID, FoundUsing ? FoundUsing : TagOrTempResult.get(), Owned, Policy); + DiagID, TagOrTempResult.get(), Owned, Policy); } else { DS.SetTypeSpecError(); return; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index e2b921bfe78f7..b2ac4173410a8 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -16616,8 +16616,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, bool &IsDependent, SourceLocation ScopedEnumKWLoc, bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, bool IsTypeSpecifier, bool IsTemplateParamOrArg, - OffsetOfKind OOK, UsingShadowDecl *&FoundUsingShadow, - SkipBodyInfo *SkipBody) { + OffsetOfKind OOK, SkipBodyInfo *SkipBody) { // If this is not a definition, it must have a name. IdentifierInfo *OrigName = Name; assert((Name != nullptr || TUK == TUK_Definition) && @@ -17052,7 +17051,6 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, // redefinition if either context is within the other. if (auto *Shadow = dyn_cast<UsingShadowDecl>(DirectPrevDecl)) { auto *OldTag = dyn_cast<TagDecl>(PrevDecl); - FoundUsingShadow = Shadow; if (SS.isEmpty() && TUK != TUK_Reference && TUK != TUK_Friend && isDeclInScope(Shadow, SearchDC, S, isMemberSpecialization) && !(OldTag && isAcceptableTagRedeclContext( diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 348092fc62e8f..df83442a8cd18 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -16977,7 +16977,6 @@ DeclResult Sema::ActOnTemplatedFriendTag( if (SS.isEmpty()) { bool Owned = false; bool IsDependent = false; - UsingShadowDecl* FoundUsing = nullptr; return ActOnTag(S, TagSpec, TUK_Friend, TagLoc, SS, Name, NameLoc, Attr, AS_public, /*ModulePrivateLoc=*/SourceLocation(), @@ -16986,7 +16985,7 @@ DeclResult Sema::ActOnTemplatedFriendTag( /*ScopedEnumUsesClassTag=*/false, /*UnderlyingType=*/TypeResult(), /*IsTypeSpecifier=*/false, - /*IsTemplateParamOrArg=*/false, /*OOK=*/OOK_Outside, FoundUsing); + /*IsTemplateParamOrArg=*/false, /*OOK=*/OOK_Outside); } NestedNameSpecifierLoc QualifierLoc = SS.getWithLocInContext(Context); diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 4b144c239fa47..b40bd0978a8ab 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -10181,14 +10181,11 @@ Sema::ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, bool Owned = false; bool IsDependent = false; - UsingShadowDecl* FoundUsing = nullptr; - Decl *TagD = - ActOnTag(S, TagSpec, Sema::TUK_Reference, KWLoc, SS, Name, NameLoc, Attr, - AS_none, /*ModulePrivateLoc=*/SourceLocation(), + Decl *TagD = ActOnTag(S, TagSpec, Sema::TUK_Reference, KWLoc, SS, Name, + NameLoc, Attr, AS_none, /*ModulePrivateLoc=*/SourceLocation(), MultiTemplateParamsArg(), Owned, IsDependent, SourceLocation(), false, TypeResult(), /*IsTypeSpecifier*/ false, - /*IsTemplateParamOrArg*/ false, /*OOK=*/OOK_Outside, FoundUsing) - .get(); + /*IsTemplateParamOrArg*/ false, /*OOK=*/OOK_Outside).get(); assert(!IsDependent && "explicit instantiation of dependent name not yet handled"); if (!TagD) diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 505b3b922d33d..2cdd562506f2e 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1589,9 +1589,6 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) { // TypeQuals handled by caller. Result = Context.getTypeDeclType(D); - if (const auto *Using = - dyn_cast_or_null<UsingShadowDecl>(DS.getRepAsFoundDecl())) - Result = Context.getUsingType(Using, Result); // In both C and C++, make an ElaboratedType. ElaboratedTypeKeyword Keyword @@ -6257,9 +6254,6 @@ namespace { void VisitTagTypeLoc(TagTypeLoc TL) { TL.setNameLoc(DS.getTypeSpecTypeNameLoc()); } - void VisitUsingTypeLoc(UsingTypeLoc TL) { - TL.setNameLoc(DS.getTypeSpecTypeNameLoc()); - } void VisitAtomicTypeLoc(AtomicTypeLoc TL) { // An AtomicTypeLoc can come from either an _Atomic(...) type specifier // or an _Atomic qualifier. diff --git a/clang/test/CXX/drs/dr2xx.cpp b/clang/test/CXX/drs/dr2xx.cpp index 8a462203ca9a9..31ac31b088105 100644 --- a/clang/test/CXX/drs/dr2xx.cpp +++ b/clang/test/CXX/drs/dr2xx.cpp @@ -992,7 +992,7 @@ namespace dr284 { // dr284: no } struct B::V {}; // expected-error {{no struct named 'V'}} struct B::W {}; - struct B::X {}; // expected-error {{forward declaration of struct cannot have}} + struct B::X {}; // FIXME: ill-formed enum B::Y e; // ok per dr417 class B::Z z; // ok per dr417 @@ -1009,7 +1009,7 @@ namespace dr284 { // dr284: no }; struct D::V {}; // expected-error {{no struct named 'V'}} struct D::W {}; - struct D::X {}; // expected-error {{forward declaration of struct cannot have}} + struct D::X {}; // FIXME: ill-formed enum D::Y e2; // ok per dr417 class D::Z z2; // ok per dr417 } diff --git a/clang/test/CXX/drs/dr4xx.cpp b/clang/test/CXX/drs/dr4xx.cpp index 158eb39fe633f..476d80ef0720d 100644 --- a/clang/test/CXX/drs/dr4xx.cpp +++ b/clang/test/CXX/drs/dr4xx.cpp @@ -301,8 +301,9 @@ namespace dr417 { // dr417: no struct F; struct H; } + // FIXME: This is ill-formed. using N::D; - struct dr417::D {}; // expected-error {{forward declaration of struct cannot}} expected-warning {{extra qualification}} + struct dr417::D {}; // expected-warning {{extra qualification}} using namespace N; struct dr417::E {}; // expected-warning {{extra qualification}} expected-error {{no struct named 'E'}} struct N::F {}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits