Debian Codegraph @

gcc/testsuite/g++.dg/cpp1z/class-deduction109.C

raw
1 // PR c++/103943
2 // { dg-do compile { target c++17 } }
3
4 template<typename R, typename...AA> struct F0 { //OK
5 R(*fun_ptr)(AA...);
6 };
7 template<typename R, typename...AA> struct F1 { //OK
8 R(*fun_ptr)(AA...);
9 F1(R(*fun_ptr)(AA...)) : fun_ptr(fun_ptr) {}
10 };
11 template<typename R, typename...AA> struct F2 { //OK
12 R(*fun_ptr)(AA...);
13 using fun_ptr_t = decltype(fun_ptr);
14 F2(fun_ptr_t fun_ptr) : fun_ptr(fun_ptr) {}
15 };
16 template<typename R, typename...AA> struct F3 {
17 R(*fun_ptr)(AA...);
18 // using fun_ptr_t = decltype(fun_ptr); //OK as in F2
19 using fun_ptr_t = decltype(F3::fun_ptr); //ICE: Segmentation fault
20 // using fun_ptr_t = decltype(F3<R, AA...>::fun_ptr); //ICE: Segmentation fault
21 F3(fun_ptr_t fun_ptr) : fun_ptr(fun_ptr) {}
22 };
23 template<typename R, typename...AA> struct F4 {
24 static R fun_not_implemented(AA...);
25 // using fun_ptr_t = decltype(&fun_not_implemented); //OK
26 using fun_ptr_t = decltype(&F4::fun_not_implemented); //OK with aggregate initialization (no ctor)
27 // using fun_ptr_t = decltype(&F4<R, AA...>::fun_not_implemented); //OK with aggregate initialization (no ctor)
28 fun_ptr_t fun_ptr;
29 };
30 template<typename R, typename...AA> struct F5 { //OK
31 static R fun_not_implemented(AA...);
32 using fun_ptr_t = decltype(&fun_not_implemented);
33 fun_ptr_t fun_ptr;
34 F5(fun_ptr_t fun_ptr) : fun_ptr(fun_ptr) {}
35 };
36 template<typename R, typename...AA> struct F6 {
37 static R fun_not_implemented(AA...);
38 // using fun_ptr_t = decltype(&fun_not_implemented); //OK as in F5
39 using fun_ptr_t = decltype(&F6::fun_not_implemented); //ICE: in build_qualified_name, at cp/tree.c:2238
40 // using fun_ptr_t = decltype(&F6<R, AA...>::fun_not_implemented); //ICE: in build_qualified_name, at cp/tree.c:2238
41 fun_ptr_t fun_ptr;
42 F6(fun_ptr_t fun_ptr) : fun_ptr(fun_ptr) {}
43 };
44 template<typename R, typename...AA> F0(R(*fun_ptr)(AA...)) -> F0<R, AA...>;
45 template<typename R, typename...AA> F1(R(*fun_ptr)(AA...)) -> F1<R, AA...>;
46 template<typename R, typename...AA> F2(R(*fun_ptr)(AA...)) -> F2<R, AA...>;
47 template<typename R, typename...AA> F3(R(*fun_ptr)(AA...)) -> F3<R, AA...>;
48 template<typename R, typename...AA> F4(R(*fun_ptr)(AA...)) -> F4<R, AA...>;
49 template<typename R, typename...AA> F5(R(*fun_ptr)(AA...)) -> F5<R, AA...>;
50 template<typename R, typename...AA> F6(R(*fun_ptr)(AA...)) -> F6<R, AA...>;
51
52 int fun(int a) {
53 return a + 1;
54 }
55 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
56 void test() {
57 auto f0 = F0{&fun}; //OK
58 auto f1 = F1{&fun}; //OK
59 auto f2 = F2{&fun}; //OK
60 auto f3 = F3{&fun}; //ICE: Segmentation fault
61 auto f4 = F4{&fun}; //OK
62 auto f5 = F5{&fun}; //OK
63 auto f6 = F6{&fun}; //ICE: in build_qualified_name, at cp/tree.c:2238
64 }