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