Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/explicit1.C

raw
1 // P0892R2
2 // { dg-do compile }
3 // Explicit { dg-require-effective-target exceptions_enabled } to avoid verify compiler messages FAILs for '-fno-exceptions'.
4 // { dg-options "-std=c++2a" }
5
6 constexpr int fn0 () { return 0; }
7 constexpr int fn1 () { return 1; }
8
9 struct S {
10 explicit(true) S(int);
11 explicit(1 == 0) S(int, int);
12 explicit(fn0()) S(int, int, int);
13 explicit(fn1()) S(int, int, int, int);
14 };
15
16 struct X {
17 static const bool value = true;
18 static constexpr bool foo () { return 1; }
19 };
20
21 struct T {
22 explicit(true ? 1 : throw 1) T(int);
23 explicit(true || true ? 1 : throw 1) T(int, int);
24 explicit(X::value) T(int, int, int);
25 explicit(X::foo ()) T(int, int, int, int);
26 };
27
28 struct W {
29 constexpr operator bool() { return true; };
30 };
31
32 struct W2 {
33 constexpr operator bool() { return false; };
34 };
35
36 struct U {
37 explicit(W()) U(int);
38 explicit(W2()) U(int, int);
39 };
40
41 int
42 main ()
43 {
44 S s1 = { 1 }; // { dg-error "converting" }
45 S s1x{ 1 };
46 S s2 = { 2, 3 };
47 S s3 = { 4, 5, 6 };
48 S s4 = { 7, 8, 9, 10 }; // { dg-error "converting" }
49 S s4x{ 7, 8, 9, 10 };
50
51 T t1 = { 1 }; // { dg-error "converting" }
52 T t2 = { 1, 2 }; // { dg-error "converting" }
53 T t3 = { 1, 2, 3 }; // { dg-error "converting" }
54 T t4 = { 1, 2, 3, 4 }; // { dg-error "converting" }
55 T t5{ 1 };
56 T t6{ 1, 2 };
57 T t7{ 1, 2, 3 };
58 T t8{ 1, 2, 3, 4 };
59
60 U u1 = { 1 }; // { dg-error "converting" }
61 U u2{ 1 };
62 U u3 = { 1, 2 };
63 U u4 { 1, 2 };
64 }