Bug 21336 - [3.4 Regression] Internal compiler error when using custom new operators
Summary: [3.4 Regression] Internal compiler error when using custom new operators
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 critical
Target Milestone: 3.4.5
Assignee: Mark Mitchell
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2005-05-02 12:03 UTC by Marc 'Foddex' Oude Kotte
Modified: 2005-06-03 16:31 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.3
Known to fail: 3.4.0 4.0.0 4.1.0
Last reconfirmed: 2005-05-02 12:21:41


Attachments
Preprocessed file (344 bytes, text/plain)
2005-05-02 12:07 UTC, Marc 'Foddex' Oude Kotte
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marc 'Foddex' Oude Kotte 2005-05-02 12:03:05 UTC
The following piece of code crashes both my custom built gcc 4.0.0 (straight
from an official mirror) and gcc 4.0.0-0.41.fc3 from Red Hat. The code is a
reconstruction of a piece of propriatary code I cannot post. 

CODE:
typedef unsigned int size_t;

class A;
class B;
class C;

template<class _T> inline void* operator new( size_t Size, _T&);
template<class _T> inline void operator delete( void*, _T&);

class Abase {};
class A : public Abase {
public:
	A() {}
	A(int a, int b, int c, int d) {}
};

class Bbase {};
class B : public Bbase {
public:
	Abase* m() {
		return new(a) A(1,2,3,4);
	}
	A a;
};

class C {
public:
	Bbase* n() {
		return new B();
	}
};

GCC OUTPUT:
main.cpp: In member function ‘Bbase* C::n()’:
main.cpp:29: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccUR3mvM.out file, please attach this to
your bugreport.

OTHER COMPILERS:
MSVC++ 7.0 compiles the code above without warnings.

gcc version 3.4.3 20050227 (Red Hat 3.4.3-22.fc3) returns this:
main.cpp: In member function `Bbase* C::n()':
main.cpp:29: error: no suitable or ambiguous `operator new' found in class `B'
Comment 1 Marc 'Foddex' Oude Kotte 2005-05-02 12:07:41 UTC
Created attachment 8793 [details]
Preprocessed file

Preprocessed file as mentioned in bug description
Comment 2 Andrew Pinski 2005-05-02 12:21:39 UTC
Confirmed, a 3.4 regression also.
Reduced testcase:
typedef __SIZE_TYPE__ size_t;
template<class _T> inline void* operator new( size_t Size, _T&);
struct B {
        int a;
        int* m() {
                return new(a) int;
        }
};
B* n() {
 return new B();
}
Comment 3 Andrew Pinski 2005-06-01 00:17:26 UTC
The ICE started
: Search converges between 2004-01-17-trunk (#438) and 2004-01-23-trunk (#439).
Comment 4 CVS Commits 2005-06-03 16:17:04 UTC
Subject: Bug 21336

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2005-06-03 16:16:47

Modified files:
	gcc/cp         : cp-tree.h decl.c pt.c ChangeLog 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: new2.C 

Log message:
	PR c++/21336
	* cp-tree.h (grok_op_properties): Remove friendp parameter.
	* decl.c (grokfndecl): Adjust call.
	(grok_op_properties): Determine the class of which the function is
	a member by looking at its DECL_CONTEXT, not current_class_type.
	* pt.c (tsubst_decl): Adjust call to grok_op_properties.
	
	PR c++/21336
	* g++.dg/template/new2.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.1139&r2=1.1140
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1402&r2=1.1403
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.1000&r2=1.1001
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4772&r2=1.4773
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5585&r2=1.5586
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/new2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 5 CVS Commits 2005-06-03 16:19:09 UTC
Subject: Bug 21336

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	mmitchel@gcc.gnu.org	2005-06-03 16:18:54

Modified files:
	gcc/cp         : cp-tree.h decl.c pt.c ChangeLog 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: new2.C 

Log message:
	PR c++/21336
	* cp-tree.h (grok_op_properties): Remove friendp parameter.
	* decl.c (grokfndecl): Adjust call.
	(grok_op_properties): Determine the class of which the function is
	a member by looking at its DECL_CONTEXT, not current_class_type.
	* pt.c (tsubst_decl): Adjust call to grok_op_properties.
	
	PR c++/21336
	* g++.dg/template/new2.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1106.2.6&r2=1.1106.2.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1371.2.13&r2=1.1371.2.14
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.978.2.11&r2=1.978.2.12
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.4648.2.55&r2=1.4648.2.56
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.221&r2=1.5084.2.222
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/new2.C.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 6 Mark Mitchell 2005-06-03 16:19:28 UTC
Fixed in 4.0, 4.1.
Comment 7 CVS Commits 2005-06-03 16:29:49 UTC
Subject: Bug 21336

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2005-06-03 16:29:36

Modified files:
	gcc/cp         : cp-tree.h decl.c pt.c ChangeLog 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: new2.C 

Log message:
	PR c++/21336
	* cp-tree.h (grok_op_properties): Remove friendp parameter.
	* decl.c (grokfndecl): Adjust call.
	(grok_op_properties): Determine the class of which the function is
	a member by looking at its DECL_CONTEXT, not current_class_type.
	* pt.c (tsubst_decl): Adjust call to grok_op_properties.
	
	PR c++/21336
	* g++.dg/template/new2.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.946.4.20&r2=1.946.4.21
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.1174.2.34&r2=1.1174.2.35
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.816.2.53&r2=1.816.2.54
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.220&r2=1.3892.2.221
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.399&r2=1.3389.2.400
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/new2.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.4.1

Comment 8 Mark Mitchell 2005-06-03 16:31:11 UTC
Fixed in 3.4.5.