aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaExprMember.cpp
diff options
context:
space:
mode:
authorMikhail Goncharov <goncharov.mikhail@gmail.com>2024-04-15 08:41:32 +0200
committerMikhail Goncharov <goncharov.mikhail@gmail.com>2024-04-15 08:41:32 +0200
commit46131aaf616c5cd97df0ec376a7e6ba475e1913c (patch)
treeea2585af24d4c3bc1ebf4d15d533472d85ce5e4a /clang/lib/Sema/SemaExprMember.cpp
parent2cc0c2104909558680409f8a8f39755936305e72 (diff)
downloadllvm-46131aaf616c5cd97df0ec376a7e6ba475e1913c.zip
llvm-46131aaf616c5cd97df0ec376a7e6ba475e1913c.tar.gz
llvm-46131aaf616c5cd97df0ec376a7e6ba475e1913c.tar.bz2
Revert "Reapply "[Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (#87541)" (#88311)"
This reverts commit aa80f3ec48419a73aafcc2ff947c6dd1e3734481. See https://github.com/llvm/llvm-project/pull/88311#issuecomment-2052291140. There is a fix forward proposed but I am reverting this commit to fix trunk.
Diffstat (limited to 'clang/lib/Sema/SemaExprMember.cpp')
-rw-r--r--clang/lib/Sema/SemaExprMember.cpp63
1 files changed, 14 insertions, 49 deletions
diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp
index eeac753..32998ae 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -61,10 +61,6 @@ enum IMAKind {
/// The reference is a contextually-permitted abstract member reference.
IMA_Abstract,
- /// Whether the context is static is dependent on the enclosing template (i.e.
- /// in a dependent class scope explicit specialization).
- IMA_Dependent,
-
/// The reference may be to an unresolved using declaration and the
/// context is not an instance method.
IMA_Unresolved_StaticOrExplicitContext,
@@ -95,18 +91,10 @@ static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef,
DeclContext *DC = SemaRef.getFunctionLevelDeclContext();
- bool couldInstantiateToStatic = false;
- bool isStaticOrExplicitContext = SemaRef.CXXThisTypeOverride.isNull();
-
- if (auto *MD = dyn_cast<CXXMethodDecl>(DC)) {
- if (MD->isImplicitObjectMemberFunction()) {
- isStaticOrExplicitContext = false;
- // A dependent class scope function template explicit specialization
- // that is neither declared 'static' nor with an explicit object
- // parameter could instantiate to a static or non-static member function.
- couldInstantiateToStatic = MD->getDependentSpecializationInfo();
- }
- }
+ bool isStaticOrExplicitContext =
+ SemaRef.CXXThisTypeOverride.isNull() &&
+ (!isa<CXXMethodDecl>(DC) || cast<CXXMethodDecl>(DC)->isStatic() ||
+ cast<CXXMethodDecl>(DC)->isExplicitObjectMemberFunction());
if (R.isUnresolvableResult())
return isStaticOrExplicitContext ? IMA_Unresolved_StaticOrExplicitContext
@@ -135,9 +123,6 @@ static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef,
if (Classes.empty())
return IMA_Static;
- if (couldInstantiateToStatic)
- return IMA_Dependent;
-
// C++11 [expr.prim.general]p12:
// An id-expression that denotes a non-static data member or non-static
// member function of a class can only be used:
@@ -278,52 +263,32 @@ static void diagnoseInstanceReference(Sema &SemaRef,
}
}
-bool Sema::isPotentialImplicitMemberAccess(const CXXScopeSpec &SS,
- LookupResult &R,
- bool IsAddressOfOperand) {
- if (!getLangOpts().CPlusPlus)
- return false;
- else if (R.empty() || !R.begin()->isCXXClassMember())
- return false;
- else if (!IsAddressOfOperand)
- return true;
- else if (!SS.isEmpty())
- return false;
- else if (R.isOverloadedResult())
- return false;
- else if (R.isUnresolvableResult())
- return true;
- else
- return isa<FieldDecl, IndirectFieldDecl, MSPropertyDecl>(R.getFoundDecl());
-}
-
/// Builds an expression which might be an implicit member expression.
ExprResult Sema::BuildPossibleImplicitMemberExpr(
const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R,
- const TemplateArgumentListInfo *TemplateArgs, const Scope *S) {
- switch (IMAKind Classification = ClassifyImplicitMemberAccess(*this, R)) {
+ const TemplateArgumentListInfo *TemplateArgs, const Scope *S,
+ UnresolvedLookupExpr *AsULE) {
+ switch (ClassifyImplicitMemberAccess(*this, R)) {
case IMA_Instance:
+ return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, true, S);
+
case IMA_Mixed:
case IMA_Mixed_Unrelated:
case IMA_Unresolved:
- return BuildImplicitMemberExpr(
- SS, TemplateKWLoc, R, TemplateArgs,
- /*IsKnownInstance=*/Classification == IMA_Instance, S);
+ return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, false,
+ S);
+
case IMA_Field_Uneval_Context:
Diag(R.getNameLoc(), diag::warn_cxx98_compat_non_static_member_use)
<< R.getLookupNameInfo().getName();
[[fallthrough]];
case IMA_Static:
case IMA_Abstract:
- case IMA_Dependent:
case IMA_Mixed_StaticOrExplicitContext:
case IMA_Unresolved_StaticOrExplicitContext:
if (TemplateArgs || TemplateKWLoc.isValid())
- return BuildTemplateIdExpr(SS, TemplateKWLoc, R, /*RequiresADL=*/false,
- TemplateArgs);
- return BuildDeclarationNameExpr(
- SS, R, /*NeedsADL=*/false, /*AcceptInvalidDecl=*/false,
- /*NeedUnresolved=*/Classification == IMA_Dependent);
+ return BuildTemplateIdExpr(SS, TemplateKWLoc, R, false, TemplateArgs);
+ return AsULE ? AsULE : BuildDeclarationNameExpr(SS, R, false);
case IMA_Error_StaticOrExplicitContext:
case IMA_Error_Unrelated: