Skip to content

Incorrect -Wformat type warnings with non-variadic functions #59824

@sapphyrus

Description

@sapphyrus

This piece of code produces an incorrect warning when compiled with -Wformat:

template <typename... Args>
__attribute__((__format__(__printf__, 1, 2)))
void my_format(char const *format, Args... args);

void foo()
{
	float x = 0.f;

	my_format("%f", x);
}
<source>:9:18: warning: format specifies type 'double' but the argument has type 'float' [-Wformat]
        my_format("%f", x);
                   ~~   ^
                   %f

Meanwhile, declaring my_format as a variadic function results in no warning, as expected:

__attribute__((__format__(__printf__, 1, 2)))
void my_format(char const *format, ...);

void foo()
{
	float x = 0.f;

	my_format("%f", x);
}

It doesn't seem to be related to my_format being templated, declaring it as void my_format(char const *format, float f); results in the same incorrect warning.

Metadata

Metadata

Labels

clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions