| 1 |
// RUN: %clang_cc1 -verify -std=c++1y %s |
| 2 |
|
| 3 |
namespace PR17846 { |
| 4 |
template <typename T> constexpr T pi = T(3.14); |
| 5 |
template <typename T> constexpr T tau = 2 * pi<T>; |
| 6 |
constexpr double tau_double = tau<double>; |
| 7 |
static_assert(tau_double == 6.28, ""); |
| 8 |
} |
| 9 |
|
| 10 |
namespace PR17848 { |
| 11 |
template<typename T> constexpr T var = 12345; |
| 12 |
template<typename T> constexpr T f() { return var<T>; } |
| 13 |
constexpr int k = f<int>(); |
| 14 |
static_assert(k == 12345, ""); |
| 15 |
} |
| 16 |
|
| 17 |
namespace NonDependent { |
| 18 |
template<typename T> constexpr T a = 0; |
| 19 |
template<typename T> constexpr T b = a<int>; |
| 20 |
static_assert(b<int> == 0, ""); |
| 21 |
} |
| 22 |
|
| 23 |
namespace InstantiationDependent { |
| 24 |
int f(int); |
| 25 |
void f(char); |
| 26 |
|
| 27 |
template<int> constexpr int a = 1; |
| 28 |
template<typename T> constexpr T b = a<sizeof(sizeof(f(T())))>; // expected-error {{invalid application of 'sizeof' to an incomplete type 'void'}} |
| 29 |
|
| 30 |
static_assert(b<int> == 1, ""); |
| 31 |
static_assert(b<char> == 1, ""); // expected-note {{in instantiation of}} |
| 32 |
|
| 33 |
template<typename T> void f() { |
| 34 |
int check[a<sizeof(sizeof(f(T())))> == 0 ? 1 : -1]; // expected-error {{array with a negative size}} |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
namespace PR24483 { |
| 39 |
template<typename> struct A; |
| 40 |
template<typename... T> A<T...> models; |
| 41 |
template<> struct B models<>; // expected-error {{incomplete type 'struct B'}} expected-note {{forward declaration}} |
| 42 |
} |
| 43 |
|
| 44 |
namespace InvalidInsertPos { |
| 45 |
template<typename T, int N> T v; |
| 46 |
template<int N> decltype(v<int, N-1>) v<int, N>; |
| 47 |
template<> int v<int, 0>; |
| 48 |
int k = v<int, 500>; |
| 49 |
} |
| 50 |
|
| 51 |
namespace GH97881_comment { |
| 52 |
template <bool B> |
| 53 |
auto g = sizeof(g<!B>); |
| 54 |
// expected-error@-1 {{the type of variable template specialization 'g<false>'}} |
| 55 |
// expected-note@-2 {{in instantiation of variable template specialization 'GH97881_comment::g'}} |
| 56 |
|
| 57 |
void test() { |
| 58 |
(void)sizeof(g<false>); // expected-note {{in instantiation of variable template specialization 'GH97881_comment::g'}} |
| 59 |
} |
| 60 |
} |