On Thu, Jul 11, 2013 at 10:16 PM, Nico Weber <[email protected]> wrote:
> Nice, thanks! > > On Thu, Jul 11, 2013 at 3:38 PM, Kaelyn Uhrain <[email protected]> wrote: > >> Author: rikka >> Date: Thu Jul 11 17:38:30 2013 >> New Revision: 186128 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=186128&view=rev >> Log: >> Provide a fixit hint for changing '->' to '.' if there is no operator-> >> defined for a class. >> >> Modified: >> cfe/trunk/lib/Sema/SemaOverload.cpp >> cfe/trunk/test/FixIt/fixit.cpp >> >> Modified: cfe/trunk/lib/Sema/SemaOverload.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=186128&r1=186127&r2=186128&view=diff >> >> ============================================================================== >> --- cfe/trunk/lib/Sema/SemaOverload.cpp (original) >> +++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Jul 11 17:38:30 2013 >> @@ -11353,10 +11353,17 @@ Sema::BuildOverloadedArrowExpr(Scope *S, >> 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, "."); >> > > Since this is a fixit on an error, don't you need to fix up the AST? ( > http://clang.llvm.org/docs/InternalsManual.html#fix-it-hints) > This is a tricky case because of how operator-> is recursively applied to it's own result... from what I could tell, recovery would require not just breaking out of the loop for operator-> in ActOnStartCXXMemberReference but also telling the parser to start over with the '.' in place of the '->', which I have no idea how to do from several function-call-layers within Sema. And I couldn't add the fixit to a note as the internals manual suggests since there is no note associated with the diagnostic. > >> + } 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); >> >> Modified: cfe/trunk/test/FixIt/fixit.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit.cpp?rev=186128&r1=186127&r2=186128&view=diff >> >> ============================================================================== >> --- cfe/trunk/test/FixIt/fixit.cpp (original) >> +++ cfe/trunk/test/FixIt/fixit.cpp Thu Jul 11 17:38:30 2013 >> @@ -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 '.'?}} >> + } >> +} >> >> >> _______________________________________________ >> cfe-commits mailing list >> [email protected] >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >> > >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
