https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124469
Bug ID: 124469
Summary: error: 'format' attribute argument 3 value '6' does
not refer to a variable argument list
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: office at faf dot software
Target Milestone: ---
The below code doesn't compile - the error message is in the "Summary".
The parameter 6 is a variable argument list - "this" is 1st, therefore the
counting starts from 2.
Commenting the line with "__attribute__..." compiles and produces the output.
gcc would complain regarding "%d" because I provide an unsigned integer.
https://godbolt.org/z/EqhT5xare
#include <vector>
#include <source_location>
#include <stdio.h>
typedef unsigned int uint;
constexpr std::size_t MAX_LOG_LINE_LENGTH = { 2'500 };
enum LogControllerMode
//--------------------
{
Default = 0,
};
enum class LogControllerType
//--------------------------
{
Normal,
};
template <typename... Ts>
//-----------------------
struct FAEWE_LOG
{
__attribute__ ((format(printf, 5, 7)))
FAEWE_LOG( const uint instrumentsId,
[[maybe_unused]] const LogControllerMode logMode,
[[maybe_unused]] const std::vector<LogControllerType> &
logControllerType,
const char * formatString, Ts &&... LogArguments,
const std::source_location & sourceLocation =
std::source_location::current() )
{
char resolvedParameters [MAX_LOG_LINE_LENGTH];
snprintf( resolvedParameters, sizeof(resolvedParameters),
formatString, LogArguments...);
printf( "%s:%d - [%d] %s\n", sourceLocation.file_name(),
sourceLocation.line(),
instrumentsId, resolvedParameters );
}
};
template <typename... Ts>
FAEWE_LOG( const uint, const LogControllerMode, const
std::vector<LogControllerType>, const char *, Ts &&... )
-> FAEWE_LOG<Ts...>;
auto main () -> int
{
FAEWE_LOG( 5, LogControllerMode::Default, { LogControllerType::Normal },
" This is not a correct printf %s string %d", "formatted", 73U );
return 0;
}