| 1 |
// RUN: %clang_cc1 -verify -std=c2x %s |
| 2 |
|
| 3 |
// Demonstrate that we don't support the expression form without parentheses in |
| 4 |
// C2x mode. |
| 5 |
typeof 0 int i = 12; // expected-error {{expected '(' after 'typeof'}} expected-error {{expected identifier or '('}} |
| 6 |
typeof 0 j = 12; // expected-error {{expected '(' after 'typeof'}} expected-error {{expected identifier or '('}} |
| 7 |
typeof_unqual 0 k = 12; // expected-error {{expected '(' after 'typeof_unqual'}} expected-error {{expected identifier or '('}} |
| 8 |
typeof_unqual 0 int l = 12; // expected-error {{expected '(' after 'typeof_unqual'}} expected-error {{expected identifier or '('}} |
| 9 |
|
| 10 |
// Show that combining typeof with another type specifier fails, but otherwise |
| 11 |
// the expression and type forms are both parsed properly. |
| 12 |
typeof(0) int a = 12; // expected-error {{cannot combine with previous 'typeof' declaration specifier}} |
| 13 |
typeof(0) b = 12; |
| 14 |
typeof_unqual(0) int c = 12; // expected-error {{cannot combine with previous 'typeof_unqual' declaration specifier}} |
| 15 |
typeof_unqual(0) d = 12; |
| 16 |
typeof(int) e = 12; |
| 17 |
typeof_unqual(int) f = 12; |
| 18 |
|
| 19 |
// Show that we can parse nested constructs of both forms. |
| 20 |
typeof(typeof(0)) w; |
| 21 |
typeof_unqual(typeof(0)) x; |
| 22 |
typeof(typeof_unqual(0)) y; |
| 23 |
typeof_unqual(typeof_unqual(0)) z; |
| 24 |
|
| 25 |
// Show that you can spell the type in functions, structures, or as the base |
| 26 |
// type of an enumeration. |
| 27 |
typeof(b) func1(typeof(b) c); |
| 28 |
typeof_unqual(b) func2(typeof_unqual(b) c); |
| 29 |
|
| 30 |
struct S { |
| 31 |
typeof(b) i; |
| 32 |
typeof_unqual(b) j; |
| 33 |
} s; |
| 34 |
|
| 35 |
enum E1 : typeof(b) { FirstZero }; |
| 36 |
enum E2 : typeof_unqual(b) { SecondZero }; |
| 37 |
|
| 38 |
// Show that you can use this type in place of another type and everything |
| 39 |
// works as expected. |
| 40 |
_Static_assert(__builtin_offsetof(typeof(struct S), i) == 0); |
| 41 |
_Static_assert(__builtin_offsetof(typeof(s), i) == 0); |
| 42 |
_Static_assert(__builtin_offsetof(typeof_unqual(struct S), i) == 0); |
| 43 |
_Static_assert(__builtin_offsetof(typeof_unqual(s), i) == 0); |
| 44 |
|