Closed
Description
demo.cpp:
#include <cstdio>
constexpr const char* foo() {
return "%s %d";
}
struct Bar {
static constexpr char value[] = {'%', 's', '%', 'd', '\0'};
};
constexpr char Bar::value[];
int main() {
printf(foo(), "abc", "def");
printf(Bar::value, "abc", "def");
return 0;
}
Clang does not produce any warning. gcc 11.2.0 produces both warnings:
demo.cpp: In function ‘int main()’:
demo.cpp:13:14: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘const char*’ [-Wformat=]
demo.cpp:14:16: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘const char*’ [-Wformat=]
Clang version is:
clang version 15.0.0 (https://github.com/llvm/llvm-project.git a72cc958a386e5fc97e8c30137fb56eb77ef571c)
Target: x86_64-unknown-linux-gnu
Thread model: posix