1*67e74705SXin Li // RUN: %clang_cc1 -Wno-int-to-pointer-cast -fsyntax-only -verify -pedantic-errors %s
2*67e74705SXin Li // RUN: %clang_cc1 -Wno-int-to-pointer-cast -fsyntax-only -verify -pedantic-errors -std=gnu++98 %s
3*67e74705SXin Li // RUN: %clang_cc1 -Wno-int-to-pointer-cast -fsyntax-only -verify -pedantic-errors -std=gnu++11 %s
4*67e74705SXin Li // RUN: %clang_cc1 -Wno-int-to-pointer-cast -fsyntax-only -verify -pedantic-errors -x objective-c++ %s
5*67e74705SXin Li
f()6*67e74705SXin Li void f() {
7*67e74705SXin Li int a;
8*67e74705SXin Li struct S { int m; };
9*67e74705SXin Li typedef S *T;
10*67e74705SXin Li
11*67e74705SXin Li // Expressions.
12*67e74705SXin Li T(a)->m = 7;
13*67e74705SXin Li int(a)++; // expected-error {{assignment to cast is illegal}}
14*67e74705SXin Li __extension__ int(a)++; // expected-error {{assignment to cast is illegal}}
15*67e74705SXin Li __typeof(int)(a,5)<<a; // expected-error {{excess elements in scalar initializer}}
16*67e74705SXin Li void(a), ++a;
17*67e74705SXin Li if (int(a)+1) {}
18*67e74705SXin Li for (int(a)+1;;) {} // expected-warning {{expression result unused}}
19*67e74705SXin Li a = sizeof(int()+1);
20*67e74705SXin Li a = sizeof(int(1));
21*67e74705SXin Li typeof(int()+1) a2; // expected-error {{extension used}}
22*67e74705SXin Li (int(1)); // expected-warning {{expression result unused}}
23*67e74705SXin Li
24*67e74705SXin Li // type-id
25*67e74705SXin Li (int())1; // expected-error {{C-style cast from 'int' to 'int ()' is not allowed}}
26*67e74705SXin Li
27*67e74705SXin Li // Declarations.
28*67e74705SXin Li int fd(T(a)); // expected-warning {{disambiguated as a function declaration}} expected-note{{add a pair of parentheses}}
29*67e74705SXin Li T(*d)(int(p)); // expected-note {{previous}}
30*67e74705SXin Li typedef T td(int(p));
31*67e74705SXin Li extern T tp(int(p));
32*67e74705SXin Li T d3(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}}
33*67e74705SXin Li T d3v(void);
34*67e74705SXin Li typedef T d3t();
35*67e74705SXin Li extern T f3();
36*67e74705SXin Li __typeof(*T()) f4(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}}
37*67e74705SXin Li typedef void *V;
38*67e74705SXin Li __typeof(*V()) f5(); // expected-error {{ISO C++ does not allow indirection on operand of type 'V' (aka 'void *')}}
39*67e74705SXin Li T multi1,
40*67e74705SXin Li multi2(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}}
41*67e74705SXin Li T(d)[5]; // expected-error {{redefinition of 'd'}}
42*67e74705SXin Li typeof(int[])(f) = { 1, 2 }; // expected-error {{extension used}}
43*67e74705SXin Li void(b)(int);
44*67e74705SXin Li int(d2) __attribute__(());
45*67e74705SXin Li if (int(a)=1) {}
46*67e74705SXin Li int(d3(int()));
47*67e74705SXin Li }
48*67e74705SXin Li
49*67e74705SXin Li struct RAII {
50*67e74705SXin Li RAII();
51*67e74705SXin Li ~RAII();
52*67e74705SXin Li };
53*67e74705SXin Li
54*67e74705SXin Li void func();
55*67e74705SXin Li void func2(short);
56*67e74705SXin Li namespace N {
57*67e74705SXin Li struct S;
58*67e74705SXin Li
emptyParens()59*67e74705SXin Li void emptyParens() {
60*67e74705SXin Li RAII raii(); // expected-warning {{function declaration}} expected-note {{remove parentheses to declare a variable}}
61*67e74705SXin Li int a, b, c, d, e, // expected-note {{change this ',' to a ';' to call 'func'}}
62*67e74705SXin Li func(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}}
63*67e74705SXin Li
64*67e74705SXin Li S s(); // expected-warning {{function declaration}}
65*67e74705SXin Li #if __cplusplus >= 201103L
66*67e74705SXin Li // expected-note@-2 {{replace parentheses with an initializer to declare a variable}}
67*67e74705SXin Li #endif
68*67e74705SXin Li }
nonEmptyParens()69*67e74705SXin Li void nonEmptyParens() {
70*67e74705SXin Li int f = 0, // g = 0; expected-note {{change this ',' to a ';' to call 'func2'}}
71*67e74705SXin Li func2(short(f)); // expected-warning {{function declaration}} expected-note {{add a pair of parentheses}}
72*67e74705SXin Li }
73*67e74705SXin Li }
74*67e74705SXin Li
75*67e74705SXin Li class C { };
fn(int (C))76*67e74705SXin Li void fn(int(C)) { } // void fn(int(*fp)(C c)) { } expected-note{{candidate function}}
77*67e74705SXin Li // not: void fn(int C);
78*67e74705SXin Li int g(C);
79*67e74705SXin Li
foo()80*67e74705SXin Li void foo() {
81*67e74705SXin Li fn(1); // expected-error {{no matching function}}
82*67e74705SXin Li fn(g); // OK
83*67e74705SXin Li }
84*67e74705SXin Li
85*67e74705SXin Li namespace PR11874 {
86*67e74705SXin Li void foo(); // expected-note 3 {{class 'foo' is hidden by a non-type declaration of 'foo' here}}
87*67e74705SXin Li class foo {};
88*67e74705SXin Li class bar {
bar()89*67e74705SXin Li bar() {
90*67e74705SXin Li const foo* f1 = 0; // expected-error {{must use 'class' tag to refer to type 'foo' in this scope}}
91*67e74705SXin Li foo* f2 = 0; // expected-error {{must use 'class' tag to refer to type 'foo' in this scope}}
92*67e74705SXin Li foo f3; // expected-error {{must use 'class' tag to refer to type 'foo' in this scope}}
93*67e74705SXin Li }
94*67e74705SXin Li };
95*67e74705SXin Li
96*67e74705SXin Li int baz; // expected-note 2 {{class 'baz' is hidden by a non-type declaration of 'baz' here}}
97*67e74705SXin Li class baz {};
fizbin()98*67e74705SXin Li void fizbin() {
99*67e74705SXin Li const baz* b1 = 0; // expected-error {{must use 'class' tag to refer to type 'baz' in this scope}}
100*67e74705SXin Li baz* b2; // expected-error {{use of undeclared identifier 'b2'}}
101*67e74705SXin Li baz b3; // expected-error {{must use 'class' tag to refer to type 'baz' in this scope}}
102*67e74705SXin Li }
103*67e74705SXin Li }
104