Bug 21899 - [3.4 Regression] enum definition accepts values to be overriden
Summary: [3.4 Regression] enum definition accepts values to be overriden
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.4.4
: P2 normal
Target Milestone: 3.4.5
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
: 23580 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-06-03 14:04 UTC by Giambattista Bloisi
Modified: 2005-08-26 17:40 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.3 4.0.0 4.1.0
Known to fail: 3.4.0
Last reconfirmed: 2005-06-03 14:10:08


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Giambattista Bloisi 2005-06-03 14:04:04 UTC
The code below with gcc compiles and the exe prints "Value: 3".
With g++, instead, the compilation fails with the following error:
main.c:7: error: redefinition of `A'
main.c:4: error: `A' previously defined here

Regards,
Giambattista Bloisi

----
#include <stdio.h>

typedef enum {
        A = 1,
        B = 2,
        A
} myenum;

int main() {
        myenum a = A;

        printf("Value: %d\n", (int)a);
return 0;
}
Comment 1 Andrew Pinski 2005-06-03 14:10:08 UTC
Confirmed, only a 3.4 regression.
Started to work on the mainline:
: Search converges between 2004-09-24-014001-trunk (#558) and 2004-09-24-161002-trunk 
(#559).

Started to fail:
: Search converges between 2004-01-01-trunk (#437) and 2004-01-17-trunk (#438).
Comment 2 jsm-csl@polyomino.org.uk 2005-06-03 16:03:21 UTC
Subject: Re:  [3.4 Regression] enum definition accepts values
 to be overriden

On Fri, 3 Jun 2005, pinskia at gcc dot gnu dot org wrote:

> Confirmed, only a 3.4 regression.
> Started to work on the mainline:
> : Search converges between 2004-09-24-014001-trunk (#558) and 2004-09-24-161002-trunk 
> (#559).

I.e., fixed by my fix for bug 17188 
<http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02566.html>.  This patch is 
probably safe to backport to 3.4 branch.

Comment 3 GCC Commits 2005-07-28 23:02:46 UTC
Subject: Bug 21899

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	jsm28@gcc.gnu.org	2005-07-28 23:01:31

Modified files:
	gcc            : ChangeLog c-decl.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/gcc.dg: decl-3.c 
Added files:
	gcc/testsuite/gcc.dg: nested-redef-1.c pr17188-1.c 

Log message:
	PR c/17188
	PR c/21899
	* c-decl.c (diagnose_mismatched_decls): Check for duplicate
	declarations of enumerators.
	(start_struct): Check TYPE_SIZE rather than TYPE_FIELDS to check
	for redefinition.  Check for nested redefinition.
	(finish_struct): Don't check for nested redefinition.
	(start_enum): Check for nested redefinition.
	
	testsuite:
	* gcc.dg/nested-redef-1.c, gcc.dg/pr17188-1.c: New tests.
	* gcc.dg/decl-3.c: Adjust expected message.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.889&r2=2.2326.2.890
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.470.4.20&r2=1.470.4.21
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.414&r2=1.3389.2.415
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/nested-redef-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.60.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr17188-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.60.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/decl-3.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.2&r2=1.2.4.1

Comment 4 Joseph S. Myers 2005-07-28 23:09:14 UTC
Fixed on 3.4 branch by backporting patch.
Comment 5 Andrew Pinski 2005-08-26 17:40:18 UTC
*** Bug 23580 has been marked as a duplicate of this bug. ***