[libcxx-commits] [PATCH] D58299: [libcxx] Portability fix: make std::io_base::xalloc() test independent on initial index value.

Andrey Maksimov via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Feb 15 12:12:13 PST 2019


amakc11 created this revision.
Herald added a reviewer: EricWF.
Herald added subscribers: libcxx-commits, arphaman, ldionne.

The requirement <http://eel.is/c++draft/ios.base.storage#1> to `std::io_base::xalloc()` is: "Returns: index++". The requirement <http://eel.is/c++draft/ios.base#3.1> to static field `index` is: "initialized to an unspecified value". This patch removes the dependency of the `std::io_base::xalloc()` test on specific initial value of this static field implemented in libc++ and makes the test pass on other conformant implementations.


Repository:
  rCXX libc++

https://reviews.llvm.org/D58299

Files:
  test/std/input.output/iostreams.base/ios.base/ios.base.storage/xalloc.pass.cpp


Index: test/std/input.output/iostreams.base/ios.base/ios.base.storage/xalloc.pass.cpp
===================================================================
--- test/std/input.output/iostreams.base/ios.base/ios.base.storage/xalloc.pass.cpp
+++ test/std/input.output/iostreams.base/ios.base/ios.base.storage/xalloc.pass.cpp
@@ -17,11 +17,9 @@
 
 int main(int, char**)
 {
-    assert(std::ios_base::xalloc() == 0);
-    assert(std::ios_base::xalloc() == 1);
-    assert(std::ios_base::xalloc() == 2);
-    assert(std::ios_base::xalloc() == 3);
-    assert(std::ios_base::xalloc() == 4);
+    int index = std::ios_base::xalloc();
+    for (int i = 0; i < 10000; ++i)
+        assert(std::ios_base::xalloc() == ++index);
 
   return 0;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58299.187059.patch
Type: text/x-patch
Size: 732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190215/7dfad264/attachment.bin>


More information about the libcxx-commits mailing list