This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/79680] New: format attribute cannot be used with template parameters
- From: "bugzilla at poradnik-webmastera dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 22 Feb 2017 18:01:58 +0000
- Subject: [Bug c/79680] New: format attribute cannot be used with template parameters
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79680
Bug ID: 79680
Summary: format attribute cannot be used with template
parameters
Product: gcc
Version: 5.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: bugzilla@poradnik-webmastera.com
Target Milestone: ---
I had logging function with printf-like declaration, and
__attribute__((format(printf, x, y))). For performance reasons I wanted to add
another one, which accepts constant string only without parameters.
Unfortunately when I created such function, gcc started complaining that call
is ambiguous. I found on stackoverflow that I can change one of extra parameter
into ordinary one with type specified via template. Unfortunately this is also
rejected with error "args to be formatted is not ‘...’". I also tried to use
variadic templates with the same results. Please extent the format attribute so
it also could be applied to ordinary parameters.
Code:
void log(const char* str) {}
template<class T>
__attribute((format(printf, 1, 2)))
void log(const char* fmt, T t, ...) {}
template <typename... T>
__attribute((format(printf, 1, 2)))
void log(const char* fmt, T... args) {}
void test()
{
log("a");
log("%d", 1);
}