// { dg-do compile { target c++11 } } // FIXME [!HOSTED]: avoidable std::allocator usage // { dg-require-effective-target hosted } // 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 #include #include struct Explicit { Explicit() = default; explicit Explicit(int) {} }; struct ExplicitDefault { explicit ExplicitDefault() {} }; struct ExplicitDefaultDefault { explicit ExplicitDefaultDefault() = default; }; std::tuple f1a() {return {1};} std::tuple f1b() {return {1,2};} std::tuple f1c() {return {1,2,3};} std::tuple f2_a() {return {1};} // { dg-error "explicit constructor" } std::tuple f2_b() {return {1,2};} // { dg-error "explicit constructor" } std::tuple f2_c() {return {1,2,3};} // { dg-error "explicit constructor" } std::tuple f3_a() {return std::tuple{1};} std::tuple f3_b() {return std::tuple{1,2};} std::tuple f3_c() {return std::tuple{1,2,3};} std::tuple f4_a() { return std::tuple{1}; // { dg-error "could not convert" } } std::tuple f4_b() { return std::tuple{1,2}; // { dg-error "could not convert" } } std::tuple f4_c() { return std::tuple{1,2,3}; // { dg-error "could not convert" } } std::tuple f5_a() {return {1};} std::tuple f5_b() {return {1,2};} std::tuple f5_c() {return {1,2,3};} std::tuple f6_a() {return {};} // { dg-error "explicit constructor" } std::tuple f6_b() {return {};} // { dg-error "explicit constructor" } std::tuple f6_c() {return {};} // { dg-error "explicit constructor" } std::tuple f6_d() {return {};} // { dg-error "explicit constructor" } std::tuple f7_a() {return {};} // { dg-error "explicit constructor" } std::tuple f7_b() {return {};} // { dg-error "explicit constructor" } std::tuple f7_c() {return {};} // { dg-error "explicit constructor" } std::tuple fp1() {return std::pair{1,2}; } std::tuple fp2() {return std::pair{1,2}; } std::tuple fp3() {return std::pair{1,2}; } // { dg-error "could not convert" } std::tuple v0_a{1}; std::tuple v0_b{1,2}; std::tuple v0_c{1,2,3}; std::tuple v1_a{1}; std::tuple v1_b{1,2}; std::tuple v1_c{1,2,3}; std::tuple v2_a = {1}; // { dg-error "explicit constructor" } std::tuple v2_b = {1,2}; // { dg-error "explicit constructor" } std::tuple v2_c = {1,2,3}; // { dg-error "explicit constructor" } std::tuple v3_a{std::tuple{1}}; std::tuple v3_b{std::tuple{1,2}}; std::tuple v3_c{std::tuple{1,2,3}}; std::tuple v4_a = std::tuple{1}; // { dg-error "conversion" } std::tuple v4_b = std::tuple{1,2}; // { dg-error "conversion" } std::tuple v4_c = std::tuple{1,2,3}; // { dg-error "conversion" } std::tuple v6_a{1}; std::tuple v6_b{1,2}; std::tuple v6_c{1,2,3}; std::tuple v7_a = {1}; std::tuple v7_b = {1,2}; std::tuple v7_c = {1,2,3}; std::tuple v8_a{std::tuple{1}}; std::tuple v8_b{std::tuple{1,2}}; std::tuple v8_c{std::tuple{1,2,3}}; std::tuple v9_a = std::tuple{1}; std::tuple v9_b = std::tuple{1,2}; std::tuple v9_c = std::tuple{1,2,3}; std::tuple v10_a{v0_a}; std::tuple v10_b{v0_b}; std::tuple v10_c{v0_c}; std::tuple v11_a = v0_a; // { dg-error "conversion" } std::tuple v11_b = v0_b; // { dg-error "conversion" } std::tuple v11_c = v0_c; // { dg-error "conversion" } std::tuple v12_a{v0_a}; std::tuple v12_b{v0_b}; std::tuple v12_c{v0_c}; std::tuple v13_a = v0_a; std::tuple v13_b = v0_b; std::tuple v13_c = v0_c; std::tuple v14{std::pair{1,2}}; std::tuple v15{std::pair{1,2}}; std::tuple v16{std::pair{1,2}}; std::tuple v17 = std::pair{1,2}; std::tuple v18 = std::pair{1,2}; std::tuple v19 = std::pair{1,2}; // { dg-error "conversion" } std::pair v20; std::tuple v21{v20}; std::tuple v22{v20}; std::tuple v23{v20}; std::tuple v24 = v20; std::tuple v25 = v20; std::tuple v26 = v20; // { dg-error "conversion" } std::tuple v27_a{std::allocator_arg, std::allocator{}, 1}; std::tuple v27_b{std::allocator_arg, std::allocator{}, 1, 2}; std::tuple v27_c{std::allocator_arg, std::allocator{}, 1,2,3}; std::tuple v28_a{std::allocator_arg, std::allocator{}, 1}; std::tuple v28_b{std::allocator_arg, std::allocator{}, 1, 2}; std::tuple v28_c{std::allocator_arg, std::allocator{}, 1,2,3}; std::tuple v29_a{std::allocator_arg, std::allocator{}, 1}; std::tuple v29_b{std::allocator_arg, std::allocator{}, 1, 2}; std::tuple v29_c{std::allocator_arg, std::allocator{}, 1,2,3}; std::tuple v30_a = {std::allocator_arg, std::allocator{}, 1}; std::tuple v30_b = {std::allocator_arg, std::allocator{}, 1, 2}; std::tuple v30_c = {std::allocator_arg, std::allocator{}, 1,2,3}; std::tuple v31_a = {std::allocator_arg, std::allocator{}, 1}; std::tuple v31_b = {std::allocator_arg, std::allocator{}, 1, 2}; std::tuple v31_c{std::allocator_arg, std::allocator{}, 1,2,3}; std::tuple v32_a = {std::allocator_arg, std::allocator{ }, 1}; // { dg-error "explicit constructor" } std::tuple v32_b = {std::allocator_arg, std::allocator{}, 1, 2}; // { dg-error "explicit constructor" } std::tuple v32_c = {std::allocator_arg, std::allocator{}, 1,2,3}; // { dg-error "explicit constructor" } std::tuple v33{std::allocator_arg, std::allocator{}, std::pair{1, 2}}; std::tuple v34{std::allocator_arg, std::allocator{}, std::pair{1, 2}}; std::tuple v35{std::allocator_arg, std::allocator{}, std::pair{1, 2}}; std::tuple v36 = {std::allocator_arg, std::allocator{}, std::pair{1, 2}}; std::tuple v37 = {std::allocator_arg, std::allocator{}, std::pair{1, 2}}; std::tuple v38 = {std::allocator_arg, std::allocator{}, std::pair{1, 2}}; // { dg-error "explicit constructor" } std::tuple v39{std::allocator_arg, std::allocator{}, v20}; std::tuple v40{std::allocator_arg, std::allocator{}, v20}; std::tuple v41{std::allocator_arg, std::allocator{}, v20}; std::tuple v42 = {std::allocator_arg, std::allocator{}, v20}; std::tuple v43 = {std::allocator_arg, std::allocator{}, v20}; std::tuple v44 = {std::allocator_arg, std::allocator{ }, v20}; // { dg-error "explicit constructor" } std::tuple v45_a{}; std::tuple v45_b{}; std::tuple v46_a = {}; // { dg-error "explicit constructor" } std::tuple v46_b = {}; // { dg-error "explicit constructor" } std::tuple v47_a{}; std::tuple v47_b{}; std::tuple v48_a = {}; // { dg-error "explicit constructor" } std::tuple v48_b = { }; // { dg-error "explicit constructor" } struct DeletedCopy { DeletedCopy(int); DeletedCopy(const DeletedCopy&) = delete; }; std::tuple v45{42}; std::tuple v46{std::allocator_arg, std::allocator{}, 42}; struct Sanity { int v; }; std::tuple v47(3, {42}); std::tuple v48(3, 4, {42}); std::tuple v49(std::allocator_arg, std::allocator{}, 3, {42}); std::tuple v50(std::allocator_arg, std::allocator{}, 3, 4, {42}); void f8_a(std::tuple) {} void f8_b(std::tuple) {} void f8_c(std::tuple) {} void f9_a(std::tuple) {} void f9_b(std::tuple) {} void f9_c(std::tuple) {} void f10_a(std::tuple) {} void f10_b(std::tuple) {} void f11_a(std::tuple) {} void f11_b(std::tuple) {} void test_arg_passing() { f8_a(v0_a); // { dg-error "could not convert" } f8_b(v0_b); // { dg-error "could not convert" } f8_c(v0_c); // { dg-error "could not convert" } f8_b(v20); // { dg-error "could not convert" } f8_a(v1_a); f8_b(v1_b); f8_c(v1_c); f8_a({1}); // { dg-error "explicit constructor" } f8_b({1,2}); // { dg-error "explicit constructor" } f8_c({1,2,3}); // { dg-error "explicit constructor" } f8_a(std::tuple{}); f8_b(std::tuple{}); f8_c(std::tuple{}); f8_a(std::tuple{}); // { dg-error "could not convert" } f8_b(std::tuple{}); // { dg-error "could not convert" } f8_c(std::tuple{}); // { dg-error "could not convert" } f8_b(std::pair{}); // { dg-error "could not convert" } f9_a(v0_a); f9_b(v0_b); f9_c(v0_c); f9_b(v20); f9_a(v6_a); f9_b(v6_b); f9_c(v6_c); f9_a({1}); f9_b({1,2}); f9_c({1,2,3}); f9_a(std::tuple{}); f9_b(std::tuple{}); f9_c(std::tuple{}); f9_b(std::pair{}); f9_a(std::tuple{}); f9_b(std::tuple{}); f9_c(std::tuple{}); f10_a({}); // { dg-error "explicit constructor" } f10_b({}); // { dg-error "explicit constructor" } f11_a({}); // { dg-error "explicit constructor" } f11_b({}); // { dg-error "explicit constructor" } f10_a(std::tuple{}); f10_b(std::tuple{}); f11_a(std::tuple{}); f11_b(std::tuple{}); }