-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Open
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-positiveWarning fires when it should notWarning fires when it should not
Description
Reproducer:
void FormatFunc(const char* format, ...) __attribute__((__format__(__printf__, 1, 2)));
consteval void Foo() {
if (false) {
FormatFunc("test"); // error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
}
}
constexpr void Bar() {
if (false) {
FormatFunc("test"); // ok in constexpr
}
}
consteval void Baz() {
if (false) {
FormatFunc("%s", "test"); // Adding a second arg somehow fixes the warning
}
}The warning is present in clang trunk (https://godbolt.org/z/q336xWjzb) and in all recent versions of clang (I checked clang16-clang19).
A more realistic example:
[[noreturn]] void Panic(const char* format, ...) noexcept __attribute__((__format__(__printf__, 1, 2)));
// assert()-like macro which allows adding description to failure message
#define FANCY_ASSERT(x, ...) \
if (!(x)) { \
Panic(" " __VA_ARGS__); \
}
constexpr int NonZeroConstexpr(int x) {
FANCY_ASSERT(x);
return x;
}
constexpr int x1 = NonZeroConstexpr(1); // ok
// constexpr int x2 = NonZeroConstexpr(0); // error - Panic(...) is not constexpr
// Same, but with consteval
consteval int NonZeroConsteval(int x) {
FANCY_ASSERT(x); // error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
return x;
}Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-positiveWarning fires when it should notWarning fires when it should not