Bug 12391

Summary: [3.4 regression] missing warning about assigning to an incomplete type
Product: gcc Reporter: John Levon <levon>
Component: cAssignee: Zack Weinberg <zackw>
Severity: normal CC: gcc-bugs
Priority: P2 Keywords: diagnostic, patch
Version: 3.4.0   
Target Milestone: 3.4.1   
Host: Target:
Build: Known to work: 3.3 4.0.0
Known to fail: Last reconfirmed: 2003-11-09 03:25:02

Description John Levon 2003-09-24 14:16:19 UTC

typedef struct { int a; } b_t;
int foo() { b_t d; struct b_t * c = &d; c->a; }

gcc 3.2 says :

a.c: In function `foo':
a.c:2: warning: initialization from incompatible pointer type
a.c:2: dereferencing pointer to incomplete type

GNU C version 3.4 20030914 (experimental) (i686-pc-linux-gnu) says :

a.c: In function `foo':
a.c:2: error: dereferencing pointer to incomplete type

Note the missing warning on initialisation. This can be moderately confusing
because the latter looks exactly like a "missing header" problem, but in fact
the problem is prepending the "struct" before the typedef name, which is
actually an incomplete type of "struct b_t".

The missing warning makes it obvious that it's not as simple as a missing
Comment 1 Wolfgang Bangerth 2003-09-24 18:40:23 UTC
Right, a mailine regression. What a vicious piece of code. The g++
front end gives this, btw, which I think is a good reason to change
your programming language :-)

g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -c x.c -W -Wall
x.c: In function `int foo()':
x.c:2: error: using typedef-name `b_t' after `struct'
x.c:2: warning: statement has no effect
Comment 2 Andrew Pinski 2003-12-19 05:59:59 UTC
The regresion happened between 20030830 and 20030902.
I want to say it was caused by: <http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00003.html>
Or one of these two:
2003-08-30  Zack Weinberg  <zack@codesourcery.com>

        * c-tree.h: Delete COMPARE_DIFFERENT_TU from enumeration.
        * c-typeck.c (same_translation_unit_p): New function.
        (comptypes): Use it instead of flags parameter to identify
        structure types from different translation units.
        * c-decl.c (duplicate_decls): Always call comptypes with
        COMPTYPE_STRICT flags argument.
        (c_reset_state): Set BLOCK_SUPERCONTEXT of the block formed
        to file_scope_decl.

2003-08-30  Zack Weinberg  <zack@codesourcery.com>

        * c-tree.h (C_TYPE_INCOMPLETE_VARS): New macro.
        * c-decl.c (struct c_scope): Remove "incomplete" field.
        (pushdecl): Attach variables with incomplete types to
        the TYPE_MAIN_VARIANT of the incomplete type in question.
        (finish_struct): Look at C_TYPE_INCOMPLETE_VARS for variables
        to complete, not at current_scope->incomplete.  All such
        variables do need completion.

These are the only patches which touched the c front-end which could cause this problem.
Comment 3 Mark Mitchell 2004-02-28 02:35:06 UTC
This is a very minor issue: postponed until GCC 3.4.1.
Comment 4 Zack Weinberg 2004-03-16 20:57:49 UTC
Fixed by the c-decl.c rewrite:
Comment 5 Zack Weinberg 2004-03-23 23:52:33 UTC
fixed in 3.5
Comment 6 Zack Weinberg 2004-06-01 04:25:36 UTC
Suspending bugs which could be fixed by backporting the c-decl.c rewrite to 3.4.
Comment 7 Mark Mitchell 2004-06-09 19:20:54 UTC
Fixed in 3.5, won't be fixed in 3.4.x.