This is to fix the following error that occurred when the char type has the shown constructors.
root@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@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@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
Wouldn't this be more generic?
I doubt that char_type must be constructible from char (at least, no more than from int).
And I guess that a type that is not default-initializable would fail in other places anyway.