http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54433

             Bug #: 54433
           Summary: bogus -Wmissing-format-attribute warnings when "first
                    to check" is wrong
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: b.r.longb...@gmail.com


For code like the following, GCC tries to convince me that any function taking
a ptr-to-char should be given the format attribute.

This is due to an incorrect fix for bug 1017 (the comments of which finally
made me realize the bug in my own code - it should be 2, not 0. Sigh, can't you
just autodetect the '...'? You give an error if any other nonzero number is
given)

((The correct fix is to check whether the ptr-to-char argument is being passed
to an attribute'd function. This seems to be almost, but not quite, entirely
unlike what happens when -Wmissing-format-attribute gives a correct warning.))

Bad: 4.3.6 .. 4.7.0

// compile with -Wmissing-format-attribute
#include <stdio.h>
#include <stdarg.h>

__attribute__((format(printf, 1, 0) ))
void my_log(const char * fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    vfprintf(stderr, fmt, ap);
    va_end(ap);
}

void not_a_log(const char *string __attribute__((unused)) )
{
    my_log("this should not be a warning\n");
}

Reply via email to