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