Consider this source: #include <stdarg.h> #include <uchar.h> extern void p (const char16_t *fmt, ...) __attribute__((__printf__ (1, 2))); void f() { p(u"%d\n", 23); } Currently gcc rejects this attribute: pokyo. gcc --syntax-only -std=c11 -Wall r.c r.c:5:3: warning: ‘__printf__’ attribute directive ignored [-Wattributes] __attribute__((__printf__ (1, 2))); ^ I don't see why it should, though. It seems to me that it could accept wchar_t, char16_t, or char32_t strings as the format argument.
glibc has this in <wchar.h>: extern int wprintf (const wchar_t *__restrict __format, ...) /* __attribute__ ((__format__ (__wprintf__, 1, 2))) */;
Naturally my example was wrong. Sorry about that. But gcc still doesn't handle it: #include <stdarg.h> #include <uchar.h> extern void p (const char16_t *fmt, ...) __attribute__((format (__printf__, 1, 2))); void f() { p (u"%s %d", 23, "hi"); } ... with gcc saying: r.cc:5:44: error: format string argument is not a string type __attribute__((format (__printf__, 1, 2))); ^
wchar_t part was filed as bug 38308 a long time ago.
Note also that gcc.dg/format tests are run both with and without -DWIDE - the intent there is that wide string formats should be tested, when supported, with essentially the same tests as narrow string formats (via appropriate macros to make the tests generic, e.g. wrapping format strings in a macro L()). That could be applied to other string types as well by running the tests more than twice.
I have a patch for this. I think it fixes bug 38308 and bug 20110 as well. It works by adding a new function to libcpp to convert a string back to the source charset. I still have to get a new copyright assignment. And the test cases are being a pain to update.
(In reply to Tom Tromey from comment #5) > I still have to get a new copyright assignment. > And the test cases are being a pain to update. How is the copyright assignment coming?
Any progress?
Sorry about the extreme delay on this. I think my patch has long since bit-rotted, but I can attach it for reference. I believe my assignment situation got sorted out so this should be fine to read and/or copy from.
Created attachment 45413 [details] ancient patch
Also I think all the test suite changes never really worked.