| 1 |
// RUN: %clang_cc1 -std=c++17 -verify %s |
| 2 |
|
| 3 |
template<typename T> int not_constexpr() { return T::error; } |
| 4 |
template<typename T> constexpr int is_constexpr() { return T::error; } // expected-error {{'::'}} |
| 5 |
|
| 6 |
template<typename T> int not_constexpr_var = T::error; |
| 7 |
template<typename T> constexpr int is_constexpr_var = T::error; // expected-error {{'::'}} |
| 8 |
template<typename T> const int is_const_var = T::error; // expected-error {{'::'}} |
| 9 |
template<typename T> const volatile int is_const_volatile_var = T::error; |
| 10 |
template<typename T> T is_dependent_var = T::error; // expected-error {{'::'}} |
| 11 |
template<typename T> int &is_reference_var = T::error; // expected-error {{'::'}} |
| 12 |
template<typename T> float is_float_var = T::error; |
| 13 |
|
| 14 |
void test() { |
| 15 |
// Do not instantiate functions referenced in unevaluated operands... |
| 16 |
(void)sizeof(not_constexpr<long>()); |
| 17 |
(void)sizeof(is_constexpr<long>()); |
| 18 |
(void)sizeof(not_constexpr_var<long>); |
| 19 |
(void)sizeof(is_constexpr_var<long>); |
| 20 |
(void)sizeof(is_const_var<long>); |
| 21 |
(void)sizeof(is_const_volatile_var<long>); |
| 22 |
(void)sizeof(is_dependent_var<long>); |
| 23 |
(void)sizeof(is_dependent_var<const long>); |
| 24 |
(void)sizeof(is_reference_var<long>); |
| 25 |
(void)sizeof(is_float_var<long>); |
| 26 |
|
| 27 |
// ... but do if they are potentially constant evaluated, and refer to |
| 28 |
// constexpr functions or to variables usable in constant expressions. |
| 29 |
(void)sizeof(int{not_constexpr<int>()}); |
| 30 |
(void)sizeof(int{is_constexpr<int>()}); // expected-note {{instantiation of}} |
| 31 |
(void)sizeof(int{not_constexpr_var<int>}); |
| 32 |
(void)sizeof(int{is_constexpr_var<int>}); // expected-note {{instantiation of}} |
| 33 |
(void)sizeof(int{is_const_var<int>}); // expected-note {{instantiation of}} |
| 34 |
(void)sizeof(int{is_const_volatile_var<int>}); |
| 35 |
(void)sizeof(int{is_dependent_var<int>}); |
| 36 |
(void)sizeof(int{is_dependent_var<const int>}); // expected-note {{instantiation of}} |
| 37 |
(void)sizeof(int{is_reference_var<int>}); // expected-note {{instantiation of}} |
| 38 |
(void)sizeof(int{is_float_var<int>}); // expected-error {{cannot be narrowed}} expected-note {{cast}} |
| 39 |
} |