Provide a fixit hint for changing '->' to '.' if there is no operator->

defined for a class.

llvm-svn: 186128
This commit is contained in:
Kaelyn Uhrain 2013-07-11 22:38:30 +00:00
parent 04bd684074
commit 1bb5dbf628
2 changed files with 23 additions and 4 deletions

View File

@ -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);

View File

@ -312,3 +312,15 @@ namespace PR5066 {
template<typename T> struct X {};
X<int *p> 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 '.'?}}
}
}