diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-01-12 23:53:29 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-01-12 23:53:29 +0000 |
commit | 8d06f424480e7cd6facd1cea474dfdee5bbcc60d (patch) | |
tree | 10b2db660a69a31d4492402fd90748c986e15ba5 /clang/test | |
parent | 7840c81df2a766c7174106ae6a6927c9ec26e5e2 (diff) | |
download | bcm5719-llvm-8d06f424480e7cd6facd1cea474dfdee5bbcc60d.tar.gz bcm5719-llvm-8d06f424480e7cd6facd1cea474dfdee5bbcc60d.zip |
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.
Sema::Declarator now tracks the location of the comma prior to the declarator in
the declaration, if there is one, to facilitate providing the note. The code to
determine an appropriate initializer from the -Wuninitialized warning has been
factored out to allow use in both that and -Wvexing-parse.
llvm-svn: 148072
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CXX/basic/basic.link/p9.cpp | 2 | ||||
-rw-r--r-- | clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p11.cpp | 16 | ||||
-rw-r--r-- | clang/test/FixIt/fixit-vexing-parse.cpp | 80 | ||||
-rw-r--r-- | clang/test/SemaCXX/condition.cpp | 2 | ||||
-rw-r--r-- | clang/test/SemaCXX/conditional-expr.cpp | 4 | ||||
-rw-r--r-- | clang/test/SemaCXX/decl-expr-ambiguity.cpp | 20 |
6 files changed, 109 insertions, 15 deletions
diff --git a/clang/test/CXX/basic/basic.link/p9.cpp b/clang/test/CXX/basic/basic.link/p9.cpp index c895253c68f..680c93db2e2 100644 --- a/clang/test/CXX/basic/basic.link/p9.cpp +++ b/clang/test/CXX/basic/basic.link/p9.cpp @@ -6,5 +6,5 @@ namespace N { } // expected-note{{here}} // First bullet: two names with external linkage that refer to // different kinds of entities. void f() { - int N(); // expected-error{{redefinition}} expected-warning{{interpreted as a function declaration}} + int N(); // expected-error{{redefinition}} expected-warning{{interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}} } diff --git a/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p11.cpp b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p11.cpp index b1dcf4d0154..99903b57bf8 100644 --- a/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p11.cpp +++ b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p11.cpp @@ -12,26 +12,26 @@ namespace test0 { namespace ns { void foo(); } // expected-note {{target of using declaration}} - int foo(); // expected-note {{conflicting declaration}} + int foo(void); // expected-note {{conflicting declaration}} using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} } namespace test1 { namespace ns { void foo(); } // expected-note {{target of using declaration}} using ns::foo; //expected-note {{using declaration}} - int foo(); // expected-error {{declaration conflicts with target of using declaration already in scope}} + int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} } namespace test2 { namespace ns { void foo(); } // expected-note 2 {{target of using declaration}} void test0() { - int foo(); // expected-note {{conflicting declaration}} expected-warning{{function declaration}} + int foo(void); // expected-note {{conflicting declaration}} using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} } void test1() { using ns::foo; //expected-note {{using declaration}} - int foo(); // expected-error {{declaration conflicts with target of using declaration already in scope}} expected-warning{{function declaration}} + int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} } } @@ -39,7 +39,7 @@ namespace test3 { namespace ns { void foo(); } // expected-note 2 {{target of using declaration}} class Test0 { void test() { - int foo(); // expected-note {{conflicting declaration}} expected-warning{{function declaration}} + int foo(void); // expected-note {{conflicting declaration}} using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} } }; @@ -47,7 +47,7 @@ namespace test3 { class Test1 { void test() { using ns::foo; //expected-note {{using declaration}} - int foo(); // expected-error {{declaration conflicts with target of using declaration already in scope}} expected-warning{{function declaration}} + int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} } }; } @@ -56,7 +56,7 @@ namespace test4 { namespace ns { void foo(); } // expected-note 2 {{target of using declaration}} template <typename> class Test0 { void test() { - int foo(); // expected-note {{conflicting declaration}} expected-warning{{function declaration}} + int foo(void); // expected-note {{conflicting declaration}} using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} } }; @@ -64,7 +64,7 @@ namespace test4 { template <typename> class Test1 { void test() { using ns::foo; //expected-note {{using declaration}} - int foo(); // expected-error {{declaration conflicts with target of using declaration already in scope}} expected-warning{{function declaration}} + int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} } }; } diff --git a/clang/test/FixIt/fixit-vexing-parse.cpp b/clang/test/FixIt/fixit-vexing-parse.cpp new file mode 100644 index 00000000000..0f0505f983c --- /dev/null +++ b/clang/test/FixIt/fixit-vexing-parse.cpp @@ -0,0 +1,80 @@ +// RUN: %clang_cc1 -verify -x c++ %s +// RUN: %clang_cc1 -fdiagnostics-parseable-fixits -x c++ %s 2>&1 | FileCheck %s + +struct S { + int n; +}; + +struct T { + T(); + int n; +}; + +struct U { + ~U(); + int n; +}; + +struct V { + ~V(); +}; + +struct W : V { +}; + +struct X : U { +}; + +int F1(); +S F2(); + +namespace N { + void test() { + // CHECK: fix-it:"{{.*}}":{34:9-34:11}:" = {}" + S s1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} + + // CHECK: fix-it:"{{.*}}":{38:9-38:10}:";" + // CHECK: fix-it:"{{.*}}":{39:7-39:9}:" = {}" + S s2, // expected-note {{change this ',' to a ';' to call 'F2'}} + F2(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} + + // CHECK: fix-it:"{{.*}}":{43:9-43:11}:"" + // CHECK: fix-it:"{{.*}}":{44:9-44:11}:"" + T t1(), // expected-warning {{function declaration}} expected-note {{remove parentheses}} + t2(); // expected-warning {{function declaration}} expected-note {{remove parentheses}} + + // CHECK: fix-it:"{{.*}}":{47:8-47:10}:" = {}" + U u(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} + + // CHECK: fix-it:"{{.*}}":{50:8-50:10}:"" + V v(); // expected-warning {{function declaration}} expected-note {{remove parentheses}} + + // CHECK: fix-it:"{{.*}}":{53:8-53:10}:"" + W w(); // expected-warning {{function declaration}} expected-note {{remove parentheses}} + + // TODO: Removing the parens here would not initialize U::n. + // Maybe suggest an " = X()" initializer for this case? + // Maybe suggest removing the parens anyway? + X x(); // expected-warning {{function declaration}} + + // CHECK: fix-it:"{{.*}}":{61:11-61:13}:" = 0" + int n1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} + + // CHECK: fix-it:"{{.*}}":{65:11-65:12}:";" + // CHECK: fix-it:"{{.*}}":{66:7-66:9}:" = 0" + int n2, // expected-note {{change this ',' to a ';' to call 'F1'}} + F1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} + + // CHECK: fix-it:"{{.*}}":{69:13-69:15}:" = 0.0" + double d(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} + + typedef void *Ptr; + + // CHECK: fix-it:"{{.*}}":{74:10-74:12}:" = 0" + Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} + +#define NULL 0 + // CHECK: fix-it:"{{.*}}":{78:10-78:12}:" = NULL" + Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} + } +} diff --git a/clang/test/SemaCXX/condition.cpp b/clang/test/SemaCXX/condition.cpp index 3d17dc39377..43ee640e0f6 100644 --- a/clang/test/SemaCXX/condition.cpp +++ b/clang/test/SemaCXX/condition.cpp @@ -7,7 +7,7 @@ void test() { typedef int arr[10]; while (arr x=0) ; // expected-error {{an array type is not allowed here}} expected-error {{array initializer must be an initializer list}} - while (int f()=0) ; // expected-warning {{interpreted as a function declaration}} expected-error {{a function type is not allowed here}} + while (int f()=0) ; // expected-warning {{interpreted as a function declaration}} expected-note {{initializer}} expected-error {{a function type is not allowed here}} struct S {} s; if (s) ++x; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} diff --git a/clang/test/SemaCXX/conditional-expr.cpp b/clang/test/SemaCXX/conditional-expr.cpp index 3cfddb3a416..4aee913277e 100644 --- a/clang/test/SemaCXX/conditional-expr.cpp +++ b/clang/test/SemaCXX/conditional-expr.cpp @@ -96,8 +96,8 @@ void test() (void)(i1 ? BadDerived() : BadBase()); // b2.1 (hierarchy stuff) - const Base constret(); // expected-warning {{interpreted as a function declaration}} - const Derived constder(); // expected-warning {{interpreted as a function declaration}} + extern const Base constret(); + extern const Derived constder(); // should use const overload A a1((i1 ? constret() : Base()).trick()); A a2((i1 ? Base() : constret()).trick()); diff --git a/clang/test/SemaCXX/decl-expr-ambiguity.cpp b/clang/test/SemaCXX/decl-expr-ambiguity.cpp index 3a946c0ffb9..f6dbe2f3398 100644 --- a/clang/test/SemaCXX/decl-expr-ambiguity.cpp +++ b/clang/test/SemaCXX/decl-expr-ambiguity.cpp @@ -26,15 +26,15 @@ void f() { T(*d)(int(p)); // expected-warning {{parentheses were disambiguated as a function declarator}} expected-note {{previous definition is here}} typedef T(*td)(int(p)); extern T(*tp)(int(p)); - T d3(); // expected-warning {{empty parentheses interpreted as a function declaration}} + T d3(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}} T d3v(void); typedef T d3t(); extern T f3(); - __typeof(*T()) f4(); // expected-warning {{empty parentheses interpreted as a function declaration}} + __typeof(*T()) f4(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}} typedef void *V; __typeof(*V()) f5(); T multi1, - multi2(); // expected-warning {{empty parentheses interpreted as a function declaration}} + multi2(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}} T(d)[5]; // expected-error {{redefinition of 'd'}} typeof(int[])(f) = { 1, 2 }; // expected-error {{extension used}} void(b)(int); @@ -43,6 +43,20 @@ void f() { int(d3(int())); } +struct RAII { + RAII(); + ~RAII(); +}; + +void func(); +namespace N { + void emptyParens() { + RAII raii(); // expected-warning {{function declaration}} expected-note {{remove parentheses to declare a variable}} + int a, b, c, d, e, // expected-note {{change this ',' to a ';' to call 'func'}} + func(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} + } +} + class C { }; void fn(int(C)) { } // void fn(int(*fp)(C c)) { } expected-note{{candidate function}} // not: void fn(int C); |