From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18632 invoked by alias); 28 Feb 2006 01:01:05 -0000 Received: (qmail 18591 invoked by uid 48); 28 Feb 2006 01:00:59 -0000 Date: Tue, 28 Feb 2006 01:09:00 -0000 Subject: [Bug c/26492] New: -Wstrict-aliasing=2 warns about explicitly allowed cast to pointer to union. X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "bartoldeman at users dot sourceforge dot net" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-02/txt/msg03123.txt.bz2 List-Id: In a discussion about aliasing, some aliasing was explicitly allowed: see http://gcc.gnu.org/ml/gcc/1999-06n/msg00294.html from Mark Mitchell. quote: " extern void printf(const char*, ...); #define noalias(type, ptr) \ (((union { type __x__; __typeof__(*(ptr)) __y__;} *)(ptr))->__x__) typedef unsigned short usa[2]; int main () { int a = 0x12345678; printf ("%x\n", a); noalias(usa, &a)[1] = 0; printf ("%x\n", a); return 0; } Here's what I get: linux1.codesourcery.com% ./a.out 12345678 5678 which is I think what you expected. " This still works, but with gcc 4.0.3 and -Wstrict-aliasing=2 I see: (using #include instead of extern void printf...) $ gcc -O2 -Wstrict-aliasing=2 alias.c alias.c: In function 'main': alias.c:13: warning: dereferencing type-punned pointer might break strict-aliasing rules $ ./a.out 12345678 5678 It would be nice if the warning would not trigger in this case. Although the documentation does not say it must trigger, this is claimed to be a documented extension and should work warning-free IMHO. -- Summary: -Wstrict-aliasing=2 warns about explicitly allowed cast to pointer to union. Product: gcc Version: 4.0.3 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bartoldeman at users dot sourceforge dot net GCC build triplet: i486-linux-gnu GCC host triplet: i486-linux-gnu GCC target triplet: i486-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26492