Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 3218c4b | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 2 | |
| 3 | // Test the use of elaborated-type-specifiers to inject the names of |
| 4 | // structs (or classes or unions) into an outer scope as described in |
| 5 | // C++ [basic.scope.pdecl]p5. |
| 6 | typedef struct S1 { |
| 7 | union { |
| 8 | struct S2 *x; |
| 9 | struct S3 *y; |
| 10 | }; |
| 11 | } S1; |
| 12 | |
| 13 | bool test_elab(S1 *s1, struct S2 *s2, struct S3 *s3) { |
| 14 | if (s1->x == s2) return true; |
| 15 | if (s1->y == s3) return true; |
| 16 | return false; |
| 17 | } |
| 18 | |
| 19 | namespace NS { |
| 20 | class X { |
| 21 | public: |
Kaelyn Uhrain | 8d3607b | 2012-06-06 20:54:51 +0000 | [diff] [blame] | 22 | void test_elab2(struct S4 *s4); // expected-note{{'NS::S4' declared here}} |
Douglas Gregor | 3218c4b | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 23 | }; |
| 24 | |
Douglas Gregor | a41a8c5 | 2010-04-22 00:20:18 +0000 | [diff] [blame] | 25 | void X::test_elab2(S4 *s4) { } // expected-note{{passing argument to parameter 's4' here}} |
Douglas Gregor | 3218c4b | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | void test_X_elab(NS::X x) { |
| 29 | struct S4 *s4 = 0; |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 30 | x.test_elab2(s4); // expected-error{{cannot initialize a parameter of type 'NS::S4 *' with an lvalue of type 'struct S4 *'}} |
Douglas Gregor | 3218c4b | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | namespace NS { |
| 34 | S4 *get_S4(); |
| 35 | } |
| 36 | |
| 37 | void test_S5_scope() { |
Kaelyn Uhrain | 8d3607b | 2012-06-06 20:54:51 +0000 | [diff] [blame] | 38 | S4 *s4; // expected-error{{unknown type name 'S4'; did you mean 'NS::S4'?}} |
Douglas Gregor | 3218c4b | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Douglas Gregor | 3218c4b | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 41 | int test_funcparam_scope(struct S5 * s5) { |
| 42 | struct S5 { int y; } *s5_2 = 0; |
Douglas Gregor | 0c6db94 | 2009-05-04 06:07:12 +0000 | [diff] [blame] | 43 | if (s5 == s5_2) return 1; // expected-error {{comparison of distinct pointer types ('struct S5 *' and 'struct S5 *')}} |
Douglas Gregor | 3218c4b | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 44 | return 0; |
| 45 | } |