This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/79680] New: format attribute cannot be used with template parameters


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);
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]