[libcxx] r303888 - [test] Workaround C1XX bug in uses_allocator_types.hpp

Casey Carter via cfe-commits cfe-commits at lists.llvm.org
Thu May 25 10:42:17 PDT 2017


Author: caseycarter
Date: Thu May 25 12:42:17 2017
New Revision: 303888

URL: http://llvm.org/viewvc/llvm-project?rev=303888&view=rev
Log:
[test] Workaround C1XX bug in uses_allocator_types.hpp

VSO#109062 "Explicit template argument specification with empty template parameter pack expansion does not imply further empty pack expansion"

Differential Revision: https://reviews.llvm.org/D33214

Added:
    libcxx/trunk/test/support/test.workarounds/c1xx_empty_parameter_pack_expansion.pass.cpp
Modified:
    libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair.pass.cpp
    libcxx/trunk/test/support/test_workarounds.h
    libcxx/trunk/test/support/uses_alloc_types.hpp

Modified: libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair.pass.cpp?rev=303888&r1=303887&r2=303888&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair.pass.cpp Thu May 25 12:42:17 2017
@@ -39,6 +39,7 @@ void test_no_inner_alloc()
         using SA = std::scoped_allocator_adaptor<Alloc>;
         static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr);
         Alloc CA(P);
         SA A(CA);
         A.construct(ptr);
@@ -61,6 +62,7 @@ void test_no_inner_alloc()
         using SA = std::scoped_allocator_adaptor<Alloc>;
         static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr);
         Alloc CA(P);
         SA A(CA);
         A.construct(ptr);
@@ -77,7 +79,6 @@ void test_no_inner_alloc()
 
 void test_with_inner_alloc()
 {
-    using VoidAlloc1 = CountingAllocator<void, 1>;
     using VoidAlloc2 = CountingAllocator<void, 2>;
 
     AllocController POuter;
@@ -93,6 +94,7 @@ void test_with_inner_alloc()
         static_assert(!std::uses_allocator<T, Outer>::value, "");
         static_assert(std::uses_allocator<T, Inner>::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr);
         Outer O(POuter);
         Inner I(PInner);
         SA A(O, I);
@@ -119,6 +121,7 @@ void test_with_inner_alloc()
         static_assert(!std::uses_allocator<T, Outer>::value, "");
         static_assert(std::uses_allocator<T, Inner>::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr);
         Outer O(POuter);
         Inner I(PInner);
         SA A(O, I);

Added: libcxx/trunk/test/support/test.workarounds/c1xx_empty_parameter_pack_expansion.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/test.workarounds/c1xx_empty_parameter_pack_expansion.pass.cpp?rev=303888&view=auto
==============================================================================
--- libcxx/trunk/test/support/test.workarounds/c1xx_empty_parameter_pack_expansion.pass.cpp (added)
+++ libcxx/trunk/test/support/test.workarounds/c1xx_empty_parameter_pack_expansion.pass.cpp Thu May 25 12:42:17 2017
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// Verify TEST_WORKAROUND_C1XX_EMPTY_PARAMETER_PACK_EXPANSION.
+
+#include <type_traits>
+
+#include "test_workarounds.h"
+
+template<class T>
+struct identity {
+    using type = T;
+};
+
+template<class...> struct list {};
+
+// C1XX believes this function template is not viable when LArgs is an empty
+// parameter pack.
+template <class ...LArgs>
+int f2(typename identity<LArgs>::type..., int i) {
+    return i;
+}
+
+#ifdef TEST_WORKAROUND_C1XX_EMPTY_PARAMETER_PACK_EXPANSION
+// C1XX believes this function template *is* viable when LArgs is an empty
+// parameter pack. Conforming compilers believe the two overloads are
+// ambiguous when LArgs is an empty pack.
+template <class ...LArgs>
+int f2(int i) {
+    return i;
+}
+#endif
+
+template <class ...LArgs, class ...Args>
+int f1(list<LArgs...>, Args&&... args) {
+    return f2<LArgs const&...>(args...);
+}
+
+int main() {
+    f1(list<>{}, 42);
+}

Modified: libcxx/trunk/test/support/test_workarounds.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/test_workarounds.h?rev=303888&r1=303887&r2=303888&view=diff
==============================================================================
--- libcxx/trunk/test/support/test_workarounds.h (original)
+++ libcxx/trunk/test/support/test_workarounds.h Thu May 25 12:42:17 2017
@@ -20,6 +20,7 @@
 #if defined(TEST_COMPILER_C1XX)
 # define TEST_WORKAROUND_C1XX_BROKEN_NULLPTR_CONVERSION_OPERATOR
 # define TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE
+# define TEST_WORKAROUND_C1XX_EMPTY_PARAMETER_PACK_EXPANSION
 # ifndef _MSC_EXTENSIONS
 #  define TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
 # endif

Modified: libcxx/trunk/test/support/uses_alloc_types.hpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/uses_alloc_types.hpp?rev=303888&r1=303887&r2=303888&view=diff
==============================================================================
--- libcxx/trunk/test/support/uses_alloc_types.hpp (original)
+++ libcxx/trunk/test/support/uses_alloc_types.hpp Thu May 25 12:42:17 2017
@@ -15,6 +15,7 @@
 #include <cstdlib>
 
 #include "test_macros.h"
+#include "test_workarounds.h"
 #include "type_id.h"
 
 // There are two forms of uses-allocator construction:
@@ -256,6 +257,13 @@ private:
         return alloc;
     }
 
+#ifdef TEST_WORKAROUND_C1XX_EMPTY_PARAMETER_PACK_EXPANSION
+    template <class ...LArgs>
+    static CtorAlloc getAllocatorFromPackImp(CtorAlloc const& alloc) {
+        return alloc;
+    }
+#endif
+
     bool has_alloc() const { return alloc_store.get_allocator() != nullptr; }
     const CtorAlloc *get_alloc() const { return alloc_store.get_allocator(); }
 public:




More information about the cfe-commits mailing list