Provide a fixit hint for changing '->' to '.' if there is no operator->
defined for a class. llvm-svn: 186128
This commit is contained in:
parent
04bd684074
commit
1bb5dbf628
|
@ -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);
|
||||
|
|
|
@ -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 '.'?}}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue