Martin Sebor <msebor at gcc dot> changed:

           What    |Removed                     |Added
           Keywords|                            |diagnostic
                 CC|                            |msebor at gcc dot
           Severity|normal                      |enhancement

--- Comment #1 from Martin Sebor <msebor at gcc dot> ---
It would certainly be nice if it did work, though I think it doesn't simply
because attribute format isn't designed to be used with variadic funtion
templates.  I don't have a sense how involved extending it to those would be
but let me confirm this as an enhancement request.

Btw., it's nice to see that because the -Wfornat-length warning runs later than
-Wformat it handles this case even without the attribute.  Moving -Wformat to a
later stage would have the same effect, in addition to letting it detect more
problems (e.g., when the format string isn't a literal).

$ cat z.C && gcc -S -O2  -Wall -Wextra -Wpedantic z.C
char d [4];

template<typename... Args>
static inline void
whatever (char *d, const char *fmt, Args&&... args)
  __builtin_sprintf(d, fmt, args...);

void qq()
  whatever(d, "hi %s", "bob");

z.C: In function ‘void qq()’:
z.C:10:6: warning: ‘%s’ directive writing 3 bytes into a region of size 1
 void qq()
z.C:7:3: note: format output 7 bytes into a destination of size 4
   __builtin_sprintf(d, fmt, args...);

Reply via email to