template <bool b, auto val> struct enable_ifv {};
template <auto val> struct enable_ifv<true, val> {
static constexpr auto value = val;
};
template <typename T1, typename T2> struct is_same {
static constexpr bool value = false;
};
template <typename T> struct is_same<T, T> {
static constexpr bool value = true;
};
namespace special_cases
{
template<int a>
struct A {
explicit(1 << a)
A(int);
};
A<-1> a(0);
template<int a>
struct B {
explicit(b)
B(int);
};
template<int a>
struct B1 {
explicit(a +)
B1(int);
};
struct B2 {
explicit(false) explicit
B2(int);
};
template<int a>
struct C {
explicit(a == 0)
C(int), C(double); };
C<0> c0 = 0.0; C<0> c1 = 0; C<1> c2 = 0.0;
C<1> c3 = 0;
explicit(false) void f(int);
struct D {
explicit(false) void f(int);};
template <typename T> struct E {
explicit((T{}, false))
E(int);
};
E<void> e = 1;
}
namespace trailing_object {
template<bool b>
struct B {
explicit(b) B(int) {}
};
template<bool b>
struct A : B<b> {
explicit(b) A(int) : B<b>(0) {}
};
A<true> a(0);
}
namespace constructor1 {
template<bool b>
struct A {
explicit(b) A(int, int = 0); };
template<bool b>
A<b>::A(int, int) {}
void f()
{
A<true> a0 = 0; A<true> a1( 0);
A<true> && a2 = 0;A<true> && a3( 0);A<true> a4{ 0};
A<true> && a5 = { 0};A<true> && a6{ 0};
A<true> a7 = { 0};
a0 = 0; a1 = { 0}; a2 = A<true>( 0);
a3 = A<true>{ 0};
A<false> c0 = ((short)0);
A<false> c1( ((short)0));
A<false> && c2 = ((short)0);
A<false> && c3( ((short)0));
A<false> c4{ ((short)0)};
A<false> && c5 = { ((short)0)};
A<false> && c6{ ((short)0)};
A<true> d1( 0, 0);
A<true> d2{ 0, 0};
A<true> d3 = { 0, 0};
d1 = { 0, 0}; d2 = A<true>( 0, 0);
d3 = A<true>{ 0, 0};
}
}
namespace constructor2 {
template<bool a, typename T1>
struct A {
template<typename T2>
explicit(a ^ is_same<T1, T2>::value)
A(T2) {}
};
A<true, int> a0 = 0.0; A<true, int> a1( 0.0);
A<true, int> && a2 = 0.0;A<true, int> && a3( 0.0);A<true, int> a4{ 0.0};
A<true, int> && a5 = { 0.0};A<true, int> && a6{ 0.0};
A<true, int> a7 = { 0.0};
A<true, int> b0 = 0;
A<true, int> b1( 0);
A<true, int> && b2 = 0;
A<true, int> && b3( 0);
A<true, int> b4{ 0};
A<true, int> && b5 = { 0};
A<true, int> && b6{ 0};
A<true, int> b7 = { 0};
A<true, double> c0 = 0; A<true, double> c1( 0);
A<true, double> && c2 = 0;A<true, double> && c3( 0);A<true, double> c4{ 0};
A<true, double> && c5 = { 0};A<true, double> && c6{ 0};
A<true, double> c7 = { 0};
}
namespace constructor_sfinae {
template<bool a>
struct A {
template<typename T>
explicit(enable_ifv<is_same<int, T>::value, a>::value)
A(T) {}
template<typename T, bool c = true>
explicit(enable_ifv<is_same<bool, T>::value, a>::value)
A(T) {}
};
A<true> a0 = 0.0; A<true> a1( 0.0); A<true> a4{ 0.0}; A<true> a7 = { 0.0};
A<true> b0 = 0; A<true> b1( 0);
A<true> b4{ 0};
A<true> b7 = { 0};
A<false> c0 = 0;
A<false> c1( 0);
A<false> c4{ 0};
A<false> c7 = { 0};
A<true> d0 = true; A<true> d1( true);
A<true> d4{ true};
A<true> d7 = { true};
}
namespace conversion {
template<bool a>
struct A {
explicit(a) operator int (); };
template<bool a>
A<a>::operator int() {
return 0;
}
A<true> A_true;
A<false> A_false;
int ai0 = A<true>(); const int& ai1 = A<true>(); int&& ai3 = A<true>(); int ai4 = A_true; const int& ai5 = A_true;
int ai01 = {A<true>()}; const int& ai11 = {A<true>()}; int&& ai31 = {A<true>()}; int ai41 = {A_true}; const int& ai51 = {A_true};
int ae0(A<true>());
const int& ae1(A<true>());
int&& ae3(A<true>());
int ae4(A_true);
const int& ae5(A_true);
int bi0 = A<false>();
const int& bi1 = A<false>();
int&& bi3 = A<false>();
int bi4 = A_false;
const int& bi5 = A_false;
int bi01 = {A<false>()};
const int& bi11 = {A<false>()};
int&& bi31 = {A<false>()};
int bi41 = {A_false};
const int& bi51 = {A_false};
int be0(A<true>());
const int& be1(A<true>());
int&& be3(A<true>());
int be4(A_true);
const int& be5(A_true);
}
namespace conversion2 {
struct B {};
template<bool a>
struct A {
template<typename T2>
explicit(enable_ifv<is_same<B, T2>::value, a>::value)
operator T2() { return T2(); };
};
A<false> A_false;
A<true> A_true;
int ai0 = A<true>(); const int& ai1 = A<true>(); int&& ai3 = A<true>(); int ai4 = A_false; const int& ai5 = A_false;
int ae0{A<true>()}; const int& ae1{A<true>()}; int&& ae3{A<true>()}; int ae4{A_true}; const int& ae5{A_true};
int ap0((A<true>())); const int& ap1((A<true>())); int&& ap3((A<true>())); int ap4(A_true); const int& ap5(A_true);
B b0 = A<true>(); const B & b1 = A<true>(); B && b3 = A<true>(); B b4 = A_true; const B & b5 = A_true;
B be0(A<true>());
const B& be1(A<true>());
B&& be3(A<true>());
B be4(A_true);
const B& be5(A_true);
B c0 = A<false>();
const B & c1 = A<false>();
B && c3 = A<false>();
B c4 = A_false;
const B & c5 = A_false;
}
namespace parameter_pack {
template<typename T>
struct A {
template<typename ... Ts>
explicit((is_same<T, Ts>::value && ...))
A(Ts...);
};
template<typename T>
template<typename ... Ts>
A<T>::A(Ts ...) {}
void f() {
A<int> a0 = 0; A<int> a1( 0, 1);
A<int> a2{ 0, 1};
A<int> a3 = { 0, 1};
a1 = 0; a2 = { 0, 1};
A<double> b0 = 0;
A<double> b1( 0, 1);
A<double> b2{ 0, 1};
A<double> b3 = { 0, 1};
b1 = 0;
b2 = { 0, 1};
}
}
namespace deduction_guide {
template<bool b>
struct B {};
B<true> b_true;
B<false> b_false;
template<typename T>
struct nondeduced
{
using type = T;
};
template<typename T1, typename T2, bool b>
struct A {
explicit(false)
A(typename nondeduced<T1>::type, typename nondeduced<T2>::type, typename nondeduced<B<b>>::type) {}
};
template<typename T1, typename T2, bool b>
explicit(enable_ifv<is_same<T1, T2>::value, b>::value)
A(T1, T2, B<b>) -> A<T1, T2, b>;
void f() {
A a0( 0.0, 1, b_true); A a1{ 0.0, 1, b_true}; A a2 = { 0.0, 1, b_true}; auto a4 = A( 0.0, 1, b_true); auto a5 = A{ 0.0, 1, b_true};
A b0( 0, 1, b_true);
A b1{ 0, 1, b_true};
A b2 = { 0, 1, b_true}; auto b4 = A( 0, 1, b_true);
auto b5 = A{ 0, 1, b_true};
b0 = { 0, 1, b_false};
A c0( 0, 1, b_false);
A c1{ 0, 1, b_false};
A c2 = { 0, 1, b_false};
auto c4 = A( 0, 1, b_false);
auto c5 = A{ 0, 1, b_false};
c2 = { 0, 1, b_false};
}
}
namespace test8 {
template<bool b>
struct A {
template<typename T1, typename T2>
explicit(b)
A(T1, T2) {}
};
template<typename T1, typename T2>
explicit(!is_same<T1, int>::value)
A(T1, T2) -> A<!is_same<int, T2>::value>;
template<bool b>
A<b> v();
void f() {
A a0( 0, 1);
A a1{ 0, 1};
A a2 = { 0, 1};
auto a4 = A( 0, 1);
auto a5 = A{ 0, 1};
auto a6(v<false>());
a6 = { 0, 1};
A b0( 0.0, 1);
A b1{ 0.0, 1};
A b2 = { 0.0, 1}; auto b4 = A( 0.0, 1);
auto b5 = A{ 0.0, 1};
A c0( 0, 1.0);
A c1{ 0, 1.0};
A c2 = { 0, 1.0}; auto c4 = A( 0, 1.0);
auto c5 = A{ 0, 1.0};
auto c6(v<true>());
c0 = { 0, 1.0};
A d0( 0.0, 1.0);
A d1{ 0.0, 1.0};
A d2 = { 0.0, 1.0}; auto d4 = A( 0.0, 1.0);
auto d5 = A{ 0.0, 1.0};
}
}
namespace conversion3 {
template<bool b>
struct A {
explicit(!b) operator int();
explicit(b) operator bool();
};
template<bool b>
A<b>::operator bool() { return false; }
struct B {
void f(int);
void f(bool);
};
void f(A<true> a, B b) {
b.f(a);
}
void f1(A<false> a, B b) {
b.f(a);
}
class X { X(); };
class Y { };
template<bool b>
struct Z {
explicit(b) operator X() const;
explicit(b) operator Y() const; explicit(b) operator int() const; };
void testExplicit()
{
Z<true> z;
Y y2 = z; Y y2b(z);
Y y3 = (Y)z;
Y y4 = Y(z);
Y y5 = static_cast<Y>(z);
int i1 = (int)z;
int i2 = int(z);
int i3 = static_cast<int>(z);
int i4(z);
const Y& y6 = z; const int& y7 = z; const Y& y8(z);
const int& y9(z);
const Y y10{z}; const Y& y11{z}; const int& y12{z};
const X x1{z};
const X& x2{z};
}
struct tmp {};
template<typename T1>
struct C {
template<typename T>
explicit(!is_same<T1, T>::value)
operator T(); };
using Bool = C<bool>;
using Integral = C<int>;
using Unrelated = C<tmp>;
void testBool() {
Bool b;
Integral n;
Unrelated u;
(void) (1 + b); (void) (1 + n);
(void) (1 + u);
(void) (!b);
(void) (!n);
(void) (!u);
(void) (b && true);
(void) (n && true);
(void) (u && true);
(void) (b || true);
(void) (n || true);
(void) (u || true);
(void) (b ? 0 : 1);
(void) (n ? 0: 1);
(void) (u ? 0: 1);
if (b) {}
if (n) {}
if (u) {}
switch (b) {} switch (n) {} switch (u) {}
while (b) {}
while (n) {}
while (u) {}
do {} while (b);
do {} while (n);
do {} while (u);
for (;b;) {}
for (;n;) {}
for (;u;) {}
bool db1(b);
bool db2(n);
bool db3(u);
int di1(b);
int di2(n);
int di3(n);
const bool &direct_cr1(b);
const bool &direct_cr2(n);
const bool &direct_cr3(n);
const int &direct_cr4(b);
const int &direct_cr5(n);
const int &direct_cr6(n);
bool directList1{b};
bool directList2{n};
bool directList3{n};
int directList4{b};
int directList5{n};
int directList6{n};
const bool &directList_cr1{b};
const bool &directList_cr2{n};
const bool &directList_cr3{n};
const int &directList_cr4{b};
const int &directList_cr5{n};
const int &directList_cr6{n};
bool copy1 = b;
bool copy2 = n;bool copyu2 = u;int copy3 = b;int copy4 = n;
int copyu4 = u;const bool ©5 = b;
const bool ©6 = n;const bool ©u6 = u;const int ©7 = b;const int ©8 = n;
const int ©u8 = u;bool copyList1 = {b};
bool copyList2 = {n};bool copyListu2 = {u};int copyList3 = {b};int copyList4 = {n};
int copyListu4 = {u};const bool ©List5 = {b};
const bool ©List6 = {n};const bool ©Listu6 = {u};const int ©List7 = {b};const int ©List8 = {n};
const int ©Listu8 = {u};}
}
namespace deduction_guide2 {
template<typename T1 = int, typename T2 = int>
struct A {
explicit(!is_same<T1, T2>::value)
A(T1 = 0, T2 = 0) {}
};
A a0 = 0;
A a1(0, 0);
A a2{0, 0};
A a3 = {0, 0};
A b0 = 0.0; A b1(0.0, 0.0);
A b2{0.0, 0.0};
A b3 = {0.0, 0.0};
A b4 = {0.0, 0};
template<typename T1, typename T2>
explicit A(T1, T2) -> A<T1, T2>;
A c0 = 0;
A c1(0, 0);
A c2{0, 0};
A c3 = {0, 0};
A d0 = 0.0; A d1(0, 0);
A d2{0, 0};
A d3 = {0.0, 0.0};
}
namespace PR42980 {
using size_t = decltype(sizeof(0));
struct Str { template <size_t N>
explicit(N > 7)
Str(char const (&str)[N]); };
template <size_t N>
Str::Str(char const(&str)[N]) { }
Str a = "short";
Str b = "not so short";
}
namespace P1401 {
const int *ptr;
struct S {
explicit(sizeof(char[2])) S(char); explicit(ptr) S(long); explicit(nullptr) S(int); explicit(42L) S(int, int); explicit(sizeof(char)) S();
explicit(0) S(char, char);
explicit(1L) S(char, char, char);
};
}