On Fri, Jul 12, 2013 at 3:16 PM, Kaelyn Uhrain <<a href="mailto:rikka@google.com">rikka@google.com</a>> wrote:<br>> On Thu, Jul 11, 2013 at 10:16 PM, Nico Weber <<a href="mailto:thakis@chromium.org">thakis@chromium.org</a>> wrote:<br>
>><br>>> Nice, thanks!<br>>><br>>> On Thu, Jul 11, 2013 at 3:38 PM, Kaelyn Uhrain <<a href="mailto:rikka@google.com">rikka@google.com</a>> wrote:<br>>>><br>>>> Author: rikka<br>
>>> Date: Thu Jul 11 17:38:30 2013<br>>>> New Revision: 186128<br>>>><br>>>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=186128&view=rev">http://llvm.org/viewvc/llvm-project?rev=186128&view=rev</a><br>
>>> Log:<br>>>> Provide a fixit hint for changing '->' to '.' if there is no operator-><br>>>> defined for a class.<br>>>><br>>>> Modified:<br>>>>     cfe/trunk/lib/Sema/SemaOverload.cpp<br>
>>>     cfe/trunk/test/FixIt/fixit.cpp<br>>>><br>>>> Modified: cfe/trunk/lib/Sema/SemaOverload.cpp<br>>>> URL:<br>>>> <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=186128&r1=186127&r2=186128&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=186128&r1=186127&r2=186128&view=diff</a><br>
>>><br>>>> ==============================================================================<br>>>> --- cfe/trunk/lib/Sema/SemaOverload.cpp (original)<br>>>> +++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Jul 11 17:38:30 2013<br>
>>> @@ -11353,10 +11353,17 @@ Sema::BuildOverloadedArrowExpr(Scope *S,<br>>>>      break;<br>>>><br>>>>    case OR_No_Viable_Function:<br>>>> -    if (CandidateSet.empty())<br>
>>> -      Diag(OpLoc, diag::err_typecheck_member_reference_arrow)<br>>>> -        << Base->getType() << Base->getSourceRange();<br>>>> -    else<br>>>> +    if (CandidateSet.empty()) {<br>
>>> +      QualType BaseType = Base->getType();<br>>>> +      if (BaseType->isRecordType() && !BaseType->isPointerType()) {<br>>>> +        Diag(OpLoc, diag::err_typecheck_member_reference_suggestion)<br>
>>> +          << BaseType << 1 << Base->getSourceRange()<br>>>> +          << FixItHint::CreateReplacement(OpLoc, ".");<br>>><br>>><br>>> Since this is a fixit on an error, don't you need to fix up the AST?<br>
>> (<a href="http://clang.llvm.org/docs/InternalsManual.html#fix-it-hints">http://clang.llvm.org/docs/InternalsManual.html#fix-it-hints</a>)<br>><br>><br>> This is a tricky case because of how operator-> is recursively applied to<br>
> it's own result... from what I could tell, recovery would require not just<br>> breaking out of the loop for operator-> in ActOnStartCXXMemberReference but<br>> also telling the parser to start over with the '.' in place of the '->',<br>
> which I have no idea how to do from several function-call-layers within<br>> Sema. And I couldn't add the fixit to a note as the internals manual<br>> suggests since there is no note associated with the diagnostic.<br>
<br>We usually handle these cases by adding a note to carry the fixit:<br><br><font face="courier new, monospace">error: member reference type 'PR15045::Cl0' is not a pointer<br>   return c->a;<br>          ^<br>
note: did you mean to use '.' instead?<br>   return c->a;</font><div><font face="courier new, monospace">           ~~<br>           .</font></div>