On 23/01/17 15:55 +0000, Jonathan Wakely wrote:
This adds indirection through a class template partial specialization
so we don't instantiate common_type<_Types...>::type unless we need
it.

        PR libstdc++/79195
        * include/experimental/array (__make_array_elem): New class template
        and partial specialization.
        (__is_reference_wrapper): Move into __make_array_elem specialization.
        (make_array): Use __make_array_elem to determine element type and move
        static assertion into specialization. Qualify std::forward call.
        (to_array): Add exception specifiation.
        * testsuite/experimental/array/make_array.cc: Test argument types
        without a common type.
        * testsuite/experimental/array/neg.cc: Adjust expected error message.

Tested powerpc64le-linux, committed to trunk (because it's only an
experimental TS feature).

Here's a more conservative fix for the gcc-6-branch. I prefer the
cleanup on trunk, as this version will remove any cv-qualifiers from
_Dest, but it's good enough for the branch IMHO.

Tested x86_64-linux, committed to gcc-6-branch.


commit 99ec893357b6b6a2f67027efc6938f30b154dce4
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Wed Feb 1 04:36:38 2017 +0000

    PR libstdc++/79195 fix make_array type deduction
    
    	PR libstdc++/79195
    	* include/experimental/array (make_array): Use common_type<_Dest>
    	and delay instantiation of common_type until after conditional_t.
    	Qualify std::forward call.
    	(to_array): Add exception specification.
    	* testsuite/experimental/array/make_array.cc: Test argument types
    	without a common type.

diff --git a/libstdc++-v3/include/experimental/array b/libstdc++-v3/include/experimental/array
index 31a066b..c01f0f9 100644
--- a/libstdc++-v3/include/experimental/array
+++ b/libstdc++-v3/include/experimental/array
@@ -69,9 +69,9 @@ template <typename _Up>
 template <typename _Dest = void, typename... _Types>
   constexpr auto
   make_array(_Types&&... __t)
-    -> array<conditional_t<is_void_v<_Dest>,
-                           common_type_t<_Types...>,
-                           _Dest>,
+    -> array<typename conditional_t<is_void_v<_Dest>,
+				    common_type<_Types...>,
+				    common_type<_Dest>>::type,
              sizeof...(_Types)>
   {
     static_assert(__or_<
@@ -80,13 +80,12 @@ template <typename _Dest = void, typename... _Types>
                   ::value,
                   "make_array cannot be used without an explicit target type "
                   "if any of the types given is a reference_wrapper");
-    return {{forward<_Types>(__t)...}};
+    return {{ std::forward<_Types>(__t)... }};
   }
 
 template <typename _Tp, size_t _Nm, size_t... _Idx>
   constexpr array<remove_cv_t<_Tp>, _Nm>
-  __to_array(_Tp (&__a)[_Nm],
-             index_sequence<_Idx...>)
+  __to_array(_Tp (&__a)[_Nm], index_sequence<_Idx...>)
   {
     return {{__a[_Idx]...}};
   }
@@ -94,6 +93,7 @@ template <typename _Tp, size_t _Nm, size_t... _Idx>
 template <typename _Tp, size_t _Nm>
   constexpr array<remove_cv_t<_Tp>, _Nm>
   to_array(_Tp (&__a)[_Nm])
+  noexcept(is_nothrow_constructible<remove_cv_t<_Tp>, _Tp&>::value)
   {
     return __to_array(__a, make_index_sequence<_Nm>{});
   }
diff --git a/libstdc++-v3/testsuite/experimental/array/make_array.cc b/libstdc++-v3/testsuite/experimental/array/make_array.cc
index 0ae188b..75f5333 100644
--- a/libstdc++-v3/testsuite/experimental/array/make_array.cc
+++ b/libstdc++-v3/testsuite/experimental/array/make_array.cc
@@ -1,7 +1,6 @@
-// { dg-options "-std=gnu++14" }
-// { dg-do compile }
+// { dg-do compile { target c++14 } }
 
-// Copyright (C) 2015-2016 Free Software Foundation, Inc.
+// Copyright (C) 2015-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
@@ -19,6 +18,7 @@
 // <http://www.gnu.org/licenses/>.
 
 #include <experimental/array>
+#include <functional> // for std::ref and std::reference_wrapper
 
 struct MoveOnly
 {
@@ -27,7 +27,7 @@ struct MoveOnly
   MoveOnly& operator=(MoveOnly&&) = default;
 };
 
-int main()
+void test01()
 {
   char x[42];
   std::array<char, 42> y = std::experimental::to_array(x);
@@ -45,3 +45,13 @@ int main()
     = std::experimental::make_array(1,2L, 3);
   constexpr std::array<MoveOnly, 1> zzz2 = std::experimental::make_array(MoveOnly{});
 }
+
+void test02()
+{
+  // PR libstdc++/79195
+  struct A {};
+  struct B : A {};
+  struct C : A {};
+  auto arr = std::experimental::make_array<A>(B{}, C{});
+  static_assert(std::is_same<decltype(arr), std::array<A, 2>>::value, "");
+}

Reply via email to