Skip to content

Commit d392335

Browse files
committed
Revert "[Clang] Implement resolution for CWG1835 (#92957)"
ppc64le-lld-multistage-test has been failing. This reverts commit 7bfb98c.
1 parent 5523a47 commit d392335

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+811
-1113
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,6 @@ Resolutions to C++ Defect Reports
306306
- Clang now considers ``noexcept(typeid(expr))`` more carefully, instead of always assuming that ``std::bad_typeid`` can be thrown.
307307
(`CWG2191: Incorrect result for noexcept(typeid(v)) <https://cplusplus.github.io/CWG/issues/2191.html>`_).
308308

309-
- Clang now correctly implements lookup for the terminal name of a member-qualified nested-name-specifier.
310-
(`CWG1835: Dependent member lookup before < <https://cplusplus.github.io/CWG/issues/1835.html>`_).
311-
312309
C Language Changes
313310
------------------
314311

clang/include/clang/AST/ExprCXX.h

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3676,9 +3676,9 @@ class CXXUnresolvedConstructExpr final
36763676
/// an implicit access if a qualifier is provided.
36773677
class CXXDependentScopeMemberExpr final
36783678
: public Expr,
3679-
private llvm::TrailingObjects<
3680-
CXXDependentScopeMemberExpr, NestedNameSpecifierLoc, DeclAccessPair,
3681-
ASTTemplateKWAndArgsInfo, TemplateArgumentLoc> {
3679+
private llvm::TrailingObjects<CXXDependentScopeMemberExpr,
3680+
ASTTemplateKWAndArgsInfo,
3681+
TemplateArgumentLoc, NamedDecl *> {
36823682
friend class ASTStmtReader;
36833683
friend class ASTStmtWriter;
36843684
friend TrailingObjects;
@@ -3691,15 +3691,17 @@ class CXXDependentScopeMemberExpr final
36913691
/// implicit accesses.
36923692
QualType BaseType;
36933693

3694+
/// The nested-name-specifier that precedes the member name, if any.
3695+
/// FIXME: This could be in principle store as a trailing object.
3696+
/// However the performance impact of doing so should be investigated first.
3697+
NestedNameSpecifierLoc QualifierLoc;
3698+
36943699
/// The member to which this member expression refers, which
36953700
/// can be name, overloaded operator, or destructor.
36963701
///
36973702
/// FIXME: could also be a template-id
36983703
DeclarationNameInfo MemberNameInfo;
36993704

3700-
/// The location of the '->' or '.' operator.
3701-
SourceLocation OperatorLoc;
3702-
37033705
// CXXDependentScopeMemberExpr is followed by several trailing objects,
37043706
// some of which optional. They are in order:
37053707
//
@@ -3719,16 +3721,8 @@ class CXXDependentScopeMemberExpr final
37193721
return CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo;
37203722
}
37213723

3722-
unsigned getNumUnqualifiedLookups() const {
3723-
return CXXDependentScopeMemberExprBits.NumUnqualifiedLookups;
3724-
}
3725-
3726-
unsigned numTrailingObjects(OverloadToken<NestedNameSpecifierLoc>) const {
3727-
return hasQualifier();
3728-
}
3729-
3730-
unsigned numTrailingObjects(OverloadToken<DeclAccessPair>) const {
3731-
return getNumUnqualifiedLookups();
3724+
bool hasFirstQualifierFoundInScope() const {
3725+
return CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope;
37323726
}
37333727

37343728
unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
@@ -3739,32 +3733,33 @@ class CXXDependentScopeMemberExpr final
37393733
return getNumTemplateArgs();
37403734
}
37413735

3736+
unsigned numTrailingObjects(OverloadToken<NamedDecl *>) const {
3737+
return hasFirstQualifierFoundInScope();
3738+
}
3739+
37423740
CXXDependentScopeMemberExpr(const ASTContext &Ctx, Expr *Base,
37433741
QualType BaseType, bool IsArrow,
37443742
SourceLocation OperatorLoc,
37453743
NestedNameSpecifierLoc QualifierLoc,
37463744
SourceLocation TemplateKWLoc,
3747-
ArrayRef<DeclAccessPair> UnqualifiedLookups,
3745+
NamedDecl *FirstQualifierFoundInScope,
37483746
DeclarationNameInfo MemberNameInfo,
37493747
const TemplateArgumentListInfo *TemplateArgs);
37503748

3751-
CXXDependentScopeMemberExpr(EmptyShell Empty, bool HasQualifier,
3752-
unsigned NumUnqualifiedLookups,
3753-
bool HasTemplateKWAndArgsInfo);
3749+
CXXDependentScopeMemberExpr(EmptyShell Empty, bool HasTemplateKWAndArgsInfo,
3750+
bool HasFirstQualifierFoundInScope);
37543751

37553752
public:
37563753
static CXXDependentScopeMemberExpr *
37573754
Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
37583755
SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
3759-
SourceLocation TemplateKWLoc,
3760-
ArrayRef<DeclAccessPair> UnqualifiedLookups,
3756+
SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
37613757
DeclarationNameInfo MemberNameInfo,
37623758
const TemplateArgumentListInfo *TemplateArgs);
37633759

