Bug 9649 - [3.3/3.4 regression] ICE in finish_member_declaration at cp/semantics.c:1850 when redeclaring a static member variable
Summary: [3.3/3.4 regression] ICE in finish_member_declaration at cp/semantics.c:1850 ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P3 normal
Target Milestone: 3.3.1
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2003-02-10 20:26 UTC by gendzwil
Modified: 2004-01-17 04:22 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-06-02 09:28:46


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gendzwil 2003-02-10 20:26:00 UTC
If you declare a static data member twice, gcc will hang while compiling.  Looks like stuck in a loop to me - top shows gcc sucking 99.9% of cpu.

aaa.h
----------
template <class R, class I> class Aaa
{
public: // methods
    Aaa() {}
    virtual ~Aaa() {}
    static int _test;
    static int _test;
};                               
template < class R, class I > int Aaa<R,I>::_test;

-----------
aab.h
-----------
#include "aaa.h"
class Aab : public Aaa< int, float >
{
public: // methods
    Aab();
    virtual ~Aab();
};

------------
aab.cpp
------------
#include "aab.h"
Aab::Aab(){} 
Aab::~Aab(){}

Release:
3.2, 3.3, 3.4 (originally reported for 2.96)

Environment:
Red Hat Linux 7.3 2.96-110

How-To-Repeat:
Compile the code included in the description:

gcc aab.cpp
Comment 1 gendzwil 2003-02-10 20:26:00 UTC
Fix:
Unknown
Comment 2 Christian Ehrhardt 2003-02-10 21:57:45 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confrimed. All supported versions fail to compile this, 3.2.2 gives
    an endless loop, 3.3 and 3.4 give an ICE at the same place. Here's 
    a minimal legal example, it is possible to remove the out of class
    definition of the static member without the ICE going away.
    ---------------- cut -----------------
    template <class R>
    struct A {
    	static int _test;
    	static int _test;
    };
    template <class R> int A<R>::_test = 0;
    struct B : public A <int> { };
    ---------------- cut -----------------
    9649.cc: In instantiation of `A<int>':
    9649.cc:7:   instantiated from here
    9649.cc:4: internal compiler error: in finish_member_declaration, at 
       cp/semantics.c:1868
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions.
Comment 3 Giovanni Bajo 2003-05-05 12:09:40 UTC
From: "Giovanni Bajo" <giovannibajo@libero.it>
To: <gcc-gnats@gcc.gnu.org>,
	<gcc-bugs@gcc.gnu.org>,
	<gendzwil@sedsystems.ca>,
	<nobody@gcc.gnu.org>,
	<gcc-prs@gcc.gnu.org>
Cc:  
Subject: Re: c++/9649: [3.3/3.4 regression] ICE in finish_member_declaration at cp/semantics.c:1850 when redeclaring a static member variable
Date: Mon, 5 May 2003 12:09:40 +0200

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9649
 
 Actually, the code is ill-formed. ยง9.2p1 states "A member shall not be
 declared twice in the member-specification, except that a nested class or
 member class template can be declared and then later defined". So, this is a
 3.3/3.4 regression because 2.95 correctly rejected the code with an error
 message.
 
 Giovanni Bajo
Comment 4 GCC Commits 2003-06-20 02:40:41 UTC
Subject: Bug 9649

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2003-06-20 02:40:37

Modified files:
	gcc/cp         : ChangeLog cp-tree.h decl.c semantics.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/g++.old-deja/g++.other: anon7.C 
Added files:
	gcc/testsuite/g++.dg/template: static4.C 

Log message:
	PR c++/9649
	* cp-tree.h (pushdecl_class_level): Change prototype.
	(push_class_level_binding): Likewise.
	* decl.c (add_binding): Reject duplicate static data members.
	(pushdecl_class_level): Return a value indicating whether or not
	the binding was valid.
	(push_class_level_binding): Likewise.
	* semantics.c (finish_member_declaration): Don't keep invalid
	declarations.
	
	PR c++/9649
	* g++.dg/template/static4.C: New test.
	* g++.old-deja/g++.other/anon7.C: Remove spurious error messages.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3440&r2=1.3441
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.857&r2=1.858
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1068&r2=1.1069
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&r1=1.311&r2=1.312
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2782&r2=1.2783
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/static4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.other/anon7.C.diff?cvsroot=gcc&r1=1.2&r2=1.3

Comment 5 GCC Commits 2003-06-20 03:06:35 UTC
Subject: Bug 9649

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	mmitchel@gcc.gnu.org	2003-06-20 03:06:32

Modified files:
	gcc/cp         : ChangeLog cp-tree.h decl.c semantics.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/g++.old-deja/g++.other: anon7.C 

Log message:
	PR c++/9649
	* cp-tree.h (pushdecl_class_level): Change prototype.
	(push_class_level_binding): Likewise.
	* decl.c (add_binding): Reject duplicate static data members.
	(pushdecl_class_level): Return a value indicating whether or not
	the binding was valid.
	(push_class_level_binding): Likewise.
	* semantics.c (finish_member_declaration): Don't keep invalid
	declarations.
	
	PR c++/9649
	* g++.dg/template/static4.C: New test.
	* g++.old-deja/g++.other/anon7.C: Remove spurious error messages.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.154&r2=1.3076.2.155
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.776.2.22&r2=1.776.2.23
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.965.2.49&r2=1.965.2.50
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.282.4.4&r2=1.282.4.5
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.192&r2=1.2261.2.193
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.other/anon7.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.1&r2=1.1.54.1

Comment 6 Mark Mitchell 2003-06-20 03:07:31 UTC
Fixed in GCC 3.3.1, GCC 3.4.