-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang][Sema] Fix bug where operator-> typo corrects in the current instantiation #91972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: Krystian Stasiowski (sdkrystian) ChangesFixes this bug introduced in #90152. This bug occurs when typo-correction attempts to fix a reference to a non-existent member of the current instantiation (even though Full diff: https://github.com/llvm/llvm-project/pull/91972.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp
index 9fa69da4f9685..a3411b3036d5e 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -995,11 +995,9 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
// arrow operator was used with a dependent non-pointer object expression,
// build a CXXDependentScopeMemberExpr.
if (R.wasNotFoundInCurrentInstantiation() ||
- (IsArrow && !BaseExprType->isPointerType() &&
- BaseExprType->isDependentType()) ||
(R.getLookupName().getCXXOverloadedOperator() == OO_Equal &&
- (SS.isSet() ? SS.getScopeRep()->isDependent()
- : BaseExprType->isDependentType())))
+ (SS.isSet() ? SS.getScopeRep()->isDependent()
+ : BaseExprType->isDependentType())))
return ActOnDependentMemberExpr(BaseExpr, BaseExprType, IsArrow, OpLoc, SS,
TemplateKWLoc, FirstQualifierInScope,
R.getLookupNameInfo(), TemplateArgs);
@@ -1322,7 +1320,11 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult &R,
else if (const ObjCObjectPointerType *Ptr =
BaseType->getAs<ObjCObjectPointerType>())
BaseType = Ptr->getPointeeType();
- else if (!BaseType->isDependentType()) {
+ else if (BaseType->isFunctionType())
+ goto fail;
+ else if (BaseType->isDependentType())
+ BaseType = S.Context.DependentTy;
+ else {
if (BaseType->isRecordType()) {
// Recover from arrow accesses to records, e.g.:
// struct MyRecord foo;
@@ -1337,8 +1339,6 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult &R,
<< FixItHint::CreateReplacement(OpLoc, ".");
}
IsArrow = false;
- } else if (BaseType->isFunctionType()) {
- goto fail;
} else {
S.Diag(MemberLoc, diag::err_typecheck_member_reference_arrow)
<< BaseType << BaseExpr.get()->getSourceRange();
diff --git a/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp b/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp
index 1adbc33a701c1..fafd54bde7622 100644
--- a/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp
@@ -551,4 +551,11 @@ namespace N4 {
template void D<B>::instantiated(D); // expected-note {{in instantiation of}}
+ template<typename T>
+ struct Typo {
+ void not_instantiated(Typo a) {
+ a->Not_instantiated;
+ a->typo;
+ }
+ };
} // namespace N4
|
f5d456a
to
a013806
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs a release note? I know the only case we have right now is because of your other patch, but perhaps this affects elsewhere too?
@erichkeane I don't think we need a release note since the code changes are in |
Ah! Missed that, yes, you're right. |
cherry-picked: 8009bbe [email protected] Tue Apr 30 14:25:09 2024 -0400 Reapply "[Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (llvm#84050)" (llvm#90152) 3191e0b [email protected] Fri May 3 17:07:52 2024 -0400 [Clang][Sema] Fix template name lookup for operator= (llvm#90999) 62b5b61 [email protected] Wed May 8 20:49:59 2024 -0400 [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (llvm#91498) 75ebcbf [email protected] Thu May 9 16:34:40 2024 -0400 [Clang][Sema] Revert changes to operator= lookup in templated classes from llvm#91498, llvm#90999, and llvm#90152 (llvm#91620) 596a9c1 [email protected] Mon May 13 12:24:46 2024 -0400 [Clang][Sema] Fix bug where operator-> typo corrects in the current instantiation (llvm#91972) fd87d76 [email protected] Mon May 20 13:55:01 2024 -0400 [Clang][Sema] Don't build CXXDependentScopeMemberExprs for potentially implicit class member access expressions (llvm#92318) e75b58c [email protected] Mon May 20 14:50:58 2024 -0400 [Clang][Sema] Do not add implicit 'const' when matching constexpr function template explicit specializations after C++14 (llvm#92449) bae2c54 [email protected] Mon Jul 1 20:55:57 2024 +0300 [clang][NFC] Move documentation of `Sema` functions into `Sema.h` e6d305e [email protected] Mon Sep 4 16:54:42 2023 +0200 Add support of Windows Trace Logging macros Change-Id: I521b2ebabd7eb9a0df78c577992bfd8508ba44fd
Fixes this bug introduced in #90152.
This bug occurs when typo-correction attempts to fix a reference to a non-existent member of the current instantiation (even though
operator->
may return a different type than the object type). This patch fixes it by simply considering the object expression to be of typeASTContext::DependentTy
when the arrow operator is used with a dependent non-pointer non-function operand (after any implicit conversions).