From: Kaelyn Uhrain Date: Thu, 11 Jul 2013 22:38:30 +0000 (+0000) Subject: Provide a fixit hint for changing '->' to '.' if there is no operator-> X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=45c3ba76e90753006bdfeea884972ddd24cb3131;p=clang Provide a fixit hint for changing '->' to '.' if there is no operator-> defined for a class. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186128 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 51e87ebba8..01fd582f5e 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -11353,10 +11353,17 @@ Sema::BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc) { break; case OR_No_Viable_Function: - if (CandidateSet.empty()) - Diag(OpLoc, diag::err_typecheck_member_reference_arrow) - << Base->getType() << Base->getSourceRange(); - else + if (CandidateSet.empty()) { + QualType BaseType = Base->getType(); + if (BaseType->isRecordType() && !BaseType->isPointerType()) { + Diag(OpLoc, diag::err_typecheck_member_reference_suggestion) + << BaseType << 1 << Base->getSourceRange() + << FixItHint::CreateReplacement(OpLoc, "."); + } else { + Diag(OpLoc, diag::err_typecheck_member_reference_arrow) + << BaseType << Base->getSourceRange(); + } + } else Diag(OpLoc, diag::err_ovl_no_viable_oper) << "operator->" << Base->getSourceRange(); CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Base); diff --git a/test/FixIt/fixit.cpp b/test/FixIt/fixit.cpp index 22c1003e8c..a858a82e7f 100644 --- a/test/FixIt/fixit.cpp +++ b/test/FixIt/fixit.cpp @@ -312,3 +312,15 @@ namespace PR5066 { template struct X {}; X x; // expected-error {{type-id cannot have a name}} } + +namespace PR15045 { + class Cl0 { + public: + int a; + }; + + int f() { + Cl0 c; + return c->a; // expected-error {{member reference type 'PR15045::Cl0' is not a pointer; maybe you meant to use '.'?}} + } +}