[libc-commits] [libc] [libc] Support %lc in printf (PR #169983)

Alexey Samsonov via libc-commits libc-commits at lists.llvm.org
Sun Dec 21 11:00:44 PST 2025


================
@@ -33,7 +41,27 @@ LIBC_INLINE int convert_char(Writer<write_mode> *writer,
     RET_IF_RESULT_NEGATIVE(writer->write(' ', padding_spaces));
   }
 
-  RET_IF_RESULT_NEGATIVE(writer->write(c));
+#ifndef LIBC_COPT_PRINTF_DISABLE_WIDE
+  if (to_conv.length_modifier == LengthModifier::l) {
----------------
vonosmas wrote:

I find it really brittle to put if/else blocks under `#ifndef` (especially such long ones), as it makes hard to reason about code flow. It may be cleaner if you put something like:

```
if (to_conv.length_modifier == LengthModifier::l) {
#ifndef LIBC_COPT_PRINTF_DISABLE_WIDE
  wint_t wi = static_cast<wint_t>(to_conv.conv_val_raw);
  <...>
#else
  char c =  static_cast<char>(to_conv.conv_val_raw);
  RET_IF_RESULT_NEGATIVE(writer->write(c));
#endif
} else {
  char c =  static_cast<char>(to_conv.conv_val_raw);
  RET_IF_RESULT_NEGATIVE(writer->write(c));  
}

https://github.com/llvm/llvm-project/pull/169983


More information about the libc-commits mailing list