Compiling the source code static const struct { int aMember; } *const aPointer = 0; int main() { int anInt = (aPointer == 0) ? 0 : aPointer->aMember; return 0; } with the command line gcc -o prog -O prog.c generates the following error output: testgcc.c: In function `main': testgcc.c:15: error: request for member `aMember' in something not a structure or union This does not happen if the -O switch is omitted. This behaviour does not occur with gcc 2.95.3 (the only other Solaris version I have to hand).
Confirmed with 3.3 branch and mainline. This is indeed a regression since 2.95.3. It does however fail with 3.0.4 and newer, so it's not a very new one.
Fold is folding something but not keeping the type around.
Fixing.
Subject: Bug 13382 CVSROOT: /cvs/gcc Module name: gcc Changes by: ebotcazou@gcc.gnu.org 2003-12-23 05:26:41 Modified files: gcc : ChangeLog c-typeck.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: null-pointer-1.c Log message: PR c/13382 * c-typeck.c (convert_for_assignment): When converting from integral type to pointer type, always call convert. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.2080&r2=2.2081 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.266&r2=1.267 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3302&r2=1.3303 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/null-pointer-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 13382 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: ebotcazou@gcc.gnu.org 2003-12-23 06:23:37 Modified files: gcc : ChangeLog c-typeck.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: null-pointer-1.c Log message: PR c/13382 * c-typeck.c (convert_for_assignment): When converting from integral type to pointer type, always call convert. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.855&r2=1.16114.2.856 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.213.2.10&r2=1.213.2.11 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.343&r2=1.2261.2.344 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/null-pointer-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1
See http://gcc.gnu.org/ml/gcc-patches/2003-12/msg01851.html