| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 |
// expected-no-diagnostics |
| 3 |
|
| 4 |
template<bool B> |
| 5 |
struct A { }; |
| 6 |
|
| 7 |
constexpr A<false> a; |
| 8 |
constexpr A<false> b; |
| 9 |
|
| 10 |
constexpr int* x = nullptr; |
| 11 |
constexpr short* y = nullptr; |
| 12 |
|
| 13 |
namespace 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 ExplicitArgs |
| 52 |
|
| 53 |
namespace 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 DeducedArgs |