Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -x c++ %s |
| 2 | // RUN: %clang_cc1 -fdiagnostics-parseable-fixits -x c++ %s 2>&1 | FileCheck %s |
| 3 | |
| 4 | struct S { |
| 5 | int n; |
| 6 | }; |
| 7 | |
| 8 | struct T { |
| 9 | T(); |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 10 | T(S, S); |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 11 | int n; |
| 12 | }; |
| 13 | |
| 14 | struct U { |
| 15 | ~U(); |
| 16 | int n; |
| 17 | }; |
| 18 | |
| 19 | struct V { |
| 20 | ~V(); |
| 21 | }; |
| 22 | |
| 23 | struct W : V { |
| 24 | }; |
| 25 | |
| 26 | struct X : U { |
| 27 | }; |
| 28 | |
| 29 | int F1(); |
| 30 | S F2(); |
| 31 | |
| 32 | namespace N { |
| 33 | void test() { |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 34 | // CHECK: fix-it:"{{.*}}":{35:9-35:11}:" = {}" |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 35 | S s1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} |
| 36 | |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 37 | // CHECK: fix-it:"{{.*}}":{39:9-39:10}:";" |
| 38 | // CHECK: fix-it:"{{.*}}":{40:7-40:9}:" = {}" |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 39 | S s2, // expected-note {{change this ',' to a ';' to call 'F2'}} |
| 40 | F2(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} |
| 41 | |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 42 | // CHECK: fix-it:"{{.*}}":{44:9-44:11}:"" |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 43 | // CHECK: fix-it:"{{.*}}":{45:9-45:11}:"" |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 44 | T t1(), // expected-warning {{function declaration}} expected-note {{remove parentheses}} |
| 45 | t2(); // expected-warning {{function declaration}} expected-note {{remove parentheses}} |
| 46 | |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 47 | // Suggest parentheses only around the first argument. |
| 48 | // CHECK: fix-it:"{{.*}}":{50:10-50:10}:"(" |
| 49 | // CHECK: fix-it:"{{.*}}":{50:13-50:13}:")" |
| 50 | T t3(S(), S()); // expected-warning {{disambiguated as a function declaration}} expected-note {{add a pair of parentheses}} |
| 51 | |
| 52 | // Check fixit position for pathological case |
| 53 | // CHECK: fix-it:"{{.*}}":{56:11-56:11}:"(" |
| 54 | // CHECK: fix-it:"{{.*}}":{56:20-56:20}:")" |
| 55 | float k[1]; |
| 56 | int l(int(k[0])); // expected-warning {{disambiguated as a function declaration}} expected-note {{add a pair of parentheses}} |
| 57 | |
| 58 | // Don't emit warning and fixit because this must be a function declaration due to void return type. |
| 59 | typedef void VO; |
| 60 | VO m(int (*p)[4]); |
| 61 | |
| 62 | // Don't emit warning and fixit because direct initializer is not permitted here. |
| 63 | if (int n(int())){} // expected-error {{function type is not allowed here}} expected-error {{condition must have an initializer}} |
| 64 | |
| 65 | // CHECK: fix-it:"{{.*}}":{66:8-66:10}:" = {}" |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 66 | U u(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} |
| 67 | |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 68 | // CHECK: fix-it:"{{.*}}":{69:8-69:10}:"" |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 69 | V v(); // expected-warning {{function declaration}} expected-note {{remove parentheses}} |
| 70 | |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 71 | // CHECK: fix-it:"{{.*}}":{72:8-72:10}:"" |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 72 | W w(); // expected-warning {{function declaration}} expected-note {{remove parentheses}} |
| 73 | |
| 74 | // TODO: Removing the parens here would not initialize U::n. |
| 75 | // Maybe suggest an " = X()" initializer for this case? |
| 76 | // Maybe suggest removing the parens anyway? |
| 77 | X x(); // expected-warning {{function declaration}} |
| 78 | |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 79 | // CHECK: fix-it:"{{.*}}":{80:11-80:13}:" = 0" |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 80 | int n1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} |
| 81 | |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 82 | // CHECK: fix-it:"{{.*}}":{84:11-84:12}:";" |
| 83 | // CHECK: fix-it:"{{.*}}":{85:7-85:9}:" = 0" |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 84 | int n2, // expected-note {{change this ',' to a ';' to call 'F1'}} |
| 85 | F1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} |
| 86 | |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 87 | // CHECK: fix-it:"{{.*}}":{88:13-88:15}:" = 0.0" |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 88 | double d(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} |
| 89 | |
| 90 | typedef void *Ptr; |
| 91 | |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 92 | // CHECK: fix-it:"{{.*}}":{93:10-93:12}:" = 0" |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 93 | Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} |
| 94 | |
| 95 | #define NULL 0 |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 96 | // CHECK: fix-it:"{{.*}}":{97:10-97:12}:" = NULL" |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 97 | Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} |
David Blaikie | 07b49a8 | 2012-03-18 02:56:47 +0000 | [diff] [blame] | 98 | |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 99 | // CHECK: fix-it:"{{.*}}":{100:11-100:13}:" = false" |
David Blaikie | 07b49a8 | 2012-03-18 02:56:47 +0000 | [diff] [blame] | 100 | bool b(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} |
| 101 | |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 102 | // CHECK: fix-it:"{{.*}}":{103:11-103:13}:" = '\\0'" |
David Blaikie | 07b49a8 | 2012-03-18 02:56:47 +0000 | [diff] [blame] | 103 | char c(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} |
| 104 | |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 105 | // CHECK: fix-it:"{{.*}}":{106:15-106:17}:" = L'\\0'" |
David Blaikie | 07b49a8 | 2012-03-18 02:56:47 +0000 | [diff] [blame] | 106 | wchar_t wc(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 107 | } |
| 108 | } |