[libcxx-commits] [PATCH] D100005: [libc++] Use the more precise constructor for char_type in std::num_get::do_get.

Yichen Yan via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 6 19:33:36 PDT 2021


oraluben created this revision.
oraluben added reviewers: libc++, ldionne.
oraluben added a project: libc++.
Herald added a subscriber: pengfei.
oraluben requested review of this revision.
Herald added 1 blocking reviewer(s): libc++.

This is to fix the following error that occurred when the char type has the shown constructors.

  root at amdsuplus1:/test# /llvm-install/bin/clang++ -o /dev/null -c test.cc -stdlib=libc++
  In file included from test.cc:1:
  /llvm-install/bin/../include/c++/v1/locale:1072:15: error: conversion from 'int' to 'std::num_get<Char>::char_type' (aka 'Char') is ambiguous
      char_type __thousands_sep = 0;
                ^                 ~
  /llvm-install/bin/../include/c++/v1/locale:583:14: note: in instantiation of member function 'std::num_get<Char>::do_get' requested here
      explicit num_get(size_t __refs = 0)
               ^
  test.cc:49:18: note: in instantiation of member function 'std::num_get<Char>::num_get' requested here
  void foo() { new std::num_get< Char >; }
                   ^
  test.cc:6:3: note: candidate constructor
    Char(char);
    ^
  test.cc:7:3: note: candidate constructor
    Char(unsigned);
    ^
  1 error generated.
  root at amdsuplus1:/test# cat test.cc
  #include <locale>
  class Char {
  public:
    typedef int32_t a;
    Char();
    Char(char);
    Char(unsigned);
    explicit Char(a);
    operator a() const;
  };
  template <> struct std::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 bool eq_int_type(int_type, int_type);
    static int_type eof();
  };
  namespace std {
  template <> class ctype< Char > : public locale::facet {
  public:
    static locale::id id;
    Char toupper(Char) const;
    char widen(const char *, const char *, Char *) const;
  };
  template <> class numpunct< Char > : public std::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 <> class basic_string< Char > {
  public:
    typedef allocator< Char >::const_reference const_reference;
    const_reference operator[](int) const;
    int copy(Char *, int) const;
    int size() const;
    bool empty() const;
  };
  }
  
  void foo() { new std::num_get< Char >; }
  
  root at amdsuplus1:/test# /llvm-install/bin/clang++ --version
  clang version 13.0.0 (https://github.com/llvm/llvm-project.git 1696b8ae96b2d8bcbf90894bd344a8a090f43c84)
  Target: x86_64-unknown-linux-gnu
  Thread model: posix
  InstalledDir: /llvm-install/bin


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100005

Files:
  libcxx/include/locale


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 = '\x00';
     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.335698.patch
Type: text/x-patch
Size: 505 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210407/ea683d5c/attachment.bin>


More information about the libcxx-commits mailing list