37643760
static CXXDependentScopeMemberExpr *
3765-
CreateEmpty(const ASTContext &Ctx, bool HasQualifier,
3766-
unsigned NumUnqualifiedLookups, bool HasTemplateKWAndArgsInfo,
3767-
unsigned NumTemplateArgs);
3761+
CreateEmpty(const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo,
3762+
unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope);
37683763

37693764
/// True if this is an implicit access, i.e. one in which the
37703765
/// member being accessed was not written in the source. The source
@@ -3789,35 +3784,34 @@ class CXXDependentScopeMemberExpr final
37893784
bool isArrow() const { return CXXDependentScopeMemberExprBits.IsArrow; }
37903785

37913786
/// Retrieve the location of the '->' or '.' operator.
3792-
SourceLocation getOperatorLoc() const { return OperatorLoc; }
3793-
3794-
/// Determines whether this member expression had a nested-name-specifier
3795-
/// prior to the name of the member, e.g., x->Base::foo.
3796-
bool hasQualifier() const {
3797-
return CXXDependentScopeMemberExprBits.HasQualifier;
3798-
}
3799-
3800-
/// If the member name was qualified, retrieves the nested-name-specifier
3801-
/// that precedes the member name, with source-location information.
3802-
NestedNameSpecifierLoc getQualifierLoc() const {
3803-
if (!hasQualifier())
3804-
return NestedNameSpecifierLoc();
3805-
return *getTrailingObjects<NestedNameSpecifierLoc>();
3787+
SourceLocation getOperatorLoc() const {
3788+
return CXXDependentScopeMemberExprBits.OperatorLoc;
38063789
}
38073790

3808-
/// If the member name was qualified, retrieves the
3809-
/// nested-name-specifier that precedes the member name. Otherwise, returns
3810-
/// NULL.
3791+
/// Retrieve the nested-name-specifier that qualifies the member name.
38113792
NestedNameSpecifier *getQualifier() const {
3812-
return getQualifierLoc().getNestedNameSpecifier();
3793+
return QualifierLoc.getNestedNameSpecifier();
38133794
}
38143795

3815-
/// Retrieve the declarations found by unqualified lookup for the first
3816-
/// component name of the nested-name-specifier, if any.
3817-
ArrayRef<DeclAccessPair> unqualified_lookups() const {
3818-
if (!getNumUnqualifiedLookups())
3819-
return std::nullopt;
3820-
return {getTrailingObjects<DeclAccessPair>(), getNumUnqualifiedLookups()};
3796+
/// Retrieve the nested-name-specifier that qualifies the member
3797+
/// name, with source location information.
3798+
NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3799+
3800+
/// Retrieve the first part of the nested-name-specifier that was
3801+
/// found in the scope of the member access expression when the member access
3802+
/// was initially parsed.
3803+
///
3804+
/// This function only returns a useful result when member access expression
3805+
/// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
3806+
/// returned by this function describes what was found by unqualified name
3807+
/// lookup for the identifier "Base" within the scope of the member access
3808+
/// expression itself. At template instantiation time, this information is
3809+
/// combined with the results of name lookup into the type of the object
3810+
/// expression itself (the class type of x).
3811+
NamedDecl *getFirstQualifierFoundInScope() const {
3812+
if (!hasFirstQualifierFoundInScope())
3813+
return nullptr;
3814+
return *getTrailingObjects<NamedDecl *>();
38213815
}
38223816

38233817
/// Retrieve the name of the member that this expression refers to.

clang/include/clang/AST/Stmt.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,19 +1020,18 @@ class alignas(void *) Stmt {
10201020
LLVM_PREFERRED_TYPE(bool)
10211021
unsigned IsArrow : 1;
10221022

1023-
/// True if this member expression used a nested-name-specifier to
1024-
/// refer to the member, e.g., "x->Base::f".
1025-
LLVM_PREFERRED_TYPE(bool)
1026-
unsigned HasQualifier : 1;
1027-
10281023
/// Whether this member expression has info for explicit template
10291024
/// keyword and arguments.
10301025
LLVM_PREFERRED_TYPE(bool)
10311026
unsigned HasTemplateKWAndArgsInfo : 1;
10321027

1033-
/// Number of declarations found by unqualified lookup for the
1034-
/// first component name of the nested-name-specifier.
1035-
unsigned NumUnqualifiedLookups;
1028+
/// See getFirstQualifierFoundInScope() and the comment listing
1029+
/// the trailing objects.
1030+
LLVM_PREFERRED_TYPE(bool)
1031+
unsigned HasFirstQualifierFoundInScope : 1;
1032+
1033+
/// The location of the '->' or '.' operator.
1034+
SourceLocation OperatorLoc;
10361035
};
10371036

10381037
class OverloadExprBitfields {

clang/include/clang/AST/UnresolvedSet.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ class UnresolvedSetImpl {
9797
decls().push_back(DeclAccessPair::make(D, AS));
9898
}
9999

100-
void addAllDecls(ArrayRef<DeclAccessPair> Other) {
101-
append(iterator(Other.begin()), iterator(Other.end()));
102-
}
103-
104100
/// Replaces the given declaration with the new one, once.
105101
///
106102
/// \return true if the set changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,9 @@ def missing_template_arg_list_after_template_kw : Extension<
895895
"keyword">, InGroup<DiagGroup<"missing-template-arg-list-after-template-kw">>,
896896
DefaultError;
897897

898-
def ext_missing_dependent_template_keyword : ExtWarn<
898+
def err_missing_dependent_template_keyword : Error<
899+
"use 'template' keyword to treat '%0' as a dependent template name">;
900+
def warn_missing_dependent_template_keyword : ExtWarn<
899901
"use 'template' keyword to treat '%0' as a dependent template name">;
900902

901903
def ext_extern_template : Extension<

clang/include/clang/Parse/Parser.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3368,11 +3368,15 @@ class Parser : public CodeCompletionHandler {
33683368
BaseResult ParseBaseSpecifier(Decl *ClassDecl);
33693369
AccessSpecifier getAccessSpecifierIfPresent() const;
33703370

3371-
bool ParseUnqualifiedIdTemplateId(
3372-
CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors,
3373-
SourceLocation TemplateKWLoc, SourceLocation TildeLoc,
3374-
IdentifierInfo *Name, SourceLocation NameLoc, bool EnteringContext,
3375-
UnqualifiedId &Id, bool AssumeTemplateId);
3371+
bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
3372+
ParsedType ObjectType,
3373+
bool ObjectHadErrors,
3374+
SourceLocation TemplateKWLoc,
3375+
IdentifierInfo *Name,
3376+
SourceLocation NameLoc,
3377+
bool EnteringContext,
3378+
UnqualifiedId &Id,
3379+
bool AssumeTemplateId);
33763380
bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
33773381
ParsedType ObjectType,
33783382
UnqualifiedId &Result);

clang/include/clang/Sema/DeclSpec.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class CXXScopeSpec {
7575
SourceRange Range;
7676
NestedNameSpecifierLocBuilder Builder;
7777
ArrayRef<TemplateParameterList *> TemplateParamLists;
78-
ArrayRef<DeclAccessPair> UnqualifiedLookups;
7978

8079
public:
8180
SourceRange getRange() const { return Range; }
@@ -92,13 +91,6 @@ class CXXScopeSpec {
9291
return TemplateParamLists;
9392
}
9493

95-
void setUnqualifiedLookups(ArrayRef<DeclAccessPair> Found) {
96-
UnqualifiedLookups = Found;
97-
}
98-
ArrayRef<DeclAccessPair> getUnqualifiedLookups() const {
99-
return UnqualifiedLookups;
100-
}
101-
10294
/// Retrieve the representation of the nested-name-specifier.
10395
NestedNameSpecifier *getScopeRep() const {
10496
return Builder.getRepresentation();

clang/include/clang/Sema/Lookup.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,11 @@ class LookupResult {
483483
ResultKind = Found;
484484
}
485485

486-
void addAllDecls(ArrayRef<DeclAccessPair> Other) {
487-
Decls.addAllDecls(Other);
488-
ResultKind = Found;
489-
}
490-
491486
/// Add all the declarations from another set of lookup
492487
/// results.
493488
void addAllDecls(const LookupResult &Other) {
494-
addAllDecls(Other.Decls.pairs());
489+
Decls.append(Other.Decls.begin(), Other.Decls.end());
490+
ResultKind = Found;
495491
}
496492

497493
/// Determine whether no result was found because we could not

clang/include/clang/Sema/Sema.h

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,8 +2802,7 @@ class Sema final : public SemaBase {
28022802
/// (e.g., Base::), perform name lookup for that identifier as a
28032803
/// nested-name-specifier within the given scope, and return the result of
28042804
/// that name lookup.
2805-
bool LookupFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS,
2806-
UnresolvedSetImpl &R);
2805+
NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS);
28072806

28082807
/// Keeps information about an identifier in a nested-name-spec.
28092808
///
@@ -2843,6 +2842,9 @@ class Sema final : public SemaBase {
28432842
/// \param EnteringContext If true, enter the context specified by the
28442843
/// nested-name-specifier.
28452844
/// \param SS Optional nested name specifier preceding the identifier.
2845+
/// \param ScopeLookupResult Provides the result of name lookup within the
2846+
/// scope of the nested-name-specifier that was computed at template
2847+
/// definition time.
28462848
/// \param ErrorRecoveryLookup Specifies if the method is called to improve
28472849
/// error recovery and what kind of recovery is performed.
28482850
/// \param IsCorrectedToColon If not null, suggestion of replace '::' -> ':'
@@ -2851,6 +2853,11 @@ class Sema final : public SemaBase {
28512853
/// not '::'.
28522854
/// \param OnlyNamespace If true, only considers namespaces in lookup.
28532855
///
2856+
/// This routine differs only slightly from ActOnCXXNestedNameSpecifier, in
2857+
/// that it contains an extra parameter \p ScopeLookupResult, which provides
2858+
/// the result of name lookup within the scope of the nested-name-specifier
2859+
/// that was computed at template definition time.
2860+
///
28542861
/// If ErrorRecoveryLookup is true, then this call is used to improve error
28552862
/// recovery. This means that it should not emit diagnostics, it should
28562863
/// just return true on failure. It also means it should only return a valid
@@ -2859,6 +2866,7 @@ class Sema final : public SemaBase {
28592866
/// specifier.
28602867
bool BuildCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo,
28612868
bool EnteringContext, CXXScopeSpec &SS,
2869+
NamedDecl *ScopeLookupResult,
28622870
bool ErrorRecoveryLookup,
28632871
bool *IsCorrectedToColon = nullptr,
28642872
bool OnlyNamespace = false);
@@ -8558,12 +8566,11 @@ class Sema final : public SemaBase {
85588566
const TemplateArgumentListInfo *TemplateArgs,
85598567
bool IsDefiniteInstance, const Scope *S);
85608568

8561-
ExprResult
8562-
ActOnDependentMemberExpr(Expr *Base, QualType BaseType, bool IsArrow,
8563-
SourceLocation OpLoc, const CXXScopeSpec &SS,
8564-
SourceLocation TemplateKWLoc,
8565-
const DeclarationNameInfo &NameInfo,
8566-
const TemplateArgumentListInfo *TemplateArgs);
8569+
ExprResult ActOnDependentMemberExpr(
8570+
Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OpLoc,
8571+
const CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8572+
NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo,
8573+
const TemplateArgumentListInfo *TemplateArgs);
85678574

85688575
/// The main callback when the parser finds something like
85698576
/// expression . [nested-name-specifier] identifier
@@ -8619,14 +8626,15 @@ class Sema final : public SemaBase {
86198626
ExprResult BuildMemberReferenceExpr(
86208627
Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow,
86218628
CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8622-
const DeclarationNameInfo &NameInfo,
8629+
NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo,
86238630
const TemplateArgumentListInfo *TemplateArgs, const Scope *S,
86248631
ActOnMemberAccessExtraArgs *ExtraArgs = nullptr);
86258632

86268633
ExprResult
86278634
BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc,
86288635
bool IsArrow, const CXXScopeSpec &SS,
8629-
SourceLocation TemplateKWLoc, LookupResult &R,
8636+
SourceLocation TemplateKWLoc,
8637+
NamedDecl *FirstQualifierInScope, LookupResult &R,
86308638
const TemplateArgumentListInfo *TemplateArgs,
86318639
const Scope *S, bool SuppressQualifierCheck = false,
86328640
ActOnMemberAccessExtraArgs *ExtraArgs = nullptr);
@@ -11114,14 +11122,15 @@ class Sema final : public SemaBase {
1111411122
QualType ObjectType, bool EnteringContext,
1111511123
RequiredTemplateKind RequiredTemplate = SourceLocation(),
1111611124
AssumedTemplateKind *ATK = nullptr,
11117-
bool AllowTypoCorrection = true, bool MayBeNNS = false);
11125+
bool AllowTypoCorrection = true);
1111811126

11119-
TemplateNameKind
11120-
isTemplateName(Scope *S, CXXScopeSpec &SS, bool hasTemplateKeyword,
11121-
const UnqualifiedId &Name, ParsedType ObjectType,
11122-
bool EnteringContext, TemplateTy &Template,
11123-
bool &MemberOfUnknownSpecialization,
11124-
bool Disambiguation = false, bool MayBeNNS = false);
11127+
TemplateNameKind isTemplateName(Scope *S, CXXScopeSpec &SS,
11128+
bool hasTemplateKeyword,
11129+
const UnqualifiedId &Name,
11130+
ParsedType ObjectType, bool EnteringContext,
11131+
TemplateTy &Template,
11132+
bool &MemberOfUnknownSpecialization,
11133+
bool Disambiguation = false);
1112511134

1112611135
/// Try to resolve an undeclared template name as a type template.
1112711136
///
@@ -11450,11 +11459,12 @@ class Sema final : public SemaBase {
1145011459
/// For example, given "x.MetaFun::template apply", the scope specifier
1145111460
/// \p SS will be "MetaFun::", \p TemplateKWLoc contains the location
1145211461
/// of the "template" keyword, and "apply" is the \p Name.
11453-
TemplateNameKind
11454-
ActOnTemplateName(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
11455-
const UnqualifiedId &Name, ParsedType ObjectType,
11456-
bool EnteringContext, TemplateTy &Template,
11457-
bool AllowInjectedClassName = false, bool MayBeNNS = false);
11462+
TemplateNameKind ActOnTemplateName(Scope *S, CXXScopeSpec &SS,
11463+
SourceLocation TemplateKWLoc,
11464+
const UnqualifiedId &Name,
11465+
ParsedType ObjectType,
11466+
bool EnteringContext, TemplateTy &Template,
11467+
bool AllowInjectedClassName = false);
1145811468

1145911469
DeclResult ActOnClassTemplateSpecialization(
1146011470
Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,

0 commit comments

Comments
 (0)