public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/35593]  New: spurious warning "array subscript is below array bounds" with void* function argument plus -O2
@ 2008-03-14 20:11 niemayer at isg dot de
  2008-03-14 22:45 ` [Bug middle-end/35593] [4.3 Regression] " rguenth at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: niemayer at isg dot de @ 2008-03-14 20:11 UTC (permalink / raw)
  To: gcc-bugs

When compiling the following tiny example .cxx source with "-Wall -O2", I get
spurious warnings:

------------- cut example test.cxx here --------------
extern void function(void * x);

struct A {
        long x;
        char d[0];
};


void test(A * a) {
        function((char *)a - 4); // gcc emits warning, here - why?
}

// ------------

struct B {
        char d[0];
};

void test(B * b) {
        char * c = (char *)b;
        void * v = c-1;
        function(v);  // gcc emits warning, here - why?
}
------------- cut here --------------

The output of
> gcc -Wall -c test.cxx -O2
is:
/tmp/test.cxx: In function ‘void test(B*)’:
/tmp/test.cxx:22: warning: array subscript is below array bounds
/tmp/test.cxx: In function ‘void test(A*)’:
/tmp/test.cxx:10: warning: array subscript is below array bounds

I have not found a sane way in my non-example, real-world code to avoid those
warnings.


-- 
           Summary: spurious warning "array subscript is below array bounds"
                    with void* function argument plus -O2
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: niemayer at isg dot de
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-06-03  5:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-14 20:11 [Bug c++/35593] New: spurious warning "array subscript is below array bounds" with void* function argument plus -O2 niemayer at isg dot de
2008-03-14 22:45 ` [Bug middle-end/35593] [4.3 Regression] " rguenth at gcc dot gnu dot org
2008-03-14 22:45 ` rguenth at gcc dot gnu dot org
2008-03-15 14:29 ` rguenth at gcc dot gnu dot org
2008-03-15 16:10 ` rguenth at gcc dot gnu dot org
2008-03-15 19:15 ` rguenth at gcc dot gnu dot org
2008-03-18 17:25 ` rguenth at gcc dot gnu dot org
2008-03-18 17:28 ` rguenth at gcc dot gnu dot org
2009-06-03  5:07 ` at dot wufei at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).