Bug 49507 - [4.6/4.7 Regression] ICE because of defaulted template destructor
Summary: [4.6/4.7 Regression] ICE because of defaulted template destructor
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.1
: P3 normal
Target Milestone: 4.6.1
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-22 21:02 UTC by Philipp
Modified: 2011-06-24 19:55 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-06-23 09:50:47


Attachments
fix (693 bytes, patch)
2011-06-23 15:10 UTC, Jason Merrill
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philipp 2011-06-22 21:02:32 UTC
The following code makes rc1 of gcc-4.6.1 segfault:

template<typename T>
struct ConcretePoolKey
{
        virtual ~ConcretePoolKey();
};

template<typename T>
ConcretePoolKey<T>::~ConcretePoolKey() = default;

int main()
{
        ConcretePoolKey<int> foo;
}


/usr/bin/g++ -std=c++0x test.cpp
test.cpp: In destructor 'ConcretePoolKey<T>::~ConcretePoolKey() [with T = int]':
test.cpp:13:1:   instantiated from here
test.cpp:2:8: internal compiler error: Segmentation fault
Comment 1 Jakub Jelinek 2011-06-23 09:50:47 UTC
Indeed, a regression from 4.6.0, caused by PR47544 fix
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174071
on the trunk and
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174159
on 4.6 branch.

#0  0x00000000006f972a in initialize_vtbl_ptrs (addr=0x0) at ../../gcc/cp/init.c:120
#1  0x000000000051f017 in begin_destructor_body () at ../../gcc/cp/decl.c:13001
#2  0x00000000005201f5 in begin_function_body () at ../../gcc/cp/decl.c:13090
#3  0x0000000000716b58 in synthesize_method (fndecl=0x7ffff1a1be00) at ../../gcc/cp/method.c:741
#4  0x00000000005c8d63 in instantiate_decl (d=0x7ffff1a1be00, defer_ok=0, expl_inst_class_mem_p=0 '\000') at ../../gcc/cp/pt.c:17738
#5  0x00000000005c9b94 in instantiate_pending_templates (retries=1) at ../../gcc/cp/pt.c:17884
#6  0x0000000000647e2c in cp_write_global_declarations () at ../../gcc/cp/decl2.c:3719

ICEs because current_class_ptr is NULL.  Jason, as this is a regression from 4.6.0, it might be desirable to fix it for 4.6.1 instead of deferring for 4.6.2.
Comment 2 Jason Merrill 2011-06-23 14:28:00 UTC
For 4.6.1 let's just revert r174159.  Will you do that or shall I?
Comment 3 Jason Merrill 2011-06-23 15:10:01 UTC
Created attachment 24586 [details]
fix

Actually, this patch seems safe enough for 4.6.1.  Testing now.
Comment 4 Jason Merrill 2011-06-23 16:53:06 UTC
Author: jason
Date: Thu Jun 23 16:53:03 2011
New Revision: 175342

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175342
Log:
	PR c++/49507
	* decl2.c (mark_used): Don't call synthesize_method for
	functions defaulted outside the class.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/defaulted30.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl2.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Jason Merrill 2011-06-23 16:56:31 UTC
Author: jason
Date: Thu Jun 23 16:56:27 2011
New Revision: 175343

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175343
Log:
	PR c++/49507
	* decl2.c (mark_used): Don't call synthesize_method for
	functions defaulted outside the class.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/defaulted30.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/decl2.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 6 Philipp 2011-06-24 10:26:06 UTC
Applying the changes on top of gcc-4.6.1 rc1 fixes the problem for me.
Thanks!
Comment 7 Jakub Jelinek 2011-06-24 19:55:26 UTC
Fixed.