[cfe-commits] r148072 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td include/clang/Sema/DeclSpec.h include/clang/Sema/Sema.h lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp lib/Parse/Parser.cpp lib/Sema/AnalysisBasedWarnings.cpp l

Eli Friedman eli.friedman at gmail.com
Thu Jan 12 18:24:49 PST 2012


On Thu, Jan 12, 2012 at 4:27 PM, David Blaikie <dblaikie at gmail.com> wrote:
> On Thu, Jan 12, 2012 at 4:13 PM, Matt Beaumont-Gay <matthewbg at google.com> wrote:
>>
>> On Thu, Jan 12, 2012 at 15:53, Richard Smith <richard-llvm at metafoo.co.uk> wrote:
>> > Author: rsmith
>> > Date: Thu Jan 12 17:53:29 2012
>> > New Revision: 148072
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=148072&view=rev
>> > Log:
>> > Improve 0-argument -Wvexing-parse diagnostic by adding notes with fix-its:
>> >
>> >  - If the declarator is at the start of a line, and the previous line contained
>> >   another declarator and ended with a comma, then that comma was probably a
>> >   typo for a semicolon:
>> >
>> >   int n = 0, m = 1, l = 2, // k = 5;
>> >   myImportantFunctionCall(); // oops!
>> >
>> >  - If removing the parentheses would correctly initialize the object, then
>> >   produce a note suggesting that fix.
>> >
>> >  - Otherwise, if there is a simple initializer we can suggest which performs
>> >   value-initialization, then provide a note suggesting a correction to that
>> >   initializer.
>>
>> These are great, but we should probably also have a note which
>> suggests a way to just silence the warning, in the (however unlikely)
>> case that the user did in fact want to declare a function.
>
>
> On the subject of the vexing parse warning, I think there's been a
> regression in the original support from some of the fancy examples
> Chris Lattner demonstrated in an LLVM blog post quite a while back.
>
> http://blog.llvm.org/2010/04/amazing-feats-of-clang-error-recovery.html
>
> $ cat t.cc
> #include <vector>
> int foo() {
>  std::vector<std::vector<int> > X();
>  return X.size();
> }
> $ clang t.cc
> t.cc:5:11: error: base of member reference has function type
> 'std::vector<std::vector<int> > ()'; perhaps you meant to call this
> function with '()'?
>  return X.size();
>          ^
>          ()
>
>
> But today, the same code today produces:
>
> t.cc:3:35: warning: empty parentheses interpreted as a function
> declaration [-Wvexing-parse]
>  std::vector<std::vector<int> > X();
>                                  ^~
> t.cc:4:12: error: member reference base type
> 'std::vector<std::vector<int> > (*)()' is not a structure or union
>  return X.size();
>         ~ ^

r148089.

-Eli




More information about the cfe-commits mailing list