[libcxx-commits] [PATCH] D100005: [libc++] Use the default initializer for char_type in std::num_get::do_get.

Yichen Yan via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Apr 7 06:54:07 PDT 2021


oraluben updated this revision to Diff 335800.
oraluben retitled this revision from "[libc++] Use the more precise constructor for char_type in std::num_get::do_get." to "[libc++] Use the default initializer for char_type in std::num_get::do_get.".
oraluben added a comment.

I checked the standard and [locale.category] says only `num_­get<char>, num_­get<wchar_­t>, num_­put<char>, num_­put<wchar_­t>` are valid, so the test case is not a valid C++ program.
However, `num_­get<C, InputIterator>` is also valid for "any other implementation-defined character types that meet the requirements for a character on which any of the iostream components can be instantiated".


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100005/new/

https://reviews.llvm.org/D100005

Files:
  libcxx/include/locale
  libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/char.compile.pass.cpp


Index: libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/char.compile.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/char.compile.pass.cpp
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+
+// <locale>
+
+#include <locale>
+
+#include "test_macros.h"
+
+struct Char {
+  Char();
+  Char(char);
+  Char(unsigned);
+  explicit Char(int32_t);
+  operator int32_t() const;
+};
+namespace std {
+template <>
+struct char_traits<Char> {
+  typedef Char char_type;
+  typedef int int_type;
+  typedef streamoff off_type;
+  typedef streampos pos_type;
+  static char_type* find(const char_type*, size_t, char_type);
+  static char_type to_char_type(int_type);
+  static int_type to_int_type(char_type);
+  static int eq_int_type(int_type, int_type);
+  static int_type eof();
+};
+template <>
+class ctype<Char> : public locale::facet {
+public:
+  static locale::id id;
+  Char toupper(Char) const;
+  int widen(const char*, const char*, Char*) const;
+};
+template <>
+class numpunct<Char> : public locale::facet {
+public:
+  typedef basic_string<Char> string_type;
+  static locale::id id;
+  Char decimal_point() const;
+  Char thousands_sep() const;
+  string grouping() const;
+  string_type truename() const;
+  string_type falsename() const;
+};
+template <>
+struct basic_string<Char> {
+  Char operator[](int) const;
+  int copy(Char*, int) const;
+  unsigned long size() const;
+  bool empty() const;
+};
+} // namespace std
+void f() { new std::num_get<Char>; }
Index: libcxx/include/locale
===================================================================
--- libcxx/include/locale
+++ libcxx/include/locale
@@ -1069,7 +1069,7 @@
     int __base = 16;
     // Stage 2
     char_type __atoms[26];
-    char_type __thousands_sep = 0;
+    char_type __thousands_sep = char_type();
     string __grouping;
     use_facet<ctype<_CharT> >(__iob.getloc()).widen(__num_get_base::__src,
                                                     __num_get_base::__src + 26, __atoms);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100005.335800.patch
Type: text/x-patch
Size: 2483 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210407/d9f99aa3/attachment.bin>


More information about the libcxx-commits mailing list