Debian Codegraph @

gcc/testsuite/g++.dg/cpp0x/pr52744.C

raw
1 // PR c++/52744
2 // { dg-do compile { target c++11 } }
3
4 struct T
5 {
6 int a;
7 void b(){}
8 int c(int)
9 {
10 return 1;
11 }
12 };
13
14 template<typename CT, CT> struct member_helper;
15
16 template<typename FT, FT(T::*mem)>
17 struct member_helper<FT(T::*), mem>
18 {
19 static const char* worker()
20 {
21 return "for members";
22 }
23 };
24
25 template<typename Return, typename... Args, Return(T::*fun)(Args...)>
26 struct member_helper<Return(T::*)(Args...), fun>
27 {
28 static const char* worker()
29 {
30 return "for member functions returning non void";
31 }
32 };
33
34 template<typename... Args, void(T::*fun)(Args...)>
35 struct member_helper<void(T::*)(Args...), fun>
36 {
37 static const char* worker()
38 {
39 return "for member functions returning void";
40 }
41 };
42
43 void member_test()
44 {
45 member_helper<decltype(&T::a), &T::a>::worker();
46 member_helper<decltype(&T::b), &T::b>::worker();
47 member_helper<decltype(&T::c), &T::c>::worker();
48 }
49
50 typedef void lua_State;
51
52 template<typename T, T> class function_helper
53 {
54 static_assert(sizeof(T) != sizeof(T),
55 "Error: function_helper works with functions (duh)");
56 };
57
58 template<typename Return, typename... Args, Return(*func)(Args...)>
59 struct function_helper<Return(*)(Args...), func>
60 {
61 static int wrapper(lua_State* l)
62 {
63 return 1;
64 }
65 };
66
67 template<typename... Args, void(*func)(Args...)>
68 struct function_helper<void(*)(Args...), func>
69 {
70 static int wrapper(lua_State* l)
71 {
72 return 0;
73 }
74 };
75
76 int ciao(int){ return 0; }
77 void ciao2(int){}
78
79 void function_test()
80 {
81 function_helper<decltype(&ciao), &ciao>::wrapper(0);
82 function_helper<decltype(&ciao2), &ciao2>::wrapper(0);
83 }