1 // RUN: %clang_cc1 -verify -std=c2x %s
3 // Demonstrate that we get the correct type information. Do this by leaning
4 // heavily on redeclarations needing to use the same type for both decls.
7 extern typeof_unqual(i
) i
;
12 extern const int n
; // expected-note 2 {{previous declaration is here}}
13 extern typeof(i
) n
; // expected-error {{redeclaration of 'n' with a different type: 'typeof (i)' (aka 'int') vs 'const int'}}
14 extern typeof_unqual(n
) n
; // expected-error {{redeclaration of 'n' with a different type: 'typeof_unqual (n)' (aka 'int') vs 'const int'}}
16 // Ensure we get a redeclaration error here for the types not matching.
17 extern typeof(j
) k
; // expected-note {{previous declaration is here}}
18 extern typeof_unqual(j
) k
; // expected-error {{redeclaration of 'k' with a different type: 'typeof_unqual (j)' (aka 'int') vs 'typeof (j)' (aka 'const int')}}
20 // Make sure the type-form of the operator also works.
22 extern typeof_unqual(const int) l
;
24 extern typeof(const int) m
; // expected-note {{previous declaration is here}}
25 extern typeof_unqual(const int) m
; // expected-error {{redeclaration of 'm' with a different type: 'typeof_unqual(const int)' (aka 'int') vs 'typeof(const int)' (aka 'const int')}}
27 // Show that we can use an incomplete type which is then completed later.
28 extern typeof(struct T
) *o
;
29 struct T
{ int a
; } t
;
30 extern typeof(struct T
) *o
;
33 extern typeof_unqual(volatile struct T
) *o
;
34 extern typeof_unqual(t
) *o
;
35 extern typeof_unqual(&t
) o
;
37 // Show that we properly strip the _Atomic qualifier.
38 extern _Atomic
int i2
;
39 extern _Atomic(int) i2
;
40 extern typeof(i2
) i2
; // expected-note {{previous declaration is here}}
41 extern typeof_unqual(i2
) i2
; // expected-error {{redeclaration of 'i2' with a different type: 'typeof_unqual (i2)' (aka 'int') vs 'typeof (i2)' (aka '_Atomic(int)')}}
43 // We cannot take the type of a bit-field.
48 typeof(s
.bit
) nope1
; // expected-error {{invalid application of 'typeof' to bit-field}}
49 typeof_unqual(s
.bit
) nope2
; // expected-error {{invalid application of 'typeof_unqual' to bit-field}}
51 // Show that we properly resolve nested typeof specifiers.
52 extern typeof(typeof(0)) i3
;
53 extern typeof(typeof(int)) i3
;
54 extern typeof(typeof_unqual(0)) i3
;
55 extern typeof(typeof_unqual(int)) i3
;
56 extern typeof_unqual(typeof(0)) i3
;
57 extern typeof_unqual(typeof(int)) i3
;
58 extern typeof_unqual(typeof_unqual(0)) i3
;
59 extern typeof_unqual(typeof_unqual(int)) i3
;
60 extern typeof(typeof_unqual(j
)) i3
;
61 extern typeof(typeof_unqual(const int)) i3
;
62 extern typeof_unqual(typeof(j
)) i3
;
63 extern typeof_unqual(typeof(const int)) i3
;
64 extern typeof_unqual(typeof_unqual(j
)) i3
;
65 extern typeof_unqual(typeof_unqual(const int)) i3
;
67 // Both of these result in a const int rather than an int.
68 extern typeof(typeof(j
)) i4
;
69 extern typeof(typeof(const int)) i4
;
71 // Ensure that redundant qualifiers are allowed, same as with typedefs.
72 typedef const int CInt
;
75 extern const typeof(j
) i4
;
76 extern const typeof(const int) i4
;
77 extern const typeof(CInt
) i4
;
79 // Qualifiers are not redundant here, but validating that the qualifiers are
81 extern const typeof_unqual(j
) i4
;
82 extern const typeof_unqual(const int) i4
;
83 extern const typeof_unqual(CInt
) i4
;
85 // Show that type attributes are stripped from the unqualified version.
86 extern __attribute__((address_space(0))) int type_attr_test_2_obj
;
87 extern int type_attr_test_2
;
88 extern typeof_unqual(type_attr_test_2_obj
) type_attr_test_2
; // expected-note {{previous declaration is here}}
89 extern __attribute__((address_space(0))) int type_attr_test_2
; // expected-error {{redeclaration of 'type_attr_test_2' with a different type: '__attribute__((address_space(0))) int' vs 'typeof_unqual (type_attr_test_2_obj)' (aka 'int')}}
91 // Ensure that an invalid type doesn't cause crashes.
92 void invalid_param_fn(__attribute__((address_space(1))) int i
); // expected-error {{parameter may not be qualified with an address space}}
93 typeof(invalid_param_fn
) invalid_param_1
;
94 typeof_unqual(invalid_param_fn
) invalid_param_2
;