[libcxx-commits] [libcxx] f162043 - [libc++][test] Make narrowing in `nasty_char_traits::to_char_type` more explicit (#138375)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jun 3 01:30:54 PDT 2026
Author: A. Jiang
Date: 2026-06-03T16:30:49+08:00
New Revision: f1620435a384c56e718a80ca0b2695285b6ce978
URL: https://github.com/llvm/llvm-project/commit/f1620435a384c56e718a80ca0b2695285b6ce978
DIFF: https://github.com/llvm/llvm-project/commit/f1620435a384c56e718a80ca0b2695285b6ce978.diff
LOG: [libc++][test] Make narrowing in `nasty_char_traits::to_char_type` more explicit (#138375)
Previously, the cast was allowed due to
[P0960R3](https://wg21.link/p0960r3), which made narrowing implicitly
done in the parenthesized aggregate initialization. MSVC doesn't seem
happy with such an implicit manner, despite not being
copy-initialization or list-initialization, and emits warning C4242.
This patch makes the narrowing more explicit to MSVC with `static_cast`.
Follows up 3e7be494f84e51d5f4245d6f39e380a500f226a6.
Added:
Modified:
libcxx/test/support/nasty_string.h
Removed:
################################################################################
diff --git a/libcxx/test/support/nasty_string.h b/libcxx/test/support/nasty_string.h
index c2968f52e3a00..6b17bbc3f2232 100644
--- a/libcxx/test/support/nasty_string.h
+++ b/libcxx/test/support/nasty_string.h
@@ -70,7 +70,7 @@ struct nasty_char_traits {
static constexpr int_type not_eof(int_type c) noexcept { return eq_int_type(c, eof()) ? ~eof() : c; }
- static constexpr char_type to_char_type(int_type c) noexcept { return char_type(c); }
+ static constexpr char_type to_char_type(int_type c) noexcept { return {static_cast<char>(c)}; }
static constexpr int_type to_int_type(char_type c) noexcept { return int_type(c.c); }
More information about the libcxx-commits
mailing list