Skip to content

Commit 39b5189

Browse files
committed
[Clang][Sema] Fix arrow operator for expressions with non-pointer type that is the current instantiation
1 parent 6ea7f9d commit 39b5189

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

clang/lib/Sema/SemaExprMember.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,24 +1323,24 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult &R,
13231323
if (IsArrow) {
13241324
if (const PointerType *Ptr = BaseType->getAs<PointerType>())
13251325
BaseType = Ptr->getPointeeType();
1326-
else if (!BaseType->isDependentType()) {
1326+
else if (BaseType->getAsRecordDecl()) {
1327+
// Recover from arrow accesses to records, e.g.:
1328+
// struct MyRecord foo;
1329+
// foo->bar
1330+
// This is actually well-formed in C++ if MyRecord has an
1331+
// overloaded operator->, but that should have been dealt with
1332+
// by now--or a diagnostic message already issued if a problem
1333+
// was encountered while looking for the overloaded operator->.
1334+
if (!S.getLangOpts().CPlusPlus) {
1335+
S.Diag(OpLoc, diag::err_typecheck_member_reference_suggestion)
1336+
<< BaseType << int(IsArrow) << BaseExpr.get()->getSourceRange()
1337+
<< FixItHint::CreateReplacement(OpLoc, ".");
1338+
}
1339+
IsArrow = false;
1340+
} else if (!BaseType->isDependentType()) {
13271341
if (const ObjCObjectPointerType *Ptr =
1328-
BaseType->getAs<ObjCObjectPointerType>())
1342+
BaseType->getAs<ObjCObjectPointerType>()) {
13291343
BaseType = Ptr->getPointeeType();
1330-
else if (BaseType->isRecordType()) {
1331-
// Recover from arrow accesses to records, e.g.:
1332-
// struct MyRecord foo;
1333-
// foo->bar
1334-
// This is actually well-formed in C++ if MyRecord has an
1335-
// overloaded operator->, but that should have been dealt with
1336-
// by now--or a diagnostic message already issued if a problem
1337-
// was encountered while looking for the overloaded operator->.
1338-
if (!S.getLangOpts().CPlusPlus) {
1339-
S.Diag(OpLoc, diag::err_typecheck_member_reference_suggestion)
1340-
<< BaseType << int(IsArrow) << BaseExpr.get()->getSourceRange()
1341-
<< FixItHint::CreateReplacement(OpLoc, ".");
1342-
}
1343-
IsArrow = false;
13441344
} else if (BaseType->isFunctionType()) {
13451345
goto fail;
13461346
} else {

0 commit comments

Comments
 (0)