[libcxx-commits] [PATCH] D72520: [libcxx] [test] Portability fix of std::basic_filebuf::overflow() test.

Andrey Maksimov via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jan 10 09:43:26 PST 2020


amakc11 created this revision.
Herald added a reviewer: EricWF.
Herald added subscribers: libcxx-commits, ldionne, christof.
Herald added a project: libc++.

The standard specifies the behavior <http://eel.is/c++draft/filebuf#virtuals-10> of `std::basic_filebuf::overflow()` as follows: "Behaves according to the description of `basic_­streambuf<charT, traits>​::​overflow(c)`, except that the behavior of “consuming characters” is performed by first converting". The behavior of `basic_­streambuf<charT, traits>​::​overflow(c)` is specified <http://eel.is/c++draft/streambuf#virt.put-5.2> as follows: "Let r be the number of characters in the pending sequence not consumed. If r is nonzero then `pbase()` and `pptr()` are set so that: `pptr() - pbase() == r` and the r characters starting at `pbase()` are the associated output stream. In case r is zero (all characters of the pending sequence have been consumed) then either `pbase()` is set to `nullptr`, or `pbase()` and `pptr()` are both set to the same non-null value". It means that in general the post-condition of this method is `(pptr() == pbase()) || (pbase() == nullptr) || (pptr() - pbase() == r)`. This patch adds this post-condition check and marks other checks as libc++ specific making the test more portable.

BTW, methods `pptr()`, `pbase()` and `epptr()` return pointers, but this test compares their results with zero instead of `nullptr`. This is also fixed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72520

Files:
  libcxx/test/std/input.output/file.streams/fstreams/filebuf.virtuals/overflow.pass.cpp


Index: libcxx/test/std/input.output/file.streams/fstreams/filebuf.virtuals/overflow.pass.cpp
===================================================================
--- libcxx/test/std/input.output/file.streams/fstreams/filebuf.virtuals/overflow.pass.cpp
+++ libcxx/test/std/input.output/file.streams/fstreams/filebuf.virtuals/overflow.pass.cpp
@@ -43,13 +43,14 @@
         test_buf<char> f;
         assert(f.open("overflow.dat", std::ios_base::out) != 0);
         assert(f.is_open());
-        assert(f.pbase() == 0);
-        assert(f.pptr() == 0);
-        assert(f.epptr() == 0);
+        assert(f.pbase() == nullptr);
+        assert(f.pptr()  == nullptr);
+        assert(f.epptr() == nullptr);
         assert(f.overflow('a') == 'a');
-        assert(f.pbase() != 0);
-        assert(f.pptr() == f.pbase());
-        assert(f.epptr() - f.pbase() == 4095);
+        assert((f.pptr() == f.pbase()) || (f.pbase() == nullptr) || (f.pptr() - f.pbase() == 1));
+        LIBCPP_ASSERT(f.pbase() != nullptr);
+        LIBCPP_ASSERT(f.pptr()  == f.pbase());
+        LIBCPP_ASSERT(f.epptr() - f.pbase() == 4095);
     }
     {
         test_buf<char> f;
@@ -63,13 +64,13 @@
         f.pubsetbuf(0, 0);
         assert(f.open("overflow.dat", std::ios_base::out) != 0);
         assert(f.is_open());
-        assert(f.pbase() == 0);
-        assert(f.pptr() == 0);
-        assert(f.epptr() == 0);
+        assert(f.pbase() == nullptr);
+        assert(f.pptr()  == nullptr);
+        assert(f.epptr() == nullptr);
         assert(f.overflow('a') == 'a');
-        assert(f.pbase() == 0);
-        assert(f.pptr() == 0);
-        assert(f.epptr() == 0);
+        assert(f.pbase() == nullptr);
+        assert(f.pptr()  == nullptr);
+        assert(f.epptr() == nullptr);
     }
     {
         test_buf<char> f;
@@ -82,13 +83,14 @@
         test_buf<wchar_t> f;
         assert(f.open("overflow.dat", std::ios_base::out) != 0);
         assert(f.is_open());
-        assert(f.pbase() == 0);
-        assert(f.pptr() == 0);
-        assert(f.epptr() == 0);
+        assert(f.pbase() == nullptr);
+        assert(f.pptr()  == nullptr);
+        assert(f.epptr() == nullptr);
         assert(f.overflow(L'a') == L'a');
-        assert(f.pbase() != 0);
-        assert(f.pptr() == f.pbase());
-        assert(f.epptr() - f.pbase() == 4095);
+        assert((f.pptr() == f.pbase()) || (f.pbase() == nullptr) || (f.pptr() - f.pbase() == 1));
+        LIBCPP_ASSERT(f.pbase() != nullptr);
+        LIBCPP_ASSERT(f.pptr()  == f.pbase());
+        LIBCPP_ASSERT(f.epptr() - f.pbase() == 4095);
     }
     {
         test_buf<wchar_t> f;
@@ -102,13 +104,13 @@
         f.pubsetbuf(0, 0);
         assert(f.open("overflow.dat", std::ios_base::out) != 0);
         assert(f.is_open());
-        assert(f.pbase() == 0);
-        assert(f.pptr() == 0);
-        assert(f.epptr() == 0);
+        assert(f.pbase() == nullptr);
+        assert(f.pptr()  == nullptr);
+        assert(f.epptr() == nullptr);
         assert(f.overflow(L'a') == L'a');
-        assert(f.pbase() == 0);
-        assert(f.pptr() == 0);
-        assert(f.epptr() == 0);
+        assert(f.pbase() == nullptr);
+        assert(f.pptr()  == nullptr);
+        assert(f.epptr() == nullptr);
     }
     {
         test_buf<wchar_t> f;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72520.237351.patch
Type: text/x-patch
Size: 3286 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200110/740f155c/attachment.bin>


More information about the libcxx-commits mailing list