brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · cc1d4ec Raw
73 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s2// expected-no-diagnostics3 4template<bool B>5struct A { };6 7constexpr A<false> a;8constexpr A<false> b;9 10constexpr int* x = nullptr;11constexpr short* y = nullptr;12 13namespace ExplicitArgs {14  template<typename T, typename U>15  constexpr int f(U) noexcept(noexcept(T())) {16    return 0;17  }18 19  template<typename T>20  constexpr int f(T*) noexcept {21    return 1;22  }23 24  template<>25  constexpr int f<int>(int*) noexcept {26    return 2;27  }28 29  static_assert(f<int>(1) == 0);30  static_assert(f<short>(y) == 1);31  static_assert(f<int>(x) == 2);32 33  template<typename T, typename U>34  constexpr int g(U*) noexcept(noexcept(T())) {35    return 3;36  }37 38  template<typename T>39  constexpr int g(T) noexcept {40    return 4;41  }42 43  template<>44  constexpr int g<int>(int*) noexcept {45    return 5;46  }47 48  static_assert(g<int>(y) == 3);49  static_assert(g<short>(1) == 4);50  static_assert(g<int>(x) == 5);51} // namespace ExplicitArgs52 53namespace DeducedArgs {54  template<typename T, bool B>55  constexpr int f(T, A<B>) noexcept(B) {56    return 0;57  }58 59  template<typename T, bool B>60  constexpr int f(T*, A<B>) noexcept(B && B) {61    return 1;62  }63 64  template<>65  constexpr int f(int*, A<false>) {66    return 2;67  }68 69  static_assert(f<int*>(x, a) == 0);70  static_assert(f<short>(y, a) == 1);71  static_assert(f<int>(x, a) == 2);72} // namespace DeducedArgs73