[cfe-dev] [RFC] format attribute support for non-builtin types?

Marcus Johnson via cfe-dev cfe-dev at lists.llvm.org
Tue May 19 00:35:05 PDT 2020


I want to extend Clang's FormatStringLiteral class in Sema to support char16_t, char32_t, and wchar_t in not just C++, but C as well.




C++ has char16_t and char32_t as builtin types, and as of C++20 char8_t is a builtin type as well.

the problem is that C does not have char16_t and char32_t as builtin types.

in C, char16_t and char32_t are `#define'd` in the <uchar.h> header to be uint_least16_t and uint_least32_t types, which is usually defined to be unsigned short and unsigned int, but it depends on the platform.

but the real underlying problem is that Clang's Sema currently only supports builtin types in the FormatStringLiteral class.

So, a solution to this problem is we can allow any user provided type to work with FormatStringLiteral, but that is probably not the best solution.

another solution is to traverse the AST to check if the underlying type is simply a null terminated array of basic types char, short, or int.

but I still think that leaves a lot of room for ambiguity.

is there a better way, where we can canonize certain typedefs as valid character types, and have FormatStringLiteral accept only C++'s builtins and these canonized types?


More information about the cfe-dev mailing list