summaryrefslogtreecommitdiffstats
path: root/test/FixIt
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-01-12 23:53:29 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-01-12 23:53:29 +0000
commit7984de35644701c0d94336da7f2215d4c26d9f5b (patch)
tree6a925ab1c97321c244d1b77502996ef7607ab95e /test/FixIt
parent83be12c8638a5136b937e602b3a9e25f4bc8e50d (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148072 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/FixIt')
-rw-r--r--test/FixIt/fixit-vexing-parse.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/test/FixIt/fixit-vexing-parse.cpp b/test/FixIt/fixit-vexing-parse.cpp
new file mode 100644
index 0000000000..0f0505f983
--- /dev/null
+++ b/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}}
+ }
+}