commit 54e520fc40bff5fe441715f23b64c2c788db23dc Author: Jonathan Wakely Date: Fri Jul 14 19:38:51 2017 +0100 Constrain std::variant constructor for class template argument deduction 2017-07-14 Jason Merrill Jonathan Wakely * include/std/variant (variant::variant(_Tp&&)): Constrain to remove the constructor for empty variants from the candidate functions during class template argument deduction. * testsuite/20_util/variant/deduction.cc: New. diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 06646f6..23db6d2 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -1101,6 +1101,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template, variant>>, + typename = enable_if_t<(sizeof...(_Types)>0)>, typename = enable_if_t<__exactly_once<__accepted_type<_Tp&&>> && is_constructible_v<__accepted_type<_Tp&&>, _Tp&&>>> constexpr diff --git a/libstdc++-v3/testsuite/20_util/variant/deduction.cc b/libstdc++-v3/testsuite/20_util/variant/deduction.cc new file mode 100644 index 0000000..33bc9d2 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/variant/deduction.cc @@ -0,0 +1,39 @@ +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +// Copyright (C) 2017 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 + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void +test01() +{ + std::variant x(3); + + std::variant copy = x; + check_type(copy); + std::variant move = std::move(x); + check_type(move); +}