David Blaikie | 9b29f4f | 2012-10-16 18:53:14 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -Wno-int-to-pointer-cast -fsyntax-only -verify -pedantic-errors %s |
Argyrios Kyrtzidis | 99e9fe0 | 2013-05-07 19:54:28 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -Wno-int-to-pointer-cast -fsyntax-only -verify -pedantic-errors -x objective-c++ %s |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 3 | |
| 4 | void f() { |
| 5 | int a; |
| 6 | struct S { int m; }; |
| 7 | typedef S *T; |
| 8 | |
| 9 | // Expressions. |
| 10 | T(a)->m = 7; |
John McCall | f6a1648 | 2010-12-04 03:47:34 +0000 | [diff] [blame] | 11 | int(a)++; // expected-error {{assignment to cast is illegal}} |
| 12 | __extension__ int(a)++; // expected-error {{assignment to cast is illegal}} |
Douglas Gregor | 19311e7 | 2010-09-08 21:40:08 +0000 | [diff] [blame] | 13 | __typeof(int)(a,5)<<a; // expected-error {{excess elements in scalar initializer}} |
John McCall | 0faede6 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 14 | void(a), ++a; |
Argyrios Kyrtzidis | a8a4598 | 2008-10-05 15:03:47 +0000 | [diff] [blame] | 15 | if (int(a)+1) {} |
Argyrios Kyrtzidis | 1b2ad2f | 2010-09-19 23:03:35 +0000 | [diff] [blame] | 16 | for (int(a)+1;;) {} // expected-warning {{expression result unused}} |
Argyrios Kyrtzidis | 78c8d80 | 2008-10-05 19:56:22 +0000 | [diff] [blame] | 17 | a = sizeof(int()+1); |
Argyrios Kyrtzidis | d3dbbb6 | 2008-10-05 21:10:08 +0000 | [diff] [blame] | 18 | a = sizeof(int(1)); |
Eli Friedman | 2962f4d | 2009-04-28 03:59:15 +0000 | [diff] [blame] | 19 | typeof(int()+1) a2; // expected-error {{extension used}} |
Argyrios Kyrtzidis | 1b2ad2f | 2010-09-19 23:03:35 +0000 | [diff] [blame] | 20 | (int(1)); // expected-warning {{expression result unused}} |
Argyrios Kyrtzidis | d3dbbb6 | 2008-10-05 21:10:08 +0000 | [diff] [blame] | 21 | |
| 22 | // type-id |
Sebastian Redl | 9cc11e7 | 2009-07-25 15:41:38 +0000 | [diff] [blame] | 23 | (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] | 24 | |
| 25 | // Declarations. |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 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)); |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 30 | 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] | 31 | T d3v(void); |
Richard Smith | 2f0e88a | 2012-01-06 02:30:50 +0000 | [diff] [blame] | 32 | typedef T d3t(); |
| 33 | extern T f3(); |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 34 | __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] | 35 | typedef void *V; |
| 36 | __typeof(*V()) f5(); |
| 37 | T multi1, |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 38 | 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] | 39 | T(d)[5]; // expected-error {{redefinition of 'd'}} |
Eli Friedman | 2962f4d | 2009-04-28 03:59:15 +0000 | [diff] [blame] | 40 | typeof(int[])(f) = { 1, 2 }; // expected-error {{extension used}} |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 41 | void(b)(int); |
Richard Smith | cb7709c | 2012-01-05 04:12:21 +0000 | [diff] [blame] | 42 | int(d2) __attribute__(()); |
Argyrios Kyrtzidis | ca35baa | 2008-10-05 15:19:49 +0000 | [diff] [blame] | 43 | if (int(a)=1) {} |
Douglas Gregor | 3eb1c54 | 2008-12-17 16:19:15 +0000 | [diff] [blame] | 44 | int(d3(int())); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 45 | } |
Argyrios Kyrtzidis | d3dbbb6 | 2008-10-05 21:10:08 +0000 | [diff] [blame] | 46 | |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 47 | struct RAII { |
| 48 | RAII(); |
| 49 | ~RAII(); |
| 50 | }; |
| 51 | |
| 52 | void func(); |
Richard Smith | d64effc | 2012-07-30 21:42:05 +0000 | [diff] [blame] | 53 | void func2(short); |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 54 | namespace N { |
Richard Smith | f037541 | 2012-01-13 02:14:39 +0000 | [diff] [blame] | 55 | struct S; |
| 56 | |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 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}} |
Richard Smith | f037541 | 2012-01-13 02:14:39 +0000 | [diff] [blame] | 61 | |
| 62 | S s(); // expected-warning {{function declaration}} |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 63 | } |
Richard Smith | d64effc | 2012-07-30 21:42:05 +0000 | [diff] [blame] | 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 | } |
Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Argyrios Kyrtzidis | d3dbbb6 | 2008-10-05 21:10:08 +0000 | [diff] [blame] | 70 | class C { }; |
Douglas Gregor | fa04764 | 2009-02-04 00:32:51 +0000 | [diff] [blame] | 71 | 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] | 72 | // not: void fn(int C); |
| 73 | int g(C); |
| 74 | |
| 75 | void foo() { |
Douglas Gregor | fa04764 | 2009-02-04 00:32:51 +0000 | [diff] [blame] | 76 | fn(1); // expected-error {{no matching function}} |
Argyrios Kyrtzidis | d3dbbb6 | 2008-10-05 21:10:08 +0000 | [diff] [blame] | 77 | fn(g); // OK |
| 78 | } |
Kaelyn Uhrain | 12f3297 | 2012-05-02 00:11:40 +0000 | [diff] [blame] | 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 | } |