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 } // namespace function_multiple_basic
117 #define TEST_AUTO(X, A, B) \
118 static_assert(__is_same(A, B), ""); \
126 #define TEST_DAUTO(X, A, B) \
127 static_assert(__is_same(A, B), ""); \
128 decltype(auto) X(A a, B b) { \
130 return static_cast<A>(a); \
132 return static_cast<B>(b); \
138 TEST_AUTO(t1
, ManPtr
, DogPtr
) // expected-error {{but deduced as 'Animal *' (aka 'int *')}}
139 TEST_AUTO(t2
, ManPtr
, int *) // expected-error {{but deduced as 'int *'}}
140 TEST_AUTO(t3
, SocratesPtr
, ManPtr
) // expected-error {{but deduced as 'ManPtr' (aka 'int *')}}
142 TEST_AUTO(t4
, _Atomic(Man
), _Atomic(Dog
)) // expected-error {{but deduced as '_Atomic(Animal)'}}
144 using block_man
= void (^)(Man
);
145 using block_dog
= void (^)(Dog
);
146 TEST_AUTO(t5
, block_man
, block_dog
) // expected-error {{but deduced as 'void (^__strong)(Animal)'}}
148 #if __cplusplus >= 201500
149 using fp1
= SARS (*)(Man
, DogPtr
) throw(Vibrio
);
150 using fp2
= Ebola (*)(Dog
, ManPtr
) throw(Bacilli
);
151 TEST_AUTO(t6
, fp1
, fp2
); // expected-error {{but deduced as 'Virus (*)(Animal, Animal *) throw(Bacteria)' (aka 'void (*)(int, int *) throw(Bacteria)')}}
153 using fp3
= SARS (*)() throw(Man
);
154 using fp4
= Ebola (*)() throw(Vibrio
);
155 auto t7(fp3 a
, fp4 b
) {
160 return N(); // expected-error {{but deduced as 'Virus (*)() throw(Man, Vibrio)' (aka 'void (*)() throw(Man, Vibrio)')}}
164 using fp5
= void (*)(const Man
);
165 using fp6
= void (*)(Dog
);
166 TEST_AUTO(t8
, fp5
, fp6
); // expected-error {{but deduced as 'void (*)(Animal)' (aka 'void (*)(int)')}}
168 using fp7
= void (*)(ConstMan
);
169 using fp8
= void (*)(ConstDog
);
170 TEST_AUTO(t9
, fp7
, fp8
); // expected-error {{but deduced as 'void (*)(const Animal)' (aka 'void (*)(const int)')}}
172 using fp9
= void (*)(ConstMan
);
173 using fp10
= void (*)(const Dog
);
174 TEST_AUTO(t10
, fp9
, fp10
); // expected-error {{but deduced as 'void (*)(const Animal)' (aka 'void (*)(const int)')}}
176 using fp11
= void (*)(__strong block_man
);
177 using fp12
= void (*)(__weak block_dog
);
178 TEST_AUTO(t11
, fp11
, fp12
); // expected-error {{but deduced as 'void (*)(void (^)(Animal))'}}
180 TEST_AUTO(t12
, Man
Angiosperm::*, Dog
Gymnosperm::*) // expected-error {{but deduced as 'Animal Plant::*'}}
182 TEST_DAUTO(t13
, const Man
&, const Dog
&) // expected-error {{but deduced as 'const Animal &' (aka 'const int &')}}
184 TEST_DAUTO(t14
, Man
&&, Dog
&&) // expected-error {{but deduced as 'Animal &&' (aka 'int &&')}}
186 using matrix_man
= Man
__attribute__((matrix_type(4, 4)));
187 using matrix_dog
= Dog
__attribute__((matrix_type(4, 4)));
188 TEST_AUTO(t15
, matrix_man
, matrix_dog
) // expected-error {{but deduced as 'Animal __attribute__((matrix_type(4, 4)))'}}
190 using vector_man
= Man
__attribute__((vector_size(4)));
191 using vector_dog
= Dog
__attribute__((vector_size(4)));
192 TEST_AUTO(t16
, vector_man
, vector_dog
) // expected-error {{but deduced as '__attribute__((__vector_size__(1 * sizeof(Animal)))) Animal' (vector of 1 'Animal' value)}}
194 using ext_vector_man
= Man
__attribute__((ext_vector_type(4)));
195 using ext_vector_dog
= Dog
__attribute__((ext_vector_type(4)));
196 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)}}
198 using TwoDogs
= Dog
[2];
199 using ConstTwoDogsPtr
= const TwoDogs
*;
200 using ConstTwoMenPtr
= const Man(*)[2];
201 TEST_AUTO(t18
, ConstTwoDogsPtr
, ConstTwoMenPtr
); // expected-error {{but deduced as 'const Animal (*)[2]' (aka 'const int (*)[2]')}}
205 namespace exception_spec
{
208 void dyn_none() throw();
209 void dyn() throw(int);
210 void ms_any() throw(...);
211 void __declspec(nothrow
) nothrow();
212 void noexcept_basic() noexcept
;
213 void noexcept_true() noexcept(true);
214 void noexcept_false() noexcept(false);
216 #if __cplusplus < 201500
217 TEST_AUTO(t1
, decltype(&noexcept_false
), decltype(&noexcept_true
)) // expected-error {{but deduced as 'void (*)() noexcept(false)'}}
218 TEST_AUTO(t2
, decltype(&noexcept_basic
), decltype(&noexcept_true
)) // expected-error {{but deduced as 'void (*)() noexcept(true)'}}
219 TEST_AUTO(t3
, decltype(&none
), decltype(&ms_any
)) // expected-error {{but deduced as 'void (*)()'}}
220 TEST_AUTO(t4
, decltype(&noexcept_false
), decltype(&ms_any
)) // expected-error {{but deduced as 'void (*)() throw(...)'}}
221 TEST_AUTO(t5
, decltype(¬hrow
), decltype(&noexcept_false
)) // expected-error {{but deduced as 'void (*)() noexcept(false)'}}
222 TEST_AUTO(t6
, decltype(&dyn_none
), decltype(¬hrow
)) // expected-error {{but deduced as 'void (*)() throw()'}}
223 TEST_AUTO(t7
, decltype(&noexcept_true
), decltype(&dyn
)) // expected-error {{but deduced as 'void (*)() throw(int)'}}
225 } // namespace exception_spec
227 namespace non_deduced
{
234 // expected-error@-1 {{returned value of type '<overloaded function type>'}}
236 } // namespace non_deduced