[libcxx-commits] [libcxx] r357545 - [libcxx] [test] Fix test bugs in string.cons/copy_alloc.pass.cpp.

Billy Robert O'Neal III via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 2 17:05:50 PDT 2019


Author: bion
Date: Tue Apr  2 17:05:49 2019
New Revision: 357545

URL: http://llvm.org/viewvc/llvm-project?rev=357545&view=rev
Log:
[libcxx] [test] Fix test bugs in string.cons/copy_alloc.pass.cpp.

Fixed the inability to properly rebind the testing allocator, by making the
inner alloc_impl type a plain struct and making the operations templates. Before
rebind failed to compile complaining that a alloc_impl<T>* was not convertible
to an alloc_impl<U>*.

This enables the test to pass for MSVC++ once we provide the strong guarantee
for the copy assignment operator.

Reviewed as https://reviews.llvm.org/D60023

Modified:
    libcxx/trunk/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp

Modified: libcxx/trunk/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp?rev=357545&r1=357544&r2=357545&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp Tue Apr  2 17:05:49 2019
@@ -18,12 +18,12 @@
 #include "min_allocator.h"
 
 #ifndef TEST_HAS_NO_EXCEPTIONS
-template <class T>
 struct alloc_imp {
     bool active;
 
     alloc_imp() : active(true) {}
 
+    template <class T>
     T* allocate(std::size_t n)
     {
         if (active)
@@ -32,6 +32,7 @@ struct alloc_imp {
             throw std::bad_alloc();
     }
 
+    template <class T>
     void deallocate(T* p, std::size_t) { std::free(p); }
     void activate  ()                  { active = true; }
     void deactivate()                  { active = false; }
@@ -42,14 +43,14 @@ struct poca_alloc {
     typedef T value_type;
     typedef std::true_type propagate_on_container_copy_assignment;
 
-    alloc_imp<T> *imp;
+    alloc_imp *imp;
 
-    poca_alloc(alloc_imp<T> *imp_) : imp (imp_) {}
+    poca_alloc(alloc_imp *imp_) : imp (imp_) {}
 
     template <class U>
     poca_alloc(const poca_alloc<U>& other) : imp(other.imp) {}
 
-    T*   allocate  (std::size_t n)       { return imp->allocate(n);}
+    T*   allocate  (std::size_t n)       { return imp->allocate<T>(n);}
     void deallocate(T* p, std::size_t n) { imp->deallocate(p, n); }
 };
 
@@ -112,8 +113,8 @@ int main(int, char**)
     const char * p1 = "This is my first string";
     const char * p2 = "This is my second string";
 
-    alloc_imp<char> imp1;
-    alloc_imp<char> imp2;
+    alloc_imp imp1;
+    alloc_imp imp2;
     S s1(p1, A(&imp1));
     S s2(p2, A(&imp2));
 




More information about the libcxx-commits mailing list