[libcxx] r292494 - Merging r292091:

Hans Wennborg via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 19 08:50:47 PST 2017


Author: hans
Date: Thu Jan 19 10:50:46 2017
New Revision: 292494

URL: http://llvm.org/viewvc/llvm-project?rev=292494&view=rev
Log:
Merging r292091:
------------------------------------------------------------------------
r292091 | marshall | 2017-01-15 19:02:10 -0800 (Sun, 15 Jan 2017) | 1 line

Implement the missing constexpr stuff in <array>. Fixes PR#31645.
------------------------------------------------------------------------

Modified:
    libcxx/branches/release_40/   (props changed)
    libcxx/branches/release_40/include/array
    libcxx/branches/release_40/test/std/containers/sequences/array/at.pass.cpp
    libcxx/branches/release_40/test/std/containers/sequences/array/front_back.pass.cpp
    libcxx/branches/release_40/test/std/containers/sequences/array/indexing.pass.cpp

Propchange: libcxx/branches/release_40/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 19 10:50:46 2017
@@ -1,2 +1,2 @@
 /libcxx/branches/apple:136569-137939
-/libcxx/trunk:292013
+/libcxx/trunk:292013,292091

Modified: libcxx/branches/release_40/include/array
URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_40/include/array?rev=292494&r1=292493&r2=292494&view=diff
==============================================================================
--- libcxx/branches/release_40/include/array (original)
+++ libcxx/branches/release_40/include/array Thu Jan 19 10:50:46 2017
@@ -185,14 +185,17 @@ struct _LIBCPP_TEMPLATE_VIS array
     _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;}
 
     // element access:
-    _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n)             {return __elems_[__n];}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference operator[](size_type __n) const {return __elems_[__n];}
-    reference at(size_type __n);
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+    reference operator[](size_type __n)             {return __elems_[__n];}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+    const_reference operator[](size_type __n) const {return __elems_[__n];}
+
+    _LIBCPP_CONSTEXPR_AFTER_CXX14       reference at(size_type __n);
     _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
 
-    _LIBCPP_INLINE_VISIBILITY reference front()             {return __elems_[0];}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front()             {return __elems_[0];}
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];}
-    _LIBCPP_INLINE_VISIBILITY reference back()              {return __elems_[_Size > 0 ? _Size-1 : 0];}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back()              {return __elems_[_Size > 0 ? _Size-1 : 0];}
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const  {return __elems_[_Size > 0 ? _Size-1 : 0];}
 
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
@@ -202,6 +205,7 @@ struct _LIBCPP_TEMPLATE_VIS array
 };
 
 template <class _Tp, size_t _Size>
+_LIBCPP_CONSTEXPR_AFTER_CXX14
 typename array<_Tp, _Size>::reference
 array<_Tp, _Size>::at(size_type __n)
 {

Modified: libcxx/branches/release_40/test/std/containers/sequences/array/at.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_40/test/std/containers/sequences/array/at.pass.cpp?rev=292494&r1=292493&r2=292494&view=diff
==============================================================================
--- libcxx/branches/release_40/test/std/containers/sequences/array/at.pass.cpp (original)
+++ libcxx/branches/release_40/test/std/containers/sequences/array/at.pass.cpp Thu Jan 19 10:50:46 2017
@@ -23,6 +23,14 @@
 // Disable the missing braces warning for this reason.
 #include "disable_missing_braces_warning.h"
 
+#if TEST_STD_VER > 14
+constexpr bool check_idx( size_t idx, double val )
+{ 
+    std::array<double, 3> arr = {1, 2, 3.5};
+	return arr.at(idx) == val;
+}
+#endif
+
 int main()
 {
     {
@@ -82,4 +90,11 @@ int main()
     }
 #endif
 
+#if TEST_STD_VER > 14
+    {
+        static_assert (check_idx(0, 1), "");
+        static_assert (check_idx(1, 2), "");
+        static_assert (check_idx(2, 3.5), "");
+    }
+#endif
 }

Modified: libcxx/branches/release_40/test/std/containers/sequences/array/front_back.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_40/test/std/containers/sequences/array/front_back.pass.cpp?rev=292494&r1=292493&r2=292494&view=diff
==============================================================================
--- libcxx/branches/release_40/test/std/containers/sequences/array/front_back.pass.cpp (original)
+++ libcxx/branches/release_40/test/std/containers/sequences/array/front_back.pass.cpp Thu Jan 19 10:50:46 2017
@@ -9,10 +9,10 @@
 
 // <array>
 
-// reference front();
-// reference back();
+// reference front();       // constexpr in C++17
+// reference back();        // constexpr in C++17
 // const_reference front(); // constexpr in C++14
-// const_reference back(); // constexpr in C++14
+// const_reference back();  // constexpr in C++14
 
 #include <array>
 #include <cassert>
@@ -23,6 +23,20 @@
 // Disable the missing braces warning for this reason.
 #include "disable_missing_braces_warning.h"
 
+#if TEST_STD_VER > 14
+constexpr bool check_front( double val )
+{ 
+    std::array<double, 3> arr = {1, 2, 3.5};
+	return arr.front() == val;
+}
+
+constexpr bool check_back( double val )
+{ 
+    std::array<double, 3> arr = {1, 2, 3.5};
+	return arr.back() == val;
+}
+#endif
+
 int main()
 {
     {
@@ -65,4 +79,10 @@ int main()
     }
 #endif
 
+#if TEST_STD_VER > 14
+    {
+        static_assert (check_front(1),   "");
+        static_assert (check_back (3.5), "");
+    }
+#endif
 }

Modified: libcxx/branches/release_40/test/std/containers/sequences/array/indexing.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/branches/release_40/test/std/containers/sequences/array/indexing.pass.cpp?rev=292494&r1=292493&r2=292494&view=diff
==============================================================================
--- libcxx/branches/release_40/test/std/containers/sequences/array/indexing.pass.cpp (original)
+++ libcxx/branches/release_40/test/std/containers/sequences/array/indexing.pass.cpp Thu Jan 19 10:50:46 2017
@@ -23,6 +23,14 @@
 // Disable the missing braces warning for this reason.
 #include "disable_missing_braces_warning.h"
 
+#if TEST_STD_VER > 14
+constexpr bool check_idx( size_t idx, double val )
+{ 
+    std::array<double, 3> arr = {1, 2, 3.5};
+	return arr[idx] == val;
+}
+#endif
+
 int main()
 {
     {
@@ -63,4 +71,11 @@ int main()
     }
 #endif
 
+#if TEST_STD_VER > 14
+    {
+        static_assert (check_idx(0, 1), "");
+        static_assert (check_idx(1, 2), "");
+        static_assert (check_idx(2, 3.5), "");
+    }
+#endif
 }




More information about the cfe-commits mailing list