Consider

#include <stdio.h>

void foo(int i)
{
        printf("Hello World %d!\n", i);
        printf(&"Hello World %d!\n"[0], i);
        printf(&"Hello World %d!\n"[6], i);
}

> g++-3.3 -c c-format.C -Wformat=2
> g++-3.4 -c c-format.C -Wformat=2
c-format.C: In function `void foo(int)':
c-format.C:6: warning: format not a string literal, argument types not checked
> g++-4.0 -c c-format.C -Wformat=2
c-format.C: In function 'void foo(int)':
c-format.C:6: warning: format not a string literal, argument types not checked
c-format.C:7: warning: format not a string literal, argument types not checked
> g++-4.1 -c c-format.C -Wformat=2
c-format.C: In function 'void foo(int)':
c-format.C:6: warning: format not a string literal, argument types not checked
c-format.C:7: warning: format not a string literal, argument types not checked

so we're getting worse here.  The problem is that c-format.c:check_format_arg
does not handle string literals of the form ADDR_EXPR (ARRAY_REF ( ... )).

This blocks changing the C frontend to emit &a[0] for array-to-pointer decay.

-- 
           Summary: [3.3 regression] -Wformat=2 incorrectly warns about
                    string literalness
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rguenth at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


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

Reply via email to