summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2017-07-14 19:13:49 +0000
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2017-07-14 19:13:49 +0000
commitc33389c59b1e0f0805f63e44425849ae2e8c99fe (patch)
tree98d5298be92e1ed9201dbc5347653e1c5836120b
parent1e84d0ef89e03be49e4c364c109a9aa160f93a9b (diff)
downloadgcc-c33389c59b1e0f0805f63e44425849ae2e8c99fe.tar.gz
Constrain std::variant constructor for class template argument deduction
2017-07-14 Jason Merrill <jason@redhat.com> Jonathan Wakely <jwakely@redhat.com> * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@250213 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog8
-rw-r--r--libstdc++-v3/include/std/variant1
-rw-r--r--libstdc++-v3/testsuite/20_util/variant/deduction.cc39
3 files changed, 48 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 04a1c7f7aee..70d1944490e 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,11 @@
+2017-07-14 Jason Merrill <jason@redhat.com>
+ Jonathan Wakely <jwakely@redhat.com>
+
+ * 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.
+
2017-07-11 Jonathan Wakely <jwakely@redhat.com>
* doc/xml/faq.xml: Update several old entries. Improve
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 06646f6b798..23db6d27529 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -1101,6 +1101,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp,
typename = enable_if_t<!is_same_v<decay_t<_Tp>, 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 00000000000..33bc9d2a40e
--- /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
+// <http://www.gnu.org/licenses/>.
+
+#include <variant>
+
+template<typename T, typename U> struct require_same;
+template<typename T> struct require_same<T, T> { using type = void; };
+
+template<typename T, typename U>
+ typename require_same<T, U>::type
+ check_type(U&) { }
+
+void
+test01()
+{
+ std::variant<int, double> x(3);
+
+ std::variant copy = x;
+ check_type<decltype(x)>(copy);
+ std::variant move = std::move(x);
+ check_type<decltype(x)>(move);
+}