From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12115 invoked by alias); 14 Mar 2008 20:11:52 -0000 Received: (qmail 11998 invoked by uid 48); 14 Mar 2008 20:11:09 -0000 Date: Fri, 14 Mar 2008 20:11:00 -0000 Subject: [Bug c++/35593] New: spurious warning "array subscript is below array bounds" with void* function argument plus -O2 X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "niemayer at isg dot de" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-03/txt/msg01183.txt.bz2 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