Debian Codegraph @

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

raw
1 // PR c++/87820
2 // { dg-do compile { target c++11 } }
3
4 struct A {
5 constexpr explicit operator int() const { return 0; }
6 };
7
8 template<class T>
9 void f() {
10 A a;
11 T t1 = a; // { dg-error "cannot convert" }
12 T t2 = {a}; // { dg-error "cannot convert" }
13 T t3(a);
14 T t4{a};
15 T t5 = T(a);
16 T t6 = T{a};
17 new T(a);
18 new T{a};
19 }
20
21 template<class T>
22 void g() {
23 T t;
24 int n1 = t; // { dg-error "cannot convert" }
25 int n2 = {t}; // { dg-error "cannot convert" }
26 int n3(t);
27 int n4{t};
28 int n5 = int(t);
29 int n6 = int{t};
30 new int(t);
31 new int{t};
32 }
33
34 template void f<int>();
35 template void g<A>();
36
37 template<class T>
38 struct B {
39 static constexpr A a{};
40 static constexpr T t1 = a; // { dg-error "cannot convert" }
41 static constexpr T t2 = {a}; // { dg-error "cannot convert" }
42 static constexpr T t4{a};
43 static constexpr T t5 = T(a);
44 static constexpr T t6 = T{a};
45 };
46
47 template<class T>
48 struct C {
49 static constexpr T t{};
50 static constexpr int n1 = t; // { dg-error "cannot convert" }
51 static constexpr int n2 = {t}; // { dg-error "cannot convert" }
52 static constexpr int n4{t};
53 static constexpr int n5 = int(t);
54 static constexpr int n6 = int{t};
55 };
56
57 template struct B<int>;
58 template struct C<A>;
59
60 #if __cpp_inline_variables
61 template<class T>
62 struct D {
63 static inline A a;
64 static inline T t1 = a; // { dg-error "cannot convert" "" { target c++17 } }
65 static inline T t2 = {a}; // { dg-error "cannot convert" "" { target c++17 } }
66 static inline T t4{a};
67 static inline T t5 = T(a);
68 static inline T t6 = T{a};
69 };
70
71 template<class T>
72 struct E {
73 static inline T t;
74 static inline int n1 = t; // { dg-error "cannot convert" "" { target c++17 } }
75 static inline int n2 = {t}; // { dg-error "cannot convert" "" { target c++17 } }
76 static inline int n4{t};
77 static inline int n5 = int(t);
78 static inline int n6 = int{t};
79 };
80
81 template struct D<int>;
82 template struct E<A>;
83 #endif