brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.0 KiB · cf879ef Raw
243 lines · cpp
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-mangling2// 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-mangling3 4namespace std {5template<typename T> struct initializer_list {6  const T *begin, *end;7  initializer_list();8};9} // namespace std10 11enum class N {};12 13using Animal = int;14 15using AnimalPtr = Animal *;16 17using Man = Animal;18using Dog = Animal;19 20using ManPtr = Man *;21using DogPtr = Dog *;22 23using SocratesPtr = ManPtr;24 25using ConstMan = const Man;26using ConstDog = const Dog;27 28using Virus = void;29using SARS = Virus;30using Ebola = Virus;31 32using Bacteria = float;33using Bacilli = Bacteria;34using Vibrio = Bacteria;35 36struct Plant;37using Gymnosperm = Plant;38using Angiosperm = Plant;39 40namespace variable {41 42auto x1 = Animal();43N t1 = x1; // expected-error {{lvalue of type 'Animal' (aka 'int')}}44 45auto x2 = AnimalPtr();46N t2 = x2; // expected-error {{lvalue of type 'AnimalPtr' (aka 'int *')}}47 48auto *x3 = AnimalPtr();49N t3 = x3; // expected-error {{lvalue of type 'Animal *' (aka 'int *')}}50 51// Each variable deduces separately.52auto x4 = Man(), x5 = Dog();53N t4 = x4; // expected-error {{lvalue of type 'Man' (aka 'int')}}54N t5 = x5; // expected-error {{lvalue of type 'Dog' (aka 'int')}}55 56auto x6 = { Man(), Dog() };57N t6 = x6; // expected-error {{from 'std::initializer_list<Animal>' (aka 'std::initializer_list<int>')}}58 59} // namespace variable60 61namespace function_basic {62 63auto f1() { return Animal(); }64auto x1 = f1();65N t1 = x1; // expected-error {{lvalue of type 'Animal' (aka 'int')}}66 67decltype(auto) f2() { return Animal(); }68auto x2 = f2();69N t2 = x2; // expected-error {{lvalue of type 'Animal' (aka 'int')}}70 71auto x3 = [a = Animal()] { return a; }();72N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}73 74} // namespace function_basic75 76namespace function_multiple_basic {77 78N t1 = [] { // expected-error {{rvalue of type 'Animal' (aka 'int')}}79  if (true)80    return Man();81  return Dog();82}();83 84N t2 = []() -> decltype(auto) { // expected-error {{rvalue of type 'Animal' (aka 'int')}}85  if (true)86    return Man();87  return Dog();88}();89 90N t3 = [] { // expected-error {{rvalue of type 'Animal' (aka 'int')}}91  if (true)92    return Dog();93  auto x = Man();94  return x;95}();96 97N t4 = [] { // expected-error {{rvalue of type 'int'}}98  if (true)99    return Dog();100  return 1;101}();102 103N t5 = [] { // expected-error {{rvalue of type 'Virus' (aka 'void')}}104  if (true)105    return Ebola();106  return SARS();107}();108 109N t6 = [] { // expected-error {{rvalue of type 'void'}}110  if (true)111    return SARS();112  return;113}();114 115N t7 = [] { // expected-error {{rvalue of type 'Virus' (aka 'void')}}116  if (true)117    return Ebola();118  return SARS{};119}();120 121} // namespace function_multiple_basic122 123#define TEST_AUTO(X, A, B) \124  static_assert(__is_same(A, B), ""); \125  auto X(A a, B b) {       \126    if (0)                 \127      return a;            \128    if (0)                 \129      return b;            \130    return N();            \131  }132#define TEST_DAUTO(X, A, B)     \133  static_assert(__is_same(A, B), ""); \134  decltype(auto) X(A a, B b) {  \135    if (0)                      \136      return static_cast<A>(a); \137    if (0)                      \138      return static_cast<B>(b); \139    return N();                 \140  }141 142namespace misc {143 144TEST_AUTO(t1, ManPtr, DogPtr)      // expected-error {{but deduced as 'Animal *' (aka 'int *')}}145TEST_AUTO(t2, ManPtr, int *)       // expected-error {{but deduced as 'int *'}}146TEST_AUTO(t3, SocratesPtr, ManPtr) // expected-error {{but deduced as 'ManPtr' (aka 'int *')}}147 148TEST_AUTO(t4, _Atomic(Man), _Atomic(Dog)) // expected-error {{but deduced as '_Atomic(Animal)'}}149 150using block_man = void (^)(Man);151using block_dog = void (^)(Dog);152TEST_AUTO(t5, block_man, block_dog) // expected-error {{but deduced as 'void (^__strong)(Animal)'}}153 154#if __cplusplus >= 201500155using fp1 = SARS (*)(Man, DogPtr) throw(Vibrio);156using fp2 = Ebola (*)(Dog, ManPtr) throw(Bacilli);157TEST_AUTO(t6, fp1, fp2); // expected-error {{but deduced as 'Virus (*)(Animal, Animal *) throw(Bacteria)' (aka 'void (*)(int, int *) throw(Bacteria)')}}158 159using fp3 = SARS (*)() throw(Man);160using fp4 = Ebola (*)() throw(Vibrio);161auto t7(fp3 a, fp4 b) {162  if (false)163    return true ? a : b;164  if (false)165    return a;166  return N(); // expected-error {{but deduced as 'Virus (*)() throw(Man, Vibrio)' (aka 'void (*)() throw(Man, Vibrio)')}}167}168#endif169 170using fp5 = void (*)(const Man);171using fp6 = void (*)(Dog);172TEST_AUTO(t8, fp5, fp6); // expected-error {{but deduced as 'void (*)(Animal)' (aka 'void (*)(int)')}}173 174using fp7 = void (*)(ConstMan);175using fp8 = void (*)(ConstDog);176TEST_AUTO(t9, fp7, fp8); // expected-error {{but deduced as 'void (*)(const Animal)' (aka 'void (*)(const int)')}}177 178using fp9 = void (*)(ConstMan);179using fp10 = void (*)(const Dog);180TEST_AUTO(t10, fp9, fp10); // expected-error {{but deduced as 'void (*)(const Animal)' (aka 'void (*)(const int)')}}181 182using fp11 = void (*)(__strong block_man);183using fp12 = void (*)(__weak block_dog);184TEST_AUTO(t11, fp11, fp12); // expected-error {{but deduced as 'void (*)(void (^)(Animal))'}}185 186TEST_AUTO(t12, Man Angiosperm::*, Dog Gymnosperm::*) // expected-error {{but deduced as 'Animal Plant::*'}}187 188TEST_DAUTO(t13, const Man &, const Dog &) // expected-error {{but deduced as 'const Animal &' (aka 'const int &')}}189 190TEST_DAUTO(t14, Man &&, Dog &&) // expected-error {{but deduced as 'Animal &&' (aka 'int &&')}}191 192using matrix_man = Man __attribute__((matrix_type(4, 4)));193using matrix_dog = Dog __attribute__((matrix_type(4, 4)));194TEST_AUTO(t15, matrix_man, matrix_dog) // expected-error {{but deduced as 'Animal __attribute__((matrix_type(4, 4)))'}}195 196using vector_man = Man __attribute__((vector_size(4)));197using vector_dog = Dog __attribute__((vector_size(4)));198TEST_AUTO(t16, vector_man, vector_dog) // expected-error {{but deduced as '__attribute__((__vector_size__(1 * sizeof(Animal)))) Animal' (vector of 1 'Animal' value)}}199 200using ext_vector_man = Man __attribute__((ext_vector_type(4)));201using ext_vector_dog = Dog __attribute__((ext_vector_type(4)));202TEST_AUTO(t17, ext_vector_man, ext_vector_dog) // expected-error {{but deduced as 'Animal __attribute__((ext_vector_type(4)))' (vector of 4 'Animal' values)}}203 204using TwoDogs = Dog[2];205using ConstTwoDogsPtr = const TwoDogs*;206using ConstTwoMenPtr = const Man(*)[2];207TEST_AUTO(t18, ConstTwoDogsPtr, ConstTwoMenPtr); // expected-error {{but deduced as 'const Animal (*)[2]' (aka 'const int (*)[2]')}}208 209} // namespace misc210 211namespace exception_spec {212 213void none();214void dyn_none() throw();215void dyn() throw(int);216void ms_any() throw(...);217void __declspec(nothrow) nothrow();218void noexcept_basic() noexcept;219void noexcept_true() noexcept(true);220void noexcept_false() noexcept(false);221 222#if __cplusplus < 201500223TEST_AUTO(t1, decltype(&noexcept_false), decltype(&noexcept_true)) // expected-error {{but deduced as 'void (*)() noexcept(false)'}}224TEST_AUTO(t2, decltype(&noexcept_basic), decltype(&noexcept_true)) // expected-error {{but deduced as 'void (*)() noexcept(true)'}}225TEST_AUTO(t3, decltype(&none), decltype(&ms_any)) // expected-error {{but deduced as 'void (*)()'}}226TEST_AUTO(t4, decltype(&noexcept_false), decltype(&ms_any)) // expected-error {{but deduced as 'void (*)() throw(...)'}}227TEST_AUTO(t5, decltype(&nothrow), decltype(&noexcept_false)) // expected-error {{but deduced as 'void (*)() noexcept(false)'}}228TEST_AUTO(t6, decltype(&dyn_none), decltype(&nothrow)) // expected-error {{but deduced as 'void (*)() throw()'}}229TEST_AUTO(t7, decltype(&noexcept_true), decltype(&dyn)) // expected-error {{but deduced as 'void (*)() throw(int)'}}230#endif231} // namespace exception_spec232 233namespace non_deduced {234  void f();235  void g();236  void g(int);237  auto h() {238    if (false) return f;239    return g;240    // expected-error@-1 {{returned value of type '<overloaded function type>'}}241  }242} // namespace non_deduced243