Bug 21509 - [4.0 regression] -Wformat=2 incorrectly warns about string literalness
Summary: [4.0 regression] -Wformat=2 incorrectly warns about string literalness
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.4
: P2 normal
Target Milestone: 4.0.4
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: diagnostic, patch
Depends on:
Blocks:
 
Reported: 2005-05-11 09:53 UTC by Richard Biener
Modified: 2007-01-18 04:10 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.3 4.1.0 4.1.1 4.1.2 4.2.0
Known to fail: 3.4.0 4.0.0
Last reconfirmed: 2005-12-27 00:26:10


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2005-05-11 09:53:25 UTC
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.
Comment 1 Andrew Pinski 2005-05-11 10:48:40 UTC
Confirmed.
Comment 2 Andrew Pinski 2005-05-11 11:19:41 UTC
Patch posted here: <http://gcc.gnu.org/ml/gcc-patches/2005-05/msg00978.html>.
Comment 3 Richard Biener 2005-05-15 20:59:26 UTC
Fixed on mainline.
Comment 4 Andrew Pinski 2005-07-22 21:12:24 UTC
Moving to 4.0.2 pre Mark.
Comment 5 Gabriel Dos Reis 2007-01-18 04:10:10 UTC
Works in GCC-4.1.x and higher.
won't fix in GCC-4.0.x