[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

David Blaikie dblaikie at gmail.com
Thu Jan 12 16:27:22 PST 2012


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();
         ~ ^

Also, what I consider to be the more common case of really vexing parse is this:

struct foo { };
struct bar { bar(foo) {} };
foo f(bar()); // example 1
int main() {
  foo g(bar()); // example 2
}

Clang does something with this, but not much:

vexing.cpp:11:8: warning: parentheses were disambiguated as a function
declarator [-Wvexing-parse]
  foo g(bar());
       ^~~~~~~

(completely ignoring the global scope case) - this same diagnostic
fires on far more obvious code (like the one you've been improving)
but doesn't do much to explain this particularly esoteric case & how
to fix it ( "foo f((bar()));" ). It's somewhere on my todo list (which
is very slow going) - but thought I'd mention it in case it was
relevant to anyone else.

- David




More information about the cfe-commits mailing list