]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix std::any constraints [PR101034]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 14 Jun 2021 13:18:33 +0000 (14:18 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 14 Jun 2021 14:10:56 +0000 (15:10 +0100)
PR libstdc++/101034

libstdc++-v3/ChangeLog:

* include/std/any (any(in_place_t<T>, initializer_list<U>, A&&...))
(any::emplace<T>(initializer_list<U>, A&&...)): Fix constraint
to use lvalue.
* testsuite/20_util/any/cons/101034.cc: New test.

libstdc++-v3/include/std/any
libstdc++-v3/testsuite/20_util/any/cons/101034.cc [new file with mode: 0644]

index 21120a9146f9774cdcd76c5c960e1b33bc96cdea..a6995b79c4322525bbaa3e8020ffd121f808fbe7 100644 (file)
@@ -205,7 +205,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     /// the contained object.
     template <typename _Tp, typename _Up, typename... _Args,
              typename _VTp = decay_t<_Tp>, typename _Mgr = _Manager<_VTp>,
-             __any_constructible_t<_VTp, initializer_list<_Up>,
+             __any_constructible_t<_VTp, initializer_list<_Up>&,
                                    _Args&&...> = false>
       explicit
       any(in_place_type_t<_Tp>, initializer_list<_Up> __il, _Args&&... __args)
@@ -269,7 +269,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     /// Emplace with an object created from @p __il and @p __args as
     /// the contained object.
     template <typename _Tp, typename _Up, typename... _Args>
-      __emplace_t<decay_t<_Tp>, initializer_list<_Up>, _Args&&...>
+      __emplace_t<decay_t<_Tp>, initializer_list<_Up>&, _Args&&...>
       emplace(initializer_list<_Up> __il, _Args&&... __args)
       {
        using _VTp = decay_t<_Tp>;
diff --git a/libstdc++-v3/testsuite/20_util/any/cons/101034.cc b/libstdc++-v3/testsuite/20_util/any/cons/101034.cc
new file mode 100644 (file)
index 0000000..55f550a
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-do compile { target c++17 } }
+// PR libstdc++/101034 - wrong constraint in std::any's constructor
+
+#include <any>
+
+struct S {
+  S(std::initializer_list<int>&, int) {}
+};
+
+std::any a(std::in_place_type<S>, {0}, 0);
+S& s = a.emplace<S>({0}, 0);