Skip to content

Commit c39e95c

Browse files
hokeintru
authored andcommitted
Revert "[clang] Build UsingType for elaborated type specifiers."
This reverts commit e70ca7b and the followup patch "[clang] Fix the location of UsingTypeLoc" (ebbeb16). 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! } ``` (cherry picked from commit e400c63)
1 parent 99777ef commit c39e95c

File tree

12 files changed

+18
-51
lines changed

12 files changed

+18
-51
lines changed

clang-tools-extra/clangd/unittests/SelectionTests.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,13 +520,6 @@ TEST(SelectionTest, CommonAncestor) {
520520
)cpp",
521521
"TypedefTypeLoc"},
522522

523-
{R"cpp(
524-
namespace ns { class Foo {}; }
525-
using ns::Foo;
526-
class [[^Foo]] foo;
527-
)cpp",
528-
"UsingTypeLoc"},
529-
530523
// lambda captured var-decl
531524
{R"cpp(
532525
void test(int bar) {

clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@ TEST(WalkAST, Using) {
150150
}
151151
using ns::$explicit^Y;)cpp",
152152
"^Y<int> x;");
153-
testWalk(R"cpp(
154-
namespace ns { class Foo {}; }
155-
)cpp", "using ns::$explicit^Foo; class ^Foo foo;");
156153
}
157154

158155
TEST(WalkAST, Namespaces) {

clang/include/clang/Sema/DeclSpec.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -506,16 +506,8 @@ class DeclSpec {
506506
assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type");
507507
return TypeRep;
508508
}
509-
// Returns the underlying decl, if any.
510509
Decl *getRepAsDecl() const {
511-
auto *D = getRepAsFoundDecl();
512-
if (const auto *Using = dyn_cast_or_null<UsingShadowDecl>(D))
513-
return Using->getTargetDecl();
514-
return D;
515-
}
516-
// Returns the originally found decl, if any.
517-
Decl *getRepAsFoundDecl() const {
518-
assert(isDeclRep((TST)TypeSpecType) && "DeclSpec does not store a decl");
510+
assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl");
519511
return DeclRep;
520512
}
521513
Expr *getRepAsExpr() const {

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,9 +3327,7 @@ class Sema final {
33273327
SourceLocation ScopedEnumKWLoc,
33283328
bool ScopedEnumUsesClassTag, TypeResult UnderlyingType,
33293329
bool IsTypeSpecifier, bool IsTemplateParamOrArg,
3330-
OffsetOfKind OOK,
3331-
UsingShadowDecl*& FoundUsingShadow,
3332-
SkipBodyInfo *SkipBody = nullptr);
3330+
OffsetOfKind OOK, SkipBodyInfo *SkipBody = nullptr);
33333331

33343332
DeclResult ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc,
33353333
unsigned TagSpec, SourceLocation TagLoc,

clang/lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4965,7 +4965,6 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
49654965
bool IsDependent = false;
49664966
const char *PrevSpec = nullptr;
49674967
unsigned DiagID;
4968-
UsingShadowDecl* FoundUsing = nullptr;
49694968
Decl *TagDecl =
49704969
Actions.ActOnTag(getCurScope(), DeclSpec::TST_enum, TUK, StartLoc, SS,
49714970
Name, NameLoc, attrs, AS, DS.getModulePrivateSpecLoc(),
@@ -4974,7 +4973,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
49744973
BaseType, DSC == DeclSpecContext::DSC_type_specifier,
49754974
DSC == DeclSpecContext::DSC_template_param ||
49764975
DSC == DeclSpecContext::DSC_template_type_arg,
4977-
OffsetOfState, FoundUsing, &SkipBody).get();
4976+
OffsetOfState, &SkipBody).get();
49784977

49794978
if (SkipBody.ShouldSkip) {
49804979
assert(TUK == Sema::TUK_Definition && "can only skip a definition");
@@ -4984,8 +4983,8 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
49844983
T.skipToEnd();
49854984

49864985
if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc,
4987-
NameLoc.isValid() ? NameLoc : StartLoc, PrevSpec,
4988-
DiagID, FoundUsing ? FoundUsing : TagDecl, Owned,
4986+
NameLoc.isValid() ? NameLoc : StartLoc,
4987+
PrevSpec, DiagID, TagDecl, Owned,
49894988
Actions.getASTContext().getPrintingPolicy()))
49904989
Diag(StartLoc, DiagID) << PrevSpec;
49914990
return;
@@ -5039,8 +5038,8 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
50395038
}
50405039

50415040
if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc,
5042-
NameLoc.isValid() ? NameLoc : StartLoc, PrevSpec,
5043-
DiagID, FoundUsing ? FoundUsing : TagDecl, Owned,
5041+
NameLoc.isValid() ? NameLoc : StartLoc,
5042+
PrevSpec, DiagID, TagDecl, Owned,
50445043
Actions.getASTContext().getPrintingPolicy()))
50455044
Diag(StartLoc, DiagID) << PrevSpec;
50465045
}

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,6 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
19341934
// Create the tag portion of the class or class template.
19351935
DeclResult TagOrTempResult = true; // invalid
19361936
TypeResult TypeResult = true; // invalid
1937-
UsingShadowDecl *FoundUsing = nullptr;
19381937

19391938
bool Owned = false;
19401939
Sema::SkipBodyInfo SkipBody;
@@ -2075,7 +2074,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
20752074
DSC == DeclSpecContext::DSC_type_specifier,
20762075
DSC == DeclSpecContext::DSC_template_param ||
20772076
DSC == DeclSpecContext::DSC_template_type_arg,
2078-
OffsetOfState, FoundUsing, &SkipBody);
2077+
OffsetOfState, &SkipBody);
20792078

20802079
// If ActOnTag said the type was dependent, try again with the
20812080
// less common call.
@@ -2134,7 +2133,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
21342133
} else if (!TagOrTempResult.isInvalid()) {
21352134
Result = DS.SetTypeSpecType(
21362135
TagType, StartLoc, NameLoc.isValid() ? NameLoc : StartLoc, PrevSpec,
2137-
DiagID, FoundUsing ? FoundUsing : TagOrTempResult.get(), Owned, Policy);
2136+
DiagID, TagOrTempResult.get(), Owned, Policy);
21382137
} else {
21392138
DS.SetTypeSpecError();
21402139
return;

clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16616,8 +16616,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
1661616616
bool &IsDependent, SourceLocation ScopedEnumKWLoc,
1661716617
bool ScopedEnumUsesClassTag, TypeResult UnderlyingType,
1661816618
bool IsTypeSpecifier, bool IsTemplateParamOrArg,
16619-
OffsetOfKind OOK, UsingShadowDecl *&FoundUsingShadow,
16620-
SkipBodyInfo *SkipBody) {
16619+
OffsetOfKind OOK, SkipBodyInfo *SkipBody) {
1662116620
// If this is not a definition, it must have a name.
1662216621
IdentifierInfo *OrigName = Name;
1662316622
assert((Name != nullptr || TUK == TUK_Definition) &&
@@ -17052,7 +17051,6 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
1705217051
// redefinition if either context is within the other.
1705317052
if (auto *Shadow = dyn_cast<UsingShadowDecl>(DirectPrevDecl)) {
1705417053
auto *OldTag = dyn_cast<TagDecl>(PrevDecl);
17055-
FoundUsingShadow = Shadow;
1705617054
if (SS.isEmpty() && TUK != TUK_Reference && TUK != TUK_Friend &&
1705717055
isDeclInScope(Shadow, SearchDC, S, isMemberSpecialization) &&
1705817056
!(OldTag && isAcceptableTagRedeclContext(

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16977,7 +16977,6 @@ DeclResult Sema::ActOnTemplatedFriendTag(
1697716977
if (SS.isEmpty()) {
1697816978
bool Owned = false;
1697916979
bool IsDependent = false;
16980-
UsingShadowDecl* FoundUsing = nullptr;
1698116980
return ActOnTag(S, TagSpec, TUK_Friend, TagLoc, SS, Name, NameLoc, Attr,
1698216981
AS_public,
1698316982
/*ModulePrivateLoc=*/SourceLocation(),
@@ -16986,7 +16985,7 @@ DeclResult Sema::ActOnTemplatedFriendTag(
1698616985
/*ScopedEnumUsesClassTag=*/false,
1698716986
/*UnderlyingType=*/TypeResult(),
1698816987
/*IsTypeSpecifier=*/false,
16989-
/*IsTemplateParamOrArg=*/false, /*OOK=*/OOK_Outside, FoundUsing);
16988+
/*IsTemplateParamOrArg=*/false, /*OOK=*/OOK_Outside);
1699016989
}
1699116990

1699216991
NestedNameSpecifierLoc QualifierLoc = SS.getWithLocInContext(Context);

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10181,14 +10181,11 @@ Sema::ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc,
1018110181

1018210182
bool Owned = false;
1018310183
bool IsDependent = false;
10184-
UsingShadowDecl* FoundUsing = nullptr;
10185-
Decl *TagD =
10186-
ActOnTag(S, TagSpec, Sema::TUK_Reference, KWLoc, SS, Name, NameLoc, Attr,
10187-
AS_none, /*ModulePrivateLoc=*/SourceLocation(),
10184+
Decl *TagD = ActOnTag(S, TagSpec, Sema::TUK_Reference, KWLoc, SS, Name,
10185+
NameLoc, Attr, AS_none, /*ModulePrivateLoc=*/SourceLocation(),
1018810186
MultiTemplateParamsArg(), Owned, IsDependent, SourceLocation(),
1018910187
false, TypeResult(), /*IsTypeSpecifier*/ false,
10190-
/*IsTemplateParamOrArg*/ false, /*OOK=*/OOK_Outside, FoundUsing)
10191-
.get();
10188+
/*IsTemplateParamOrArg*/ false, /*OOK=*/OOK_Outside).get();
1019210189
assert(!IsDependent && "explicit instantiation of dependent name not yet handled");
1019310190

1019410191
if (!TagD)

clang/lib/Sema/SemaType.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,9 +1588,6 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
15881588

15891589
// TypeQuals handled by caller.
15901590
Result = Context.getTypeDeclType(D);
1591-
if (const auto *Using =
1592-
dyn_cast_or_null<UsingShadowDecl>(DS.getRepAsFoundDecl()))
1593-
Result = Context.getUsingType(Using, Result);
15941591

15951592
// In both C and C++, make an ElaboratedType.
15961593
ElaboratedTypeKeyword Keyword
@@ -6256,9 +6253,6 @@ namespace {
62566253
void VisitTagTypeLoc(TagTypeLoc TL) {
62576254
TL.setNameLoc(DS.getTypeSpecTypeNameLoc());
62586255
}
6259-
void VisitUsingTypeLoc(UsingTypeLoc TL) {
6260-
TL.setNameLoc(DS.getTypeSpecTypeNameLoc());
6261-
}
62626256
void VisitAtomicTypeLoc(AtomicTypeLoc TL) {
62636257
// An AtomicTypeLoc can come from either an _Atomic(...) type specifier
62646258
// or an _Atomic qualifier.

0 commit comments

Comments
 (0)