111
|
1 // PR c++/56970
|
|
2 // { dg-do compile { target c++11 } }
|
|
3
|
|
4 template <typename T>
|
|
5 struct has
|
|
6 {
|
|
7 template <typename>
|
|
8 constexpr static int test(...) {
|
|
9 return 0;
|
|
10 }
|
|
11
|
|
12 template <typename C>
|
|
13 constexpr static int test(decltype(sizeof(C::x))) { // Doesn't compile.
|
|
14 return 1; // Is a member variable.
|
|
15 }
|
|
16
|
|
17 template <typename C, int c = sizeof(decltype(((C*)nullptr)->x()))>
|
|
18 constexpr static int test(int) {
|
|
19 return 2; // Is a member function.
|
|
20 }
|
|
21
|
|
22 static const int value = test<T>(0);
|
|
23 };
|
|
24
|
|
25 struct foo {
|
|
26 int x;
|
|
27 };
|
|
28
|
|
29 struct bar {
|
|
30 int x();
|
|
31 };
|
|
32
|
|
33 static_assert(has<int>::value == 0, "");
|
|
34 static_assert(has<foo>::value == 1, "");
|
|
35 static_assert(has<bar>::value == 2, "");
|