[libcxx-commits] [libcxx] 363a8a0 - [libc++] money_get::do_get() set failbit and eofbit if iterator begin equals end

Jason Liu via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 28 19:23:17 PDT 2021


Author: Jason Liu
Date: 2021-07-28T22:23:09-04:00
New Revision: 363a8a05988de8f5771fd1330b0fa9a4d2ae4944

URL: https://github.com/llvm/llvm-project/commit/363a8a05988de8f5771fd1330b0fa9a4d2ae4944
DIFF: https://github.com/llvm/llvm-project/commit/363a8a05988de8f5771fd1330b0fa9a4d2ae4944.diff

LOG: [libc++] money_get::do_get() set failbit and eofbit if iterator begin equals end

Summary:
Currently, if we pass in the same iterator for begin and end,
the long double version of do_get would throw a runtime error.

However, according to standard (https://eel.is/c++draft/locale.money.get#virtuals-1),
we should set the failbit and eofbit when no more characters are available.

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

Added: 
    

Modified: 
    libcxx/include/locale
    libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_en_US.pass.cpp
    libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_string_en_US.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/include/locale b/libcxx/include/locale
index 8e584005da08a..82c27bad6f51e 100644
--- a/libcxx/include/locale
+++ b/libcxx/include/locale
@@ -2891,6 +2891,10 @@ money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e,
                                             unique_ptr<char_type, void(*)(void*)>& __wb,
                                             char_type*& __wn, char_type* __we)
 {
+    if (__b == __e) {
+        __err |= ios_base::failbit;
+        return false;
+    }
     const unsigned __bz = 100;
     unsigned __gbuf[__bz];
     unique_ptr<unsigned, void(*)(void*)> __gb(__gbuf, __do_nothing);

diff  --git a/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_en_US.pass.cpp b/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_en_US.pass.cpp
index 41dc94bc0fed5..24167bb4f8564 100644
--- a/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_en_US.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_en_US.pass.cpp
@@ -721,6 +721,17 @@ int main(int, char**)
             assert(err == std::ios_base::failbit);
         }
     }
+    {
+      // test for err
+      const my_facet f(1);
+      std::string v = "1.23";
+      typedef cpp17_input_iterator<const char*> I;
+      long double ex = -1L;
+      std::ios_base::iostate err = std::ios_base::goodbit;
+      f.get(I(v.data()), I(v.data()), false, ios, err, ex);
+      assert(err == (std::ios_base::failbit | std::ios_base::eofbit));
+      assert(ex == -1L);
+    }
 
   return 0;
 }

diff  --git a/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_string_en_US.pass.cpp b/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_string_en_US.pass.cpp
index 2f329463ae7e0..08119ec7333a8 100644
--- a/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_string_en_US.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_string_en_US.pass.cpp
@@ -729,6 +729,17 @@ int main(int, char**)
             assert(ex == L"");
         }
     }
+    {
+      // test for err
+      const my_facet f(1);
+      std::string v = "1.23";
+      typedef cpp17_input_iterator<const char*> I;
+      std::string ex = "NULL";
+      std::ios_base::iostate err = std::ios_base::goodbit;
+      f.get(I(v.data()), I(v.data()), false, ios, err, ex);
+      assert(err == (std::ios_base::failbit | std::ios_base::eofbit));
+      assert(ex == "NULL");
+    }
 
   return 0;
 }


        


More information about the libcxx-commits mailing list