1 // RUN: %clang_cc1 -fsyntax-only -verify -xobjective-c++ %s -std=c++20 -fms-extensions -fblocks -fobjc-arc -fobjc-runtime-has-weak -fenable-matrix -Wno-dynamic-exception-spec -Wno-c++17-compat-mangling
2 // RUN: %clang_cc1 -fsyntax-only -verify -xobjective-c++ %s -std=c++14 -fms-extensions -fblocks -fobjc-arc -fobjc-runtime-has-weak -fenable-matrix -Wno-dynamic-exception-spec -Wno-c++17-compat-mangling
5 template<typename T
> struct initializer_list
{
15 using AnimalPtr
= Animal
*;
23 using SocratesPtr
= ManPtr
;
25 using ConstMan
= const Man
;
26 using ConstDog
= const Dog
;
32 using Bacteria
= float;
33 using Bacilli
= Bacteria
;
34 using Vibrio
= Bacteria
;
37 using Gymnosperm
= Plant
;
38 using Angiosperm
= Plant
;
43 N t1
= x1
; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
45 auto x2
= AnimalPtr();
46 N t2
= x2
; // expected-error {{lvalue of type 'AnimalPtr' (aka 'int *')}}
48 auto *x3
= AnimalPtr();
49 N t3
= x3
; // expected-error {{lvalue of type 'Animal *' (aka 'int *')}}
51 // Each variable deduces separately.
52 auto x4
= Man(), x5
= Dog();
53 N t4
= x4
; // expected-error {{lvalue of type 'Man' (aka 'int')}}
54 N t5
= x5
; // expected-error {{lvalue of type 'Dog' (aka 'int')}}
56 auto x6
= { Man(), Dog() };
57 N t6
= x6
; // expected-error {{from 'std::initializer_list<Animal>' (aka 'initializer_list<int>')}}
59 } // namespace variable
61 namespace function_basic
{
63 auto f1() { return Animal(); }
65 N t1
= x1
; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
67 decltype(auto) f2() { return Animal(); }
69 N t2
= x2
; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
71 auto x3
= [a
= Animal()] { return a
; }();
72 N t3
= x3
; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
74 } // namespace function_basic
76 namespace function_multiple_basic
{
78 N t1
= [] { // expected-error {{rvalue of type 'Animal' (aka 'int')}}
84 N t2
= []() -> decltype(auto) { // expected-error {{rvalue of type 'Animal' (aka 'int')}}
90 N t3
= [] { // expected-error {{rvalue of type 'Animal' (aka 'int')}}
97 N t4
= [] { // expected-error {{rvalue of type 'int'}}
103 N t5
= [] { // expected-error {{rvalue of type 'Virus' (aka 'void')}}
109 N t6
= [] { // expected-error {{rvalue of type 'void'}}
115 N t7
= [] { // expected-error {{rvalue of type 'Virus' (aka 'void')}}
121 } // namespace function_multiple_basic
123 #define TEST_AUTO(X, A, B) \
124 static_assert(__is_same(A, B), ""); \
132 #define TEST_DAUTO(X, A, B) \
133 static_assert(__is_same(A, B), ""); \
134 decltype(auto) X(A a, B b) { \
136 return static_cast<A>(a); \
138 return static_cast<B>(b); \
144 TEST_AUTO(t1
, ManPtr
, DogPtr
) // expected-error {{but deduced as 'Animal *' (aka 'int *')}}
145 TEST_AUTO(t2
, ManPtr
, int *) // expected-error {{but deduced as 'int *'}}
146 TEST_AUTO(t3
, SocratesPtr
, ManPtr
) // expected-error {{but deduced as 'ManPtr' (aka 'int *')}}
148 TEST_AUTO(t4
, _Atomic(Man
), _Atomic(Dog
)) // expected-error {{but deduced as '_Atomic(Animal)'}}
150 using block_man
= void (^)(Man
);
151 using block_dog
= void (^)(Dog
);
152 TEST_AUTO(t5
, block_man
, block_dog
) // expected-error {{but deduced as 'void (^__strong)(Animal)'}}
154 #if __cplusplus >= 201500
155 using fp1
= SARS (*)(Man
, DogPtr
) throw(Vibrio
);
156 using fp2
= Ebola (*)(Dog
, ManPtr
) throw(Bacilli
);
157 TEST_AUTO(t6
, fp1
, fp2
); // expected-error {{but deduced as 'Virus (*)(Animal, Animal *) throw(Bacteria)' (aka 'void (*)(int, int *) throw(Bacteria)')}}
159 using fp3
= SARS (*)() throw(Man
);
160 using fp4
= Ebola (*)() throw(Vibrio
);
161 auto t7(fp3 a
, fp4 b
) {
166 return N(); // expected-error {{but deduced as 'Virus (*)() throw(Man, Vibrio)' (aka 'void (*)() throw(Man, Vibrio)')}}
170 using fp5
= void (*)(const Man
);
171 using fp6
= void (*)(Dog
);
172 TEST_AUTO(t8
, fp5
, fp6
); // expected-error {{but deduced as 'void (*)(Animal)' (aka 'void (*)(int)')}}
174 using fp7
= void (*)(ConstMan
);
175 using fp8
= void (*)(ConstDog
);
176 TEST_AUTO(t9
, fp7
, fp8
); // expected-error {{but deduced as 'void (*)(const Animal)' (aka 'void (*)(const int)')}}
178 using fp9
= void (*)(ConstMan
);
179 using fp10
= void (*)(const Dog
);
180 TEST_AUTO(t10
, fp9
, fp10
); // expected-error {{but deduced as 'void (*)(const Animal)' (aka 'void (*)(const int)')}}
182 using fp11
= void (*)(__strong block_man
);
183 using fp12
= void (*)(__weak block_dog
);
184 TEST_AUTO(t11
, fp11
, fp12
); // expected-error {{but deduced as 'void (*)(void (^)(Animal))'}}
186 TEST_AUTO(t12
, Man
Angiosperm::*, Dog
Gymnosperm::*) // expected-error {{but deduced as 'Animal Plant::*'}}
188 TEST_DAUTO(t13
, const Man
&, const Dog
&) // expected-error {{but deduced as 'const Animal &' (aka 'const int &')}}
190 TEST_DAUTO(t14
, Man
&&, Dog
&&) // expected-error {{but deduced as 'Animal &&' (aka 'int &&')}}
192 using matrix_man
= Man
__attribute__((matrix_type(4, 4)));
193 using matrix_dog
= Dog
__attribute__((matrix_type(4, 4)));
194 TEST_AUTO(t15
, matrix_man
, matrix_dog
) // expected-error {{but deduced as 'Animal __attribute__((matrix_type(4, 4)))'}}
196 using vector_man
= Man
__attribute__((vector_size(4)));
197 using vector_dog
= Dog
__attribute__((vector_size(4)));
198 TEST_AUTO(t16
, vector_man
, vector_dog
) // expected-error {{but deduced as '__attribute__((__vector_size__(1 * sizeof(Animal)))) Animal' (vector of 1 'Animal' value)}}
200 using ext_vector_man
= Man
__attribute__((ext_vector_type(4)));
201 using ext_vector_dog
= Dog
__attribute__((ext_vector_type(4)));
202 TEST_AUTO(t17
, ext_vector_man
, ext_vector_dog
) // expected-error {{but deduced as 'Animal __attribute__((ext_vector_type(4)))' (vector of 4 'Animal' values)}}
204 using TwoDogs
= Dog
[2];
205 using ConstTwoDogsPtr
= const TwoDogs
*;
206 using ConstTwoMenPtr
= const Man(*)[2];
207 TEST_AUTO(t18
, ConstTwoDogsPtr
, ConstTwoMenPtr
); // expected-error {{but deduced as 'const Animal (*)[2]' (aka 'const int (*)[2]')}}
211 namespace exception_spec
{
214 void dyn_none() throw();
215 void dyn() throw(int);
216 void ms_any() throw(...);
217 void __declspec(nothrow
) nothrow();
218 void noexcept_basic() noexcept
;
219 void noexcept_true() noexcept(true);
220 void noexcept_false() noexcept(false);
222 #if __cplusplus < 201500
223 TEST_AUTO(t1
, decltype(&noexcept_false
), decltype(&noexcept_true
)) // expected-error {{but deduced as 'void (*)() noexcept(false)'}}
224 TEST_AUTO(t2
, decltype(&noexcept_basic
), decltype(&noexcept_true
)) // expected-error {{but deduced as 'void (*)() noexcept(true)'}}
225 TEST_AUTO(t3
, decltype(&none
), decltype(&ms_any
)) // expected-error {{but deduced as 'void (*)()'}}
226 TEST_AUTO(t4
, decltype(&noexcept_false
), decltype(&ms_any
)) // expected-error {{but deduced as 'void (*)() throw(...)'}}
227 TEST_AUTO(t5
, decltype(¬hrow
), decltype(&noexcept_false
)) // expected-error {{but deduced as 'void (*)() noexcept(false)'}}
228 TEST_AUTO(t6
, decltype(&dyn_none
), decltype(¬hrow
)) // expected-error {{but deduced as 'void (*)() throw()'}}
229 TEST_AUTO(t7
, decltype(&noexcept_true
), decltype(&dyn
)) // expected-error {{but deduced as 'void (*)() throw(int)'}}
231 } // namespace exception_spec
233 namespace non_deduced
{
240 // expected-error@-1 {{returned value of type '<overloaded function type>'}}
242 } // namespace non_deduced