Hi,
when trying to access a member of a namespace/class/struct/enum, clang currently just prints that the given namespace does not have a member with the given name, for example:
./enum.cpp:12:7: error: no member named 'b' in 'Foo' foo.b = 10; ~~~ ^ 1 error generated.
However, for programmers it is usually also important to know where the namespace has been declared, e.g. in the example above it would be useful to know where foo's type has been declared. The following patch adds support for this by simply printing a note:
./enum.cpp:12:7: error: no member named 'b' in 'Foo' foo.b = 10; ~~~ ^ ./enum.cpp:3:7: note: 'Foo' declared here class Foo { ^~~ 1 error generated.
That is of course a very simple example, but I think this adds value in real-world scenarios.
The patch is unfortunately all over the place and mostly updating test cases with the additional expected note.
In addition to the usual review I'd like opinions on the following open questions:
- There are now three places where the patch adds the exact same code, would a helper function (in Sema?) be better and if so, where is the best place for it?
- The notes are pretty clunky to read when the namespace is created by a lambda: " note: '(lambda at enum.cpp:41:12)' declared here" - should lambdas simply be ignored (how to do that?) or should I handle them differently?
- The patch only emits the note if clang does not output a typo correction. I thought it might not be as useful in this case since it would clutter the output and chances are that the typo fix _is_ the right thing to show. Opinions on this?
Thanks,
Timm