| 1 |
// PR c++/88815 |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
|
| 4 |
struct true_type { |
| 5 |
constexpr operator bool() const { return true; } |
| 6 |
}; |
| 7 |
|
| 8 |
struct false_type { |
| 9 |
constexpr operator bool() const { return false; } |
| 10 |
}; |
| 11 |
|
| 12 |
template<int (*p)()> |
| 13 |
true_type is_constexpr_impl(decltype(int{(p(), 0U)})); |
| 14 |
|
| 15 |
template<int (*p)()> |
| 16 |
false_type is_constexpr_impl(...); |
| 17 |
|
| 18 |
template<int (*p)()> |
| 19 |
using is_constexpr = decltype(is_constexpr_impl<p>(0)); |
| 20 |
|
| 21 |
constexpr int f() { return 0; } |
| 22 |
int g() { return 0; } |
| 23 |
|
| 24 |
static_assert(is_constexpr<f>(), ""); |
| 25 |
static_assert(!is_constexpr<g>(), ""); |