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/22476] New: -Wmissing-format-attribute should pick out function pointer candidates also


Currently the -Wmissing-format-attribute works on functions by examining the 
current function body for calls to vprintf-like functions and if so it flags 
the current function as a candidate for another format attribute.  You can then 
back-track to callees and propagate the attribute as necessary by recompiling 
the code with the new attribute added.  This works fine for functions, but 
doesn't pick up function pointers.  For example:

#include <stdio.h>
int (*ptr)(const char *, ...);

int main()
{
  ptr = printf;
  ptr("hello world %d\n", 5L);

  return 0;
}

This code compiled with -Wall -Wmissing-format-attribute doesn't yield any 
warnings because there's no format attribute on the function pointer 'ptr' to 
complain about the int vs. long mismatch, and the missing format attribute 
detection doesn't catch that that the attribute is missing.

However in the assignment 'ptr = printf' we should be able to detect that both 
operands are indeed variable argument functions (or function pointers) and that 
the right-hand side has a format attribute whereas the left-hand side doesn't.  
This should trigger the missing format attribute diagnostic.

Beyond printf, we should do the same for vprintf-like functions as well.

-- 
           Summary: -Wmissing-format-attribute should pick out function
                    pointer candidates also
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ghazi at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


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


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