1 // PR c++/52282
2 // { dg-do run { target c++11 } }
3 
4 template <typename T, T V>
valueW5 struct W { static constexpr T value() { return V; } };
6 
7 template <typename T, T V>
valueX8 struct X { typedef T type; static constexpr type value() { return V; } };
9 
10 template <typename T, T V>
valueY11 struct Y { using type = T; static constexpr type value() { return V; } };
12 
13 template <typename T, T V>
decltypeZ14 struct Z { static constexpr decltype(V) value() { return V; } };
15 
16 template <typename T, T V>
17 struct W_ { static constexpr T value = V; };
18 
19 template <typename T, T V>
20 struct X_ { typedef T type; static constexpr type value = V; };
21 
22 template <typename T, T V>
23 struct Y_ { using type = T; static constexpr type value = V; };
24 
25 template <typename T, T V>
26 struct Z_ { static constexpr decltype(V) value = V; };
27 
28 
29 static_assert(W<int, 10>::value() == 10, "oops");
30 static_assert(X<int, 10>::value() == 10, "oops");
31 static_assert(Y<int, 10>::value() == 10, "oops");
32 static_assert(Z<int, 10>::value() == 10, "oops");
33 static_assert(W_<int, 10>::value == 10, "oops");
34 static_assert(X_<int, 10>::value == 10, "oops");
35 static_assert(Y_<int, 10>::value == 10, "oops");
36 static_assert(Z_<int, 10>::value == 10, "oops");
37 
38 extern constexpr int a = 10;
39 static_assert(*W<const int*, &a>::value() == 10, "oops");
40 static_assert(*X<const int*, &a>::value() == 10, "oops");
41 static_assert(*Y<const int*, &a>::value() == 10, "oops");
42 static_assert(*Z<const int*, &a>::value() == 10, "oops");	// ICE
43 static_assert(*W_<const int*, &a>::value == 10, "oops");
44 static_assert(*X_<const int*, &a>::value == 10, "oops");
45 static_assert(*Y_<const int*, &a>::value == 10, "oops");
46 static_assert(*Z_<const int*, &a>::value == 10, "oops");	// ICE
47 
b()48 template <int V> constexpr int b() { return V; }
49 static_assert((W<int(*)(), &b<10>>::value())() == 10, "oops");
50 static_assert((X<int(*)(), &b<10>>::value())() == 10, "oops");	// incorrect evaluation
51 static_assert((Y<int(*)(), &b<10>>::value())() == 10, "oops");	// incorrect evaluation
52 static_assert((Z<int(*)(), &b<10>>::value())() == 10, "oops");	// ICE
53 static_assert(W_<int(*)(), &b<10>>::value() == 10, "oops");
54 static_assert(X_<int(*)(), &b<10>>::value() == 10, "oops");
55 static_assert(Y_<int(*)(), &b<10>>::value() == 10, "oops");
56 static_assert(Z_<int(*)(), &b<10>>::value() == 10, "oops");	// ICE
57 
58 constexpr struct C {
c1C59     constexpr int c1() const { return 10; }
c2C60     static constexpr int c2() { return 10; }
61 } c;
62 
63 static_assert((c.*W<int(C::*)()const, &C::c1>::value())() == 10, "oops");
64 static_assert((c.*X<int(C::*)()const, &C::c1>::value())() == 10, "oops");
65 static_assert((c.*Y<int(C::*)()const, &C::c1>::value())() == 10, "oops");
66 static_assert((c.*Z<int(C::*)()const, &C::c1>::value())() == 10, "oops");
67 static_assert((c.*W_<int(C::*)()const, &C::c1>::value)() == 10, "oops");	// incorrect evaluation
68 static_assert((c.*X_<int(C::*)()const, &C::c1>::value)() == 10, "oops");	// incorrect evaluation
69 static_assert((c.*Y_<int(C::*)()const, &C::c1>::value)() == 10, "oops");	// incorrect evaluation
70 static_assert((c.*Z_<int(C::*)()const, &C::c1>::value)() == 10, "oops");	// incorrect evaluation
71 
72 static_assert((W<int(*)(), &C::c2>::value())() == 10, "oops");
73 static_assert((X<int(*)(), &C::c2>::value())() == 10, "oops");	// incorrect evaluation
74 static_assert((Y<int(*)(), &C::c2>::value())() == 10, "oops");	// incorrect evaluation
75 static_assert((Z<int(*)(), &C::c2>::value())() == 10, "oops");	// ICE
76 static_assert(W_<int(*)(), &C::c2>::value() == 10, "oops");
77 static_assert(X_<int(*)(), &C::c2>::value() == 10, "oops");
78 static_assert(Y_<int(*)(), &C::c2>::value() == 10, "oops");
79 static_assert(Z_<int(*)(), &C::c2>::value() == 10, "oops");	// ICE
80 
81 
82 #include <assert.h>
83 
84 template <typename T, T V>
85 constexpr typename X_<T, V>::type X_<T, V>::value;
86 
main()87 int main() {
88   C c;
89 
90   // correctly evaluates inside method scope
91   int t1 = X<int(*)(), &b<10>>::value()();
92   int t2 = (c.*X_<int(C::*)()const, &C::c1>::value)();
93   int t3 = X<int(*)(), &C::c2>::value()();
94 
95   assert(t1 == 10);
96   assert(t2 == 10);
97   assert(t3 == 10);
98   return 0;
99 }
100