blob: dd0f87304a5379083bb44198a9f922705c6289c4 [file] [log] [blame]
Richard Smith7984de32012-01-12 23:53:29 +00001// RUN: %clang_cc1 -verify -x c++ %s
2// RUN: %clang_cc1 -fdiagnostics-parseable-fixits -x c++ %s 2>&1 | FileCheck %s
3
4struct S {
5 int n;
6};
7
8struct T {
9 T();
Richard Smithb9c62612012-07-30 21:30:52 +000010 T(S, S);
Richard Smith7984de32012-01-12 23:53:29 +000011 int n;
12};
13
14struct U {
15 ~U();
16 int n;
17};
18
19struct V {
20 ~V();
21};
22
23struct W : V {
24};
25
26struct X : U {
27};
28
29int F1();
30S F2();
31
32namespace N {
33 void test() {
Richard Smithb9c62612012-07-30 21:30:52 +000034 // CHECK: fix-it:"{{.*}}":{35:9-35:11}:" = {}"
Richard Smith7984de32012-01-12 23:53:29 +000035 S s1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
36
Richard Smithb9c62612012-07-30 21:30:52 +000037 // CHECK: fix-it:"{{.*}}":{39:9-39:10}:";"
38 // CHECK: fix-it:"{{.*}}":{40:7-40:9}:" = {}"
Richard Smith7984de32012-01-12 23:53:29 +000039 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 Smith7984de32012-01-12 23:53:29 +000042 // CHECK: fix-it:"{{.*}}":{44:9-44:11}:""
Richard Smithb9c62612012-07-30 21:30:52 +000043 // CHECK: fix-it:"{{.*}}":{45:9-45:11}:""
Richard Smith7984de32012-01-12 23:53:29 +000044 T t1(), // expected-warning {{function declaration}} expected-note {{remove parentheses}}
45 t2(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
46
Richard Smithb9c62612012-07-30 21:30:52 +000047 // 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 Smith7984de32012-01-12 23:53:29 +000066 U u(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
67
Richard Smithb9c62612012-07-30 21:30:52 +000068 // CHECK: fix-it:"{{.*}}":{69:8-69:10}:""
Richard Smith7984de32012-01-12 23:53:29 +000069 V v(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
70
Richard Smithb9c62612012-07-30 21:30:52 +000071 // CHECK: fix-it:"{{.*}}":{72:8-72:10}:""
Richard Smith7984de32012-01-12 23:53:29 +000072 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 Smithb9c62612012-07-30 21:30:52 +000079 // CHECK: fix-it:"{{.*}}":{80:11-80:13}:" = 0"
Richard Smith7984de32012-01-12 23:53:29 +000080 int n1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
81
Richard Smithb9c62612012-07-30 21:30:52 +000082 // CHECK: fix-it:"{{.*}}":{84:11-84:12}:";"
83 // CHECK: fix-it:"{{.*}}":{85:7-85:9}:" = 0"
Richard Smith7984de32012-01-12 23:53:29 +000084 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 Smithb9c62612012-07-30 21:30:52 +000087 // CHECK: fix-it:"{{.*}}":{88:13-88:15}:" = 0.0"
Richard Smith7984de32012-01-12 23:53:29 +000088 double d(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
89
90 typedef void *Ptr;
91
Richard Smithb9c62612012-07-30 21:30:52 +000092 // CHECK: fix-it:"{{.*}}":{93:10-93:12}:" = 0"
Richard Smith7984de32012-01-12 23:53:29 +000093 Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
94
95#define NULL 0
Richard Smithb9c62612012-07-30 21:30:52 +000096 // CHECK: fix-it:"{{.*}}":{97:10-97:12}:" = NULL"
Richard Smith7984de32012-01-12 23:53:29 +000097 Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
David Blaikie07b49a82012-03-18 02:56:47 +000098
Richard Smithb9c62612012-07-30 21:30:52 +000099 // CHECK: fix-it:"{{.*}}":{100:11-100:13}:" = false"
David Blaikie07b49a82012-03-18 02:56:47 +0000100 bool b(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
101
Richard Smithb9c62612012-07-30 21:30:52 +0000102 // CHECK: fix-it:"{{.*}}":{103:11-103:13}:" = '\\0'"
David Blaikie07b49a82012-03-18 02:56:47 +0000103 char c(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
104
Richard Smithb9c62612012-07-30 21:30:52 +0000105 // CHECK: fix-it:"{{.*}}":{106:15-106:17}:" = L'\\0'"
David Blaikie07b49a82012-03-18 02:56:47 +0000106 wchar_t wc(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
Richard Smith7984de32012-01-12 23:53:29 +0000107 }
108}