[cfe-commits] [PATCH] Add suggestion for replacing '.' with '->' in failed member reference

David Blaikie dblaikie at gmail.com
Tue Apr 24 14:37:43 PDT 2012

On Tue, Apr 24, 2012 at 2:28 PM, Kaelyn Uhrain <rikka at google.com> wrote:
> This patch adds a suggestion and related fixit for when a member reference
> using '.' such as "foo.bar()" fails because bar() is not a member of foo,
> but foo defines an operator-> and bar() is a member of the object returned
> by foo's operator->.

Oh, nice - I'd noticed this was lacking a while ago, glad to see it
being improved/fixed.

> A more concrete case where this is helpful is with
> classes like std::shared_ptr or even clang's QualType that have an
> operator-> and the user accidentally types "." where they meant to use "->"
> (since, you know, the variables in question aren't actually pointers).
> I'd like some pre-commit feedback since:
>   * while it's a fairly simple patch, there is some ugliness to it for
> trying out the correction to see if it causes additional errors,

I don't have a very informed opinion here - but for what it's worth I
think the code is fairly simple/tidy/isolated, given what it's doing.

>   * the error text feels a bit verbose, though it's hardly the longest error
> message and I can't think of a good way to shorten it, and

The text seems reasonable, though it's a bit long in your example in
part because of the names - but also because we're printing the fully
qualified name of the base expression's type. Is there any
reasonable/easy way we can print something closer to/exactly as the
user wrote? ("wrapped_ptr<Worker>") - I'm not sure whether that's a
good thing to do, or how it compares to other diagnostics that might
have this problem.

>   * I am undecided whether there should be an accompanying note, and if so
> what the note should refer to.

I doubt it - but it shouldn't be too hard to compare this diagnostic
to the other ./-> mismatch recoveries we have to ensure consistency &
I think that's probably sufficient.

- David

More information about the cfe-commits mailing list