I get the following segfault with gcc 4.2.0 20060419. 4.0/4.1 work. 14640:tbm@deprecation: ~] /usr/lib/gcc-snapshot/bin/g++ -c mini.c mini.c: In constructor 'refcounted<T, scalar>::refcounted(const A1&) [with A1 = ref<nfsserv>, T = nfsserv_ac]': mini.c:88: instantiated from 'void sfsserver_cache_alloc(sfsprog*, ref<nfsserv>, int, sfscd_mountarg*, ref<callback<void, const nfs_fh3*, void, void> >) [with T = server]' mini.c:102: instantiated from here mini.c:28: internal compiler error: Segmentation fault Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Created attachment 11483 [details] test case
Back trace: #0 0x001a2758 in expand_virtual_init (binfo=0xd8c0c0, decl=0xd92840) at ../../gcc/cp/init.c:781 #1 0x0019fb7c in dfs_initialize_vtbl_ptrs (binfo=0xd8c0c0, data=0xdb63c0) at ../../gcc/cp/init.c:112 #2 0x001bccd0 in dfs_walk_once_r (binfo=0xd8c0c0, pre_fn=0x19f8fc <dfs_initialize_vtbl_ptrs>, post_fn=0, data=0xdb63c0) at ../../gcc/cp/search.c:1576 #3 0x001bd3f8 in dfs_walk_once (binfo=0xd8c0c0, pre_fn=0x19f8fc <dfs_initialize_vtbl_ptrs>, post_fn=0, data=0xdb63c0) at ../../gcc/cp/search.c:1659 #4 0x0019fc74 in initialize_vtbl_ptrs (addr=0xd92840) at ../../gcc/cp/init.c:134 #5 0x001a2394 in emit_mem_initializers (mem_inits=0x0) at ../../gcc/cp/init.c:713 #6 0x001cac54 in finish_mem_initializers (mem_inits=0xdb2ae0) at ../../gcc/cp/semantics.c:1332 #7 0x000a7fb4 in tsubst_expr (t=0x434eb7c0, args=0xd8eda0, complain=tf_warning_or_error, in_decl=0xd89c40) at ../../gcc/cp/pt.c:8195
Reducing, I have it down to 43 lines.
Confirmed, reduced testcase: template < class T > struct refcounted : virtual T { template < class A1 > refcounted (const A1 & a1) : T () { } }; struct nfsserv {}; template < class T > void sfsserver_cache_alloc (int *ns) { new refcounted < nfsserv > (*ns); } void usage () { sfsserver_cache_alloc < int > ( 0); } if we change sfsserver_cache_alloc to be a non template it works. If we change the new ... to a local variable it works. if we change the argument type of sfsserver_cache_alloc to nfsserv, we get a secondary bogus error message: t.cc: In constructor 'refcounted<T>::refcounted(const A1&) [with A1 = nfsserv, T = nfsserv]': t.cc:11: instantiated from 'void sfsserver_cache_alloc(nfsserv*) [with T = int]' t.cc:16: instantiated from here t.cc:4: error: could not convert 'a1' to 'bool'
Janis, could you regression hunt on this bug? Thanks, Andrew Pinski
A regression hunt on powerpc-linux using the testcase from comment #4 identified this patch: http://gcc.gnu.org/viewcvs?view=rev&rev=112869 r112869 | mmitchel | 2006-04-11 22:59:57 +0000 (Tue, 11 Apr 2006)
Subject: Bug 27640 Author: mmitchel Date: Fri Jun 16 02:09:10 2006 New Revision: 114701 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114701 Log: PR c++/27640 * pt.c (instantiate_template): Set processing_template_decl to zero while performing substitutions. PR c++/27640 * g++.dg/template/ctor7.C: New test. Added: trunk/gcc/testsuite/g++.dg/template/ctor7.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/pt.c trunk/gcc/testsuite/ChangeLog
Fixed in 4.2.0.