// { dg-do compile { target c++11 } }
// Copyright (C) 2015-2025 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// .
#include
struct Explicit
{
Explicit() = default;
explicit Explicit(int) {}
};
struct ExplicitDefault
{
explicit ExplicitDefault() {}
};
struct ExplicitDefaultDefault
{
explicit ExplicitDefaultDefault() = default;
};
std::pair f1() {return {1,2};}
std::pair f2() {return {1,2};} // { dg-error "explicit constructor" }
std::pair f3() {return std::pair{1,2};}
std::pair f4()
{
return std::pair{1,2}; // { dg-error "could not convert" }
}
std::pair f5() {return {1,2};}
std::pair v0{1,2};
std::pair v1{1,2};
std::pair v2 = {1,2}; // { dg-error "explicit constructor" }
std::pair v3{std::pair{1,2}};
std::pair v4 =
std::pair{1,2}; // { dg-error "conversion" }
std::pair v5(0,0);
std::pair v6{1,2};
std::pair v7 = {1,2};
std::pair v8{std::pair{1,2}};
std::pair v9 = std::pair{1,2};
std::pair v10{v0};
std::pair v11 = v0; // { dg-error "conversion" }
std::pair v12{v0};
std::pair v13 = v0;
void f6(std::pair) {}
void f7(std::pair) {}
std::pair f8()
{
return {}; // { dg-error "convert" }
}
std::pair f9()
{
return {}; // { dg-error "convert" }
}
void f10(std::pair) {}
void f11(std::pair) {}
void test_arg_passing()
{
f6(v0); // { dg-error "could not convert" }
f6(v1);
f6({1,2}); // { dg-error "explicit constructor" }
f6(std::pair{});
f6(std::pair{}); // { dg-error "could not convert" }
f7(v0);
f7(v6);
f7({1,2});
f7(std::pair{});
f7(std::pair{});
f10({}); // { dg-error "convert" }
f11({}); // { dg-error "convert" }
f10(std::pair{});
f11(std::pair{});
}
struct MoveOnly
{
MoveOnly() = default;
MoveOnly(MoveOnly&&) {}
};
struct ExplicitMoveOnly
{
ExplicitMoveOnly() = default;
ExplicitMoveOnly(ExplicitMoveOnly&&) {}
explicit ExplicitMoveOnly(MoveOnly&&) {}
};
std::pair v14{nullptr, MoveOnly{}};
std::pair v15{MoveOnly{}, nullptr};
std::pair v16 =
{nullptr, MoveOnly{}}; // { dg-error "explicit constructor" }
std::pair v17 =
{MoveOnly{}, nullptr}; // { dg-error "explicit constructor" }