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