[libcxx-commits] [PATCH] D100005: [libc++] Use the default initializer for char_type in std::num_get::do_get.
Brian Cain via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 4 21:54:26 PDT 2023
bcain added inline comments.
================
Comment at: libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/user_defined_char_type.pass.cpp:80
+ static locale::id id;
+ Char toupper(Char c) const { return Char(std::toupper(c.underlying_)); }
+ const char* widen(const char* first, const char* last, Char* dst) const {
----------------
ldionne wrote:
> bcain wrote:
> > I'm investigating a failure that occurs when on this test case in our downstream. I'm not quite certain but it's possible the ambiguity is due to the fact that we are using a 32-bit architecture?
> >
> > ```
> > libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/user_defined_char_type.pass.cpp:80:39: error: ambiguous conversion for functional-style cast from 'int' to 'Char'
> > 80 | Char toupper(Char c) const { return Char(std::toupper(c.underlying_)); }
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > ```
> Yes, that could be. I guess
>
> ```
> Char(unsigned i) : underlying_(i) {}
> explicit Char(std::int32_t i) : underlying_(i) {}
> ```
>
> must be ambiguous somehow? Can you open a PR that fixes your problem? (kinda hard without being able to reproduce locally)
This happens to be effective in getting the test to pass but I'm afraid it might not be a suitable change.
```
diff --git a/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/user_defined_char_type.pass.cpp b/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/user_defined_char_type.pass.cpp
index d7b4b816d975..9d5d6bc03f7f 100644
--- a/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/user_defined_char_type.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/user_defined_char_type.pass.cpp
@@ -21,8 +21,12 @@
struct Char {
Char() = default;
Char(char c) : underlying_(c) {}
+#if UINTPTR_MAX == 0xffffffffffffffff
Char(unsigned i) : underlying_(i) {}
explicit Char(std::int32_t i) : underlying_(i) {}
+#else
+ // 32-bit or other platform, remove potentially ambiguous constructors
+#endif
operator std::int32_t() const { return underlying_; }
char underlying_;
```
BTW here is the unabridged error for more context.
```
# command stderr:
/local/mnt/workspace/hex/llvm-project/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/user_defined_char_type.pass.cpp:80:39: error: ambiguous conversion for functional-style cast from 'int' to 'Char'
80 | Char toupper(Char c) const { return Char(std::toupper(c.underlying_)); }
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/local/mnt/workspace/hex/llvm-project/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/user_defined_char_type.pass.cpp:23:3: note: candidate constructor
23 | Char(char c) : underlying_(c) {}
| ^
/local/mnt/workspace/hex/llvm-project/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/user_defined_char_type.pass.cpp:24:3: note: candidate constructor
24 | Char(unsigned i) : underlying_(i) {}
| ^
/local/mnt/workspace/hex/llvm-project/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/user_defined_char_type.pass.cpp:25:12: note: candidate constructor
25 | explicit Char(std::int32_t i) : underlying_(i) {}
| ^
In file included from /local/mnt/workspace/hex/llvm-project/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/user_defined_char_type.pass.cpp:16:
In file included from /local/mnt/workspace/hex/obj_runtimes_hex88_qurt_v75_ON_ON_shared/include/c++/v1/locale:200:
/local/mnt/workspace/hex/obj_runtimes_hex88_qurt_v75_ON_ON_shared/include/c++/v1/__iterator/istreambuf_iterator.h:82:17: error: ambiguous conversion for static_cast from 'int_type' (aka 'int') to 'char_type' (aka 'Char')
82 | {return static_cast<char_type>(__sbuf_->sgetc());}
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/local/mnt/workspace/hex/obj_runtimes_hex88_qurt_v75_ON_ON_shared/include/c++/v1/locale:323:22: note: in instantiation of member function 'std::istreambuf_iterator<Char>::operator*' requested here
323 | _CharT __c = *__b;
| ^
/local/mnt/workspace/hex/obj_runtimes_hex88_qurt_v75_ON_ON_shared/include/c++/v1/locale:930:37: note: in instantiation of function template specialization 'std::__scan_keyword<std::istreambuf_iterator<Char>, const std::basic_string<Char> *, std::ctype<Char>>' requested here
930 | const string_type* __i = _VSTD::__scan_keyword(__b, __e, __names, __names+2,
| ^
/local/mnt/workspace/hex/obj_runtimes_hex88_qurt_v75_ON_ON_shared/include/c++/v1/locale:610:14: note: in instantiation of member function 'std::num_get<Char>::do_get' requested here
610 | explicit num_get(size_t __refs = 0)
| ^
/local/mnt/workspace/hex/llvm-project/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/user_defined_char_type.pass.cpp:113:45: note: in instantiation of member function 'std::num_get<Char>::num_get' requested here
113 | std::locale l(std::locale::classic(), new std::num_get<Char>);
| ^
/local/mnt/workspace/hex/llvm-project/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/user_defined_char_type.pass.cpp:23:3: note: candidate constructor
23 | Char(char c) : underlying_(c) {}
| ^
/local/mnt/workspace/hex/llvm-project/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/user_defined_char_type.pass.cpp:24:3: note: candidate constructor
24 | Char(unsigned i) : underlying_(i) {}
| ^
/local/mnt/workspace/hex/llvm-project/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/user_defined_char_type.pass.cpp:25:12: note: candidate constructor
25 | explicit Char(std::int32_t i) : underlying_(i) {}
| ^
2 errors generated.
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100005/new/
https://reviews.llvm.org/D100005
More information about the libcxx-commits
mailing list