1// RUN: %clang_cc1 -verify -x c++ %s
2// RUN: not %clang_cc1 -fdiagnostics-parseable-fixits -x c++ %s 2>&1 | FileCheck %s
3
4struct S {
5  int n;
6};
7
8struct T {
9  T();
10  T(S, S);
11  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() {
34    // CHECK: fix-it:"{{.*}}":{35:9-35:11}:" = {}"
35    S s1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
36
37    // CHECK: fix-it:"{{.*}}":{39:9-39:10}:";"
38    // CHECK: fix-it:"{{.*}}":{40:7-40:9}:" = {}"
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
42    // CHECK: fix-it:"{{.*}}":{44:9-44:11}:""
43    // CHECK: fix-it:"{{.*}}":{45:9-45:11}:""
44    T t1(), // expected-warning {{function declaration}} expected-note {{remove parentheses}}
45      t2(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
46
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}:" = {}"
66    U u(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
67
68    // CHECK: fix-it:"{{.*}}":{69:8-69:10}:""
69    V v(); // expected-warning {{function declaration}} expected-note {{remove parentheses}}
70
71    // CHECK: fix-it:"{{.*}}":{72:8-72:10}:""
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
79    // CHECK: fix-it:"{{.*}}":{80:11-80:13}:" = 0"
80    int n1(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
81
82    // CHECK: fix-it:"{{.*}}":{84:11-84:12}:";"
83    // CHECK: fix-it:"{{.*}}":{85:7-85:9}:" = 0"
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
87    // CHECK: fix-it:"{{.*}}":{88:13-88:15}:" = 0.0"
88    double d(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
89
90    typedef void *Ptr;
91
92    // CHECK: fix-it:"{{.*}}":{93:10-93:12}:" = 0"
93    Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
94
95#define NULL 0
96    // CHECK: fix-it:"{{.*}}":{97:10-97:12}:" = NULL"
97    Ptr p(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
98
99    // CHECK: fix-it:"{{.*}}":{100:11-100:13}:" = false"
100    bool b(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
101
102    // CHECK: fix-it:"{{.*}}":{103:11-103:13}:" = '\\0'"
103    char c(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
104
105    // CHECK: fix-it:"{{.*}}":{106:15-106:17}:" = L'\\0'"
106    wchar_t wc(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
107  }
108}
109