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

Kaelyn Uhrain rikka at google.com
Mon Jul 15 12:57:54 PDT 2013


On Fri, Jul 12, 2013 at 4:01 PM, Richard Smith <richard at metafoo.co.uk>wrote:

> On Fri, Jul 12, 2013 at 3:16 PM, Kaelyn Uhrain <rikka at google.com> wrote:
> > On Thu, Jul 11, 2013 at 10:16 PM, Nico Weber <thakis at chromium.org>
> wrote:
> >>
> >> Nice, thanks!
> >>
> >> On Thu, Jul 11, 2013 at 3:38 PM, Kaelyn Uhrain <rikka at google.com>
> 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.
>
> We usually handle these cases by adding a note to carry the fixit:
>
> error: member reference type 'PR15045::Cl0' is not a pointer
>    return c->a;
>           ^
> note: did you mean to use '.' instead?
>    return c->a;
>            ~~
>            .
>

Ah, I see! Just submitted r186342 to move the fixit into a separate note.
Thanks Richard!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130715/3afd0066/attachment.html>


More information about the cfe-commits mailing list