r186128 - Provide a fixit hint for changing '->' to '.' if there is no operator->
Nico Weber
thakis at chromium.org
Thu Jul 11 22:16:20 PDT 2013
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)
> + } 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
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130711/ce3c1884/attachment.html>
More information about the cfe-commits
mailing list