[libcxx] r255162 - Use __make_integer_seq builtin for std::make_integer_sequence. Patch by K-ballo.

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 9 14:03:06 PST 2015


Author: ericwf
Date: Wed Dec  9 16:03:06 2015
New Revision: 255162

URL: http://llvm.org/viewvc/llvm-project?rev=255162&view=rev
Log:
Use __make_integer_seq builtin for std::make_integer_sequence. Patch by K-ballo.

Added:
    libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.fail.cpp
    libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.pass.cpp
Modified:
    libcxx/trunk/include/utility
    libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq.fail.cpp
    libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq.pass.cpp
    libcxx/trunk/test/support/test_macros.h

Modified: libcxx/trunk/include/utility
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/utility?rev=255162&r1=255161&r2=255162&view=diff
==============================================================================
--- libcxx/trunk/include/utility (original)
+++ libcxx/trunk/include/utility Wed Dec  9 16:03:06 2015
@@ -680,6 +680,16 @@ struct _LIBCPP_TYPE_VIS_ONLY integer_seq
 template<size_t... _Ip>
     using index_sequence = integer_sequence<size_t, _Ip...>;
 
+#if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
+
+template <class _Tp, _Tp _Ep>
+struct __make_integer_sequence
+{
+    typedef __make_integer_seq<integer_sequence, _Tp, _Ep> type;
+};
+
+#else
+
 namespace __detail {
 
 template<typename _Tp, size_t ..._Extra> struct __repeat;
@@ -733,10 +743,12 @@ struct __make_integer_sequence
 {
     static_assert(is_integral<_Tp>::value,
                   "std::make_integer_sequence can only be instantiated with an integral type" );
-    static_assert(0 <= _Ep, "std::make_integer_sequence input shall not be negative");
+    static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length");
     typedef __make_integer_sequence_unchecked<_Tp, _Ep> type;
 };
 
+#endif
+
 template<class _Tp, _Tp _Np>
     using make_integer_sequence = typename __make_integer_sequence<_Tp, _Np>::type;
 

Modified: libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq.fail.cpp?rev=255162&r1=255161&r2=255162&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq.fail.cpp (original)
+++ libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq.fail.cpp Wed Dec  9 16:03:06 2015
@@ -12,19 +12,23 @@
 // template<class T, T N>
 //   using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
 
+// UNSUPPORTED: c++98, c++03, c++11
+
 #include <utility>
 #include <type_traits>
 #include <cassert>
 
+#include "test_macros.h"
+
 int main()
 {
-#if _LIBCPP_STD_VER > 11
-
-    std::make_integer_sequence<int, -3>::value_type i;
+  typedef std::make_integer_sequence<int, -3> MakeSeqT;
 
+  // std::make_integer_sequence is implemented using a compiler builtin if available.
+  // this builtin has different diagnostic messages than the fallback implementation.
+#if TEST_HAS_BUILTIN(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
+    MakeSeqT i; // expected-error at utility:* {{integer sequences must have non-negative sequence length}}
 #else
-
-X
-
-#endif  // _LIBCPP_STD_VER > 11
+    MakeSeqT i; // expected-error at utility:* {{static_assert failed "std::make_integer_sequence must have a non-negative sequence length"}}
+#endif
 }

Modified: libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq.pass.cpp?rev=255162&r1=255161&r2=255162&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq.pass.cpp Wed Dec  9 16:03:06 2015
@@ -12,14 +12,14 @@
 // template<class T, T N>
 //   using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
 
+// UNSUPPORTED: c++98, c++03, c++11
+
 #include <utility>
 #include <type_traits>
 #include <cassert>
 
 int main()
 {
-#if _LIBCPP_STD_VER > 11
-
     static_assert(std::is_same<std::make_integer_sequence<int, 0>, std::integer_sequence<int>>::value, "");
     static_assert(std::is_same<std::make_integer_sequence<int, 1>, std::integer_sequence<int, 0>>::value, "");
     static_assert(std::is_same<std::make_integer_sequence<int, 2>, std::integer_sequence<int, 0, 1>>::value, "");
@@ -29,6 +29,4 @@ int main()
     static_assert(std::is_same<std::make_integer_sequence<unsigned long long, 1>, std::integer_sequence<unsigned long long, 0>>::value, "");
     static_assert(std::is_same<std::make_integer_sequence<unsigned long long, 2>, std::integer_sequence<unsigned long long, 0, 1>>::value, "");
     static_assert(std::is_same<std::make_integer_sequence<unsigned long long, 3>, std::integer_sequence<unsigned long long, 0, 1, 2>>::value, "");
-
-#endif  // _LIBCPP_STD_VER > 11
 }

Added: libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.fail.cpp?rev=255162&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.fail.cpp (added)
+++ libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.fail.cpp Wed Dec  9 16:03:06 2015
@@ -0,0 +1,18 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <utility>
+
+// template<class T, T N>
+//   using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
+
+// UNSUPPORTED: c++98, c++03, c++11
+
+#define _LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE
+#include "make_integer_seq.fail.cpp"

Added: libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.pass.cpp?rev=255162&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.pass.cpp (added)
+++ libcxx/trunk/test/std/utilities/intseq/intseq.make/make_integer_seq_fallback.pass.cpp Wed Dec  9 16:03:06 2015
@@ -0,0 +1,18 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <utility>
+
+// template<class T, T N>
+//   using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
+
+// UNSUPPORTED: c++98, c++03, c++11
+
+#define _LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE
+#include "make_integer_seq.pass.cpp"

Modified: libcxx/trunk/test/support/test_macros.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/test_macros.h?rev=255162&r1=255161&r2=255162&view=diff
==============================================================================
--- libcxx/trunk/test/support/test_macros.h (original)
+++ libcxx/trunk/test/support/test_macros.h Wed Dec  9 16:03:06 2015
@@ -26,6 +26,12 @@
 #define TEST_HAS_EXTENSION(X) 0
 #endif
 
+#ifdef __has_builtin
+#define TEST_HAS_BUILTIN(X) __has_builtin(X)
+#else
+#define TEST_HAS_BUILTIN(X) 0
+#endif
+
 /* Make a nice name for the standard version */
 #if  __cplusplus <= 199711L
 # define TEST_STD_VER 3




More information about the cfe-commits mailing list