[libc-commits] [libc] [libc] Support %lc in printf (PR #169983)
Shubh Pachchigar via libc-commits
libc-commits at lists.llvm.org
Tue Dec 2 23:01:46 PST 2025
================
@@ -33,7 +39,21 @@ LIBC_INLINE int convert_char(Writer<write_mode> *writer,
RET_IF_RESULT_NEGATIVE(writer->write(' ', padding_spaces));
}
- RET_IF_RESULT_NEGATIVE(writer->write(c));
+ if (to_conv.length_modifier == LengthModifier::l) {
+ wc = static_cast<wchar_t>(static_cast<unsigned int>(to_conv.conv_val_raw));
----------------
shubhe25p wrote:
Thanks this makes sense, what I was referring to was that naively casting from `conv_val_raw` (BigInt) to `wchar_t` leads to an error in `BigInt to()`, as the casting has a guard clause that essentially checks:
```
struct BigInt {
...
template <typename T>
LIBC_INLINE constexpr cpp::enable_if_t<
cpp::is_integral_v<T> && !cpp::is_same_v<T, bool>, T>
to() const {
... }
```
` is_integral_v ` will return false if the type is not one of:
```
char, signed char, unsigned char, short, unsigned short, int,
unsigned int, long, unsigned long, long long, unsigned long long, bool
```
That is the reason why I cast to `unsigned int` first. Let me know your thoughts
https://github.com/llvm/llvm-project/pull/169983
More information about the libc-commits
mailing list