Richard Smith | cb7709c | 2012-01-05 04:12:21 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -pedantic-errors %s |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 2 | |
| 3 | void f() { |
| 4 | int a; |
| 5 | struct S { int m; }; |
| 6 | typedef S *T; |
| 7 | |
| 8 | // Expressions. |
| 9 | T(a)->m = 7; |
John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 10 | int(a)++; // expected-error {{assignment to cast is illegal}} |
| 11 | __extension__ int(a)++; // expected-error {{assignment to cast is illegal}} |
Douglas Gregor | 19311e7 | 2010-09-08 21:40:08 +0000 | [diff] [blame] | 12 | __typeof(int)(a,5)<<a; // expected-error {{excess elements in scalar initializer}} |
John McCall | 0faede6 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 13 | void(a), ++a; |
Argyrios Kyrtzidis | a8a4598 | 2008-10-05 15:03:47 +0000 | [diff] [blame] | 14 | if (int(a)+1) {} |
Argyrios Kyrtzidis | 1b2ad2f | 2010-09-19 23:03:35 +0000 | [diff] [blame] | 15 | for (int(a)+1;;) {} // expected-warning {{expression result unused}} |
Argyrios Kyrtzidis | 78c8d80 | 2008-10-05 19:56:22 +0000 | [diff] [blame] | 16 | a = sizeof(int()+1); |
Argyrios Kyrtzidis | d3dbbb6 | 2008-10-05 21:10:08 +0000 | [diff] [blame] | 17 | a = sizeof(int(1)); |
Eli Friedman | 2962f4d | 2009-04-28 03:59:15 +0000 | [diff] [blame] | 18 | typeof(int()+1) a2; // expected-error {{extension used}} |
Argyrios Kyrtzidis | 1b2ad2f | 2010-09-19 23:03:35 +0000 | [diff] [blame] | 19 | (int(1)); // expected-warning {{expression result unused}} |
Argyrios Kyrtzidis | d3dbbb6 | 2008-10-05 21:10:08 +0000 | [diff] [blame] | 20 | |
| 21 | // type-id |
Sebastian Redl | 9cc11e7 | 2009-07-25 15:41:38 +0000 | [diff] [blame] | 22 | (int())1; // expected-error {{C-style cast from 'int' to 'int ()' is not allowed}} |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 23 | |
| 24 | // Declarations. |
Argyrios Kyrtzidis | 259b0d9 | 2008-10-15 23:21:32 +0000 | [diff] [blame] | 25 | int fd(T(a)); // expected-warning {{parentheses were disambiguated as a function declarator}} |
Douglas Gregor | 3eb1c54 | 2008-12-17 16:19:15 +0000 | [diff] [blame] | 26 | T(*d)(int(p)); // expected-warning {{parentheses were disambiguated as a function declarator}} expected-note {{previous definition is here}} |
Richard Smith | cb7709c | 2012-01-05 04:12:21 +0000 | [diff] [blame] | 27 | typedef T(*td)(int(p)); |
| 28 | extern T(*tp)(int(p)); |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 29 | T d3(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}} |
Richard Smith | 80a5b27 | 2012-01-09 18:30:34 +0000 | [diff] [blame] | 30 | T d3v(void); |
Richard Smith | 2f0e88a | 2012-01-06 02:30:50 +0000 | [diff] [blame] | 31 | typedef T d3t(); |
| 32 | extern T f3(); |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 33 | __typeof(*T()) f4(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}} |
Richard Smith | 80a5b27 | 2012-01-09 18:30:34 +0000 | [diff] [blame] | 34 | typedef void *V; |
| 35 | __typeof(*V()) f5(); |
| 36 | T multi1, |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 37 | multi2(); // expected-warning {{empty parentheses interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}} |
Douglas Gregor | 3eb1c54 | 2008-12-17 16:19:15 +0000 | [diff] [blame] | 38 | T(d)[5]; // expected-error {{redefinition of 'd'}} |
Eli Friedman | 2962f4d | 2009-04-28 03:59:15 +0000 | [diff] [blame] | 39 | typeof(int[])(f) = { 1, 2 }; // expected-error {{extension used}} |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 40 | void(b)(int); |
Richard Smith | cb7709c | 2012-01-05 04:12:21 +0000 | [diff] [blame] | 41 | int(d2) __attribute__(()); |
Argyrios Kyrtzidis | ca35baa | 2008-10-05 15:19:49 +0000 | [diff] [blame] | 42 | if (int(a)=1) {} |
Douglas Gregor | 3eb1c54 | 2008-12-17 16:19:15 +0000 | [diff] [blame] | 43 | int(d3(int())); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 44 | } |
Argyrios Kyrtzidis | d3dbbb6 | 2008-10-05 21:10:08 +0000 | [diff] [blame] | 45 | |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 46 | struct RAII { |
| 47 | RAII(); |
| 48 | ~RAII(); |
| 49 | }; |
| 50 | |
| 51 | void func(); |
| 52 | namespace N { |
Richard Smith | f037541 | 2012-01-13 02:14:39 +0000 | [diff] [blame] | 53 | struct S; |
| 54 | |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 55 | void emptyParens() { |
| 56 | RAII raii(); // expected-warning {{function declaration}} expected-note {{remove parentheses to declare a variable}} |
| 57 | int a, b, c, d, e, // expected-note {{change this ',' to a ';' to call 'func'}} |
| 58 | func(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} |
Richard Smith | f037541 | 2012-01-13 02:14:39 +0000 | [diff] [blame] | 59 | |
| 60 | S s(); // expected-warning {{function declaration}} |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
Argyrios Kyrtzidis | d3dbbb6 | 2008-10-05 21:10:08 +0000 | [diff] [blame] | 64 | class C { }; |
Douglas Gregor | fa04764 | 2009-02-04 00:32:51 +0000 | [diff] [blame] | 65 | void fn(int(C)) { } // void fn(int(*fp)(C c)) { } expected-note{{candidate function}} |
Argyrios Kyrtzidis | d3dbbb6 | 2008-10-05 21:10:08 +0000 | [diff] [blame] | 66 | // not: void fn(int C); |
| 67 | int g(C); |
| 68 | |
| 69 | void foo() { |
Douglas Gregor | fa04764 | 2009-02-04 00:32:51 +0000 | [diff] [blame] | 70 | fn(1); // expected-error {{no matching function}} |
Argyrios Kyrtzidis | d3dbbb6 | 2008-10-05 21:10:08 +0000 | [diff] [blame] | 71 | fn(g); // OK |
| 72 | } |