[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:45 PST 2025


================
@@ -3487,3 +3493,36 @@ TEST(LlvmLibcSPrintfTest, IndexModeParsing) {
                    "why would u do this, this is such   a pain. %");
 }
 #endif // LIBC_COPT_PRINTF_DISABLE_INDEX_MODE
+
+#ifndef LIBC_COPT_PRINTF_DISABLE_WIDE
+TEST(LlvmLibcSprintfTest, WideCharConversion) {
+  char buff[16];
+  int written;
+
+  // Euro sign is a 3-byte UTF-8 character.
+  written = LIBC_NAMESPACE::sprintf(buff, "%lc", static_cast<wchar_t>(L'€'));
+  EXPECT_EQ(written, 3);
+  ASSERT_STREQ(buff, "€");
+
+  // Euro sign left justified.
+  written = LIBC_NAMESPACE::sprintf(buff, "%-4lc", static_cast<wchar_t>(L'€'));
+  EXPECT_EQ(written, 6);
+  ASSERT_STREQ(buff, "€   ");
+
+  // Euro sign right justified.
+  written = LIBC_NAMESPACE::sprintf(buff, "%4lc", static_cast<wchar_t>(L'€'));
+  EXPECT_EQ(written, 6);
+  ASSERT_STREQ(buff, "   €");
+
+  // WEOF test.
+  written = LIBC_NAMESPACE::sprintf(buff, "%lc", static_cast<wchar_t>(WEOF));
+  EXPECT_EQ(written, -1);
+  ASSERT_ERRNO_FAILURE();
----------------
vonosmas wrote:

I think we should check for precise errno value, not just "some" errno.

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


More information about the libc-commits mailing list