[cfe-commits] r137966 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/SemaCXX/function-redecl.cpp

Kaelyn Uhrain rikka at google.com
Thu Aug 18 15:25:18 PDT 2011


On Thu, Aug 18, 2011 at 2:30 PM, Jordy Rose <jediknil at belkadan.com> wrote:

> Haven't tested it, but it seems like this would also be bad for
> const/non-const mismatches:
>
> struct A { int typo() const; };
> int A::typo_() { return 3; }
>

In this case the typo-corrected function would be close but not exact. The
correction note points to the definition of the correction:

 tmp.cpp:2:8: error: out-of-line definition of 'typo_' does not match any
declaration in 'A'; did you
      mean 'typo'
int A::typo_() { return 3; }
       ^~~~~
       typo
tmp.cpp:1:16: note: 'typo' declared here
struct A { int typo() const; };
               ^

However the fixit, if applied, will get the function closer but won't fix
the code entirely, and the "fixed" code then yields:

tmp.cpp:2:8: error: out-of-line definition of 'typo' does not match any
declaration in 'A'
int A::typo() { return 3; }
       ^~~~
tmp.cpp:1:16: note: member declaration nearly matches
struct A { int typo() const; };
               ^

This is actually a limitation I'm currently aware of, where
DiagnoseInvalidRedeclaration will correct typos but cannot correct missing
function qualifiers like "const", and that when both are present the fixit
doesn't completely fix the code. I feel that, while imperfect, having the
fixit with this limitation is more beneficial than doing the typo correction
but not providing any fixit--so that invalid redeclarations that only suffer
from a mistyped name can be fixed. If the name required typo correction
*and* there was some other mismatch then there might be something wonkier
than a simple typo. If the consensus is that the fixit should only be given
when it completely fixes any issue with the redeclaration I can try to
figure out and add the hoops necessary to only suggest the fixit if there is
a function declaration that exactly matches the typo-corrected
redeclaration.

Cheers,
Kaelyn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110818/1d656a5f/attachment.html>


More information about the cfe-commits mailing list