This fixes PR libstdc++/80737. I actually can't come up with a minimal test case, because I suspect that there is a front-end bug in GCC. See discussions in the bug.
Tested on x86_64-linux-gnu. Thanks! -- Regards, Tim Shen
commit 6f362991f025069328c4901d95b657d498aad250 Author: Tim Shen <tims...@google.com> Date: Fri May 19 22:26:58 2017 -0700 2017-05-20 Tim Shen <tims...@google.com> PR libstdc++/80737 * include/std/variant(variant::variant): SFINAE on is_same first. * testsuite/20_util/variant/any.cc: test case. diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 0e04a820d69..b9824a5182c 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -936,9 +936,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION noexcept((is_nothrow_move_constructible_v<_Types> && ...)) = default; template<typename _Tp, + typename = enable_if_t<!is_same_v<decay_t<_Tp>, variant>>, typename = enable_if_t<__exactly_once<__accepted_type<_Tp&&>> - && is_constructible_v<__accepted_type<_Tp&&>, _Tp&&> - && !is_same_v<decay_t<_Tp>, variant>>> + && is_constructible_v<__accepted_type<_Tp&&>, _Tp&&>>> constexpr variant(_Tp&& __t) noexcept(is_nothrow_constructible_v<__accepted_type<_Tp&&>, _Tp&&>) diff --git a/libstdc++-v3/testsuite/20_util/variant/any.cc b/libstdc++-v3/testsuite/20_util/variant/any.cc new file mode 100644 index 00000000000..5811d0f055e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/variant/any.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++17" } +// { dg-do compile } + +// 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 +// <http://www.gnu.org/licenses/>. + +#include <any> +#include <variant> + +struct A { std::variant<std::any> a; }; + +void Bar(const A&); + +void Foo() { + A a; + Bar(a); +}