This patch enhances clang's ability to check compile-time determinable
string literals as format strings, and can give FixIt hints at literals
(unlike gcc). Issue https://github.com/llvm/llvm-project/issues/55805
mentiond two compile-time string cases. And this patch partially fixes
one.
constexpr const char* foo() { return "%s %d"; } int main() { printf(foo(), "abc", "def"); return 0; }
This patch enables clang check format string for this:
<source>:4:24: warning: format specifies type 'int' but the argument has type 'const char *' [-Wformat] printf(foo(), "abc", "def"); ~~~~~ ^~~~~ <source>:2:42: note: format string is defined here constexpr const char *foo() { return "%s %d"; } ^~ %s 1 warning generated.
Signed-off-by: YingChi Long <me@inclyc.cn>
A comment above this line would be helpful. Would also visually separate it from the return above, which just confused me.