Bug 35828 - [C++0x] ICE on default template template parameter in template function
Summary: [C++0x] ICE on default template template parameter in template function
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.0
: P3 major
Target Milestone: 4.4.1
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, monitored
: 39822 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-04-04 21:28 UTC by Colin Hirsch
Modified: 2009-07-07 22:16 UTC (History)
4 users (show)

See Also:
Host: i386-apple-darwin9.2.0
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-12-28 22:11:55


Attachments
The file that triggered the ICE (preprocessed). (127.24 KB, text/plain)
2008-04-04 21:30 UTC, Colin Hirsch
Details
Here's the preprocessed source for a similar bug that might be related. (129.21 KB, text/plain)
2008-04-08 08:31 UTC, Colin Hirsch
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Colin Hirsch 2008-04-04 21:28:39 UTC
Just got an ICE while compiling some template-heavy C++ code; as shown below, the error is reported in parse_debug.hh, however the last change to the code, the one that triggered the ICE, was in parse_printer.hh (I split class printer into two classes, printer and printer_impl). I'll add the preprocessed file in a separate comment/file.

> uname -a
Darwin tigger.local 9.2.2 Darwin Kernel Version 9.2.2: Tue Mar  4 21:17:34 PST 2008; root:xnu-1228.4.31~1/RELEASE_I386 i386 i386 MacBookPro3,1 Darwin

> g++-mp-4.3 -v
Using built-in specs.
Target: i386-apple-darwin9.2.0
Configured with: ../gcc-4.3.0/configure --prefix=/opt/macports-1.6.0 --enable-languages=c,c++,objc,obj-c++,java,fortran --libdir=/opt/macports-1.6.0/lib/gcc43 --includedir=/opt/macports-1.6.0/include/gcc43 --infodir=/opt/macports-1.6.0/share/info --mandir=/opt/macports-1.6.0/share/man --with-local-prefix=/opt/macports-1.6.0 --with-system-zlib --disable-nls --program-suffix=-mp-4.3 --with-gxx-include-dir=/opt/macports-1.6.0/include/gcc43/c++/ --with-gmp=/opt/macports-1.6.0 --with-mpfr=/opt/macports-1.6.0
Thread model: posix
gcc version 4.3.0 (GCC) 

> g++-mp-4.3 -I. -std=gnu++0x -D_REENTRANT -pipe -O3 -Wall -Wextra -Wimplicit -Wconversion -Wcast-align -Woverloaded-virtual -Wold-style-cast -Wformat=2 -Wswitch-enum -Wswitch-default -Wredundant-decls -fno-enforce-eh-specs -fno-strict-overflow -lpthread calculator.cc -o calculator
./parse_debug.hh: In function 'int main(int, char**)':
./parse_debug.hh:101: internal compiler error: Bus error
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 Colin Hirsch 2008-04-04 21:30:32 UTC
Created attachment 15430 [details]
The file that triggered the ICE (preprocessed).
Comment 2 Colin Hirsch 2008-04-04 21:44:13 UTC
Looking for a workaround I noticed that the ICE might actually be in connection with the template template arguments of the overloaded functions pegtl::parse() ... it's the only place where template template arguments were used, I had introduced them shortly before the ICE, and the ICE only went away after I removed them...

Comment 3 Colin Hirsch 2008-04-08 08:31:46 UTC
Created attachment 15445 [details]
Here's the preprocessed source for a similar bug that might be related.

> g++-mp-4.3 -save-temps -I. -std=gnu++0x -D_REENTRANT -pipe -g -O3 -Wall -Wextra -Wimplicit -Wconversion -Wcast-align -Woverloaded-virtual -Wold-style-cast -Wformat=2 -Wswitch-enum -Wswitch-default -Wredundant-decls -fno-enforce-eh-specs -fno-strict-overflow -lpthread scheme.cc -o scheme
g++-mp-4.3: warning: -pipe ignored because -save-temps specified
./rules_generic.hh: In instantiation of 'pegtl::seq_min_impl1<pegtl::type_list<scheme::nested_comment>, scheme::comment_text>':
./rules_generic.hh:199:   instantiated from 'const size_t pegtl::seq_min_impl2<false, pegtl::type_list<>, scheme::nested_comment, scheme::comment_text>::min'
./rules_generic.hh:211:   instantiated from 'const size_t pegtl::seq_min_impl1<pegtl::type_list<scheme::nested_comment>, scheme::comment_text>::min'
./rules_generic.hh:223:   instantiated from 'const size_t pegtl::seq<scheme::nested_comment, scheme::comment_text>::min'
./rules_generic.hh:104:   instantiated from 'pegtl::star<scheme::comment_cont>'
./parse_debugger.hh:214:   instantiated from 'bool pegtl::trace_debug::match(Input&, Class&& ...) [with Rule = pegtl::star<scheme::comment_cont>, Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Class = ]'
./rules_generic.hh:242:   instantiated from 'static bool pegtl::seq<Rule, Rules ...>::s_match(Input&, Debug&, Class&& ...) [with Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Debug = pegtl::trace_debug, Class = , Rule = pegtl::star<scheme::comment_cont>, Rules = pegtl::string<124, 35>]'
./rules_generic.hh:242:   instantiated from 'static bool pegtl::seq<Rule, Rules ...>::s_match(Input&, Debug&, Class&& ...) [with Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Debug = pegtl::trace_debug, Class = , Rule = scheme::comment_text, Rules = pegtl::star<scheme::comment_cont>, pegtl::string<124, 35>]'
./parse_debugger.hh:214:   instantiated from 'bool pegtl::trace_debug::match(Input&, Class&& ...) [with Rule = pegtl::seq<scheme::comment_text, pegtl::star<scheme::comment_cont>, pegtl::string<124, 35> >, Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Class = ]'
./rules_generic.hh:242:   instantiated from 'static bool pegtl::seq<Rule, Rules ...>::s_match(Input&, Debug&, Class&& ...) [with Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Debug = pegtl::trace_debug, Class = , Rule = pegtl::seq<scheme::comment_text, pegtl::star<scheme::comment_cont>, pegtl::string<124, 35> >, Rules = ]'
./rules_generic.hh:242:   instantiated from 'static bool pegtl::seq<Rule, Rules ...>::s_match(Input&, Debug&, Class&& ...) [with Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Debug = pegtl::trace_debug, Class = , Rule = pegtl::string<35, 124>, Rules = pegtl::seq<scheme::comment_text, pegtl::star<scheme::comment_cont>, pegtl::string<124, 35> >]'
./parse_debugger.hh:227:   instantiated from 'bool pegtl::trace_debug::match(bool, Input&, Class&& ...) [with Rule = scheme::nested_comment, Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Class = ]'
./rules_generic.hh:183:   instantiated from 'static bool pegtl::sor<Rule, Rules ...>::s_match(Input&, Debug&, Class&& ...) [with Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Debug = pegtl::trace_debug, Class = , Rule = scheme::nested_comment, Rules = pegtl::seq<pegtl::string<35, 59>, scheme::interlexeme_space, scheme::datum>, pegtl::string<35, 33, 114, 54, 114, 115>]'
./rules_generic.hh:183:   instantiated from 'static bool pegtl::sor<Rule, Rules ...>::s_match(Input&, Debug&, Class&& ...) [with Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Debug = pegtl::trace_debug, Class = , Rule = pegtl::seq<pegtl::one<59>, pegtl::until_eol>, Rules = scheme::nested_comment, pegtl::seq<pegtl::string<35, 59>, scheme::interlexeme_space, scheme::datum>, pegtl::string<35, 33, 114, 54, 114, 115>]'
./parse_debugger.hh:227:   instantiated from 'bool pegtl::trace_debug::match(bool, Input&, Class&& ...) [with Rule = scheme::comment, Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Class = ]'
./rules_generic.hh:183:   instantiated from 'static bool pegtl::sor<Rule, Rules ...>::s_match(Input&, Debug&, Class&& ...) [with Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Debug = pegtl::trace_debug, Class = , Rule = scheme::comment, Rules = ]'
./rules_generic.hh:183:   instantiated from 'static bool pegtl::sor<Rule, Rules ...>::s_match(Input&, Debug&, Class&& ...) [with Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Debug = pegtl::trace_debug, Class = , Rule = scheme::whitespace, Rules = scheme::comment]'
./parse_debugger.hh:227:   instantiated from 'bool pegtl::trace_debug::match(bool, Input&, Class&& ...) [with Rule = scheme::interlexeme_space, Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Class = ]'
./rules_generic.hh:124:   instantiated from 'static bool pegtl::star<Rule>::s_match(Input&, Debug&, Class&& ...) [with Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Debug = pegtl::trace_debug, Class = , Rule = scheme::interlexeme_space]'
./parse_debugger.hh:214:   instantiated from 'bool pegtl::trace_debug::match(Input&, Class&& ...) [with Rule = pegtl::star<scheme::interlexeme_space>, Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Class = ]'
./rules_generic.hh:242:   instantiated from 'static bool pegtl::seq<Rule, Rules ...>::s_match(Input&, Debug&, Class&& ...) [with Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Debug = pegtl::trace_debug, Class = , Rule = pegtl::star<scheme::interlexeme_space>, Rules = pegtl::seq<pegtl::seq<pegtl::one<35>, pegtl::list<116, 84, 102, 70> >, pegtl::at<scheme::delimiter> >, pegtl::star<scheme::interlexeme_space>]'
./parse_debugger.hh:227:   instantiated from 'bool pegtl::trace_debug::match(bool, Input&, Class&& ...) [with Rule = scheme::boolean, Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Class = ]'
./rules_generic.hh:183:   instantiated from 'static bool pegtl::sor<Rule, Rules ...>::s_match(Input&, Debug&, Class&& ...) [with Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Debug = pegtl::trace_debug, Class = , Rule = scheme::boolean, Rules = scheme::number, scheme::character, scheme::string, scheme::symbol]'
./parse_debugger.hh:227:   instantiated from 'bool pegtl::trace_debug::match(bool, Input&, Class&& ...) [with Rule = scheme::lexeme_datum, Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Class = ]'
./rules_generic.hh:183:   instantiated from 'static bool pegtl::sor<Rule, Rules ...>::s_match(Input&, Debug&, Class&& ...) [with Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Debug = pegtl::trace_debug, Class = , Rule = scheme::lexeme_datum, Rules = scheme::compound_datum]'
./parse_debugger.hh:227:   instantiated from 'bool pegtl::trace_debug::match(bool, Input&, Class&& ...) [with Rule = scheme::datum, Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Class = ]'
./parse_generic.hh:18:   instantiated from 'bool pegtl::parse(Input&, Debug&, Class&& ...) [with TopRule = scheme::datum, Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Debug = pegtl::trace_debug, Class = ]'
./parse_generic.hh:46:   instantiated from 'bool pegtl::trace_parse(bool, Input&, Class&& ...) [with TopRule = scheme::datum, Input = pegtl::iterator_input<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, pegtl::ascii_location>, Class = ]'
./parse_string.hh:47:   instantiated from 'bool pegtl::trace_parse_file(bool, const std::string&, Class&& ...) [with TopRule = scheme::datum, Location = pegtl::ascii_location, Class = ]'
scheme.cc:295:   instantiated from here
./rules_generic.hh:211: internal compiler error: in finish_member_declaration, at cp/semantics.c:2319
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 4 Colin Hirsch 2008-04-08 10:55:57 UTC
The second example could be related with a recursive template, more precisely the templates seq_min_impl1 and seq_min_impl2 together perform a template meta-programming "recursive walk" of a template structure, in order to define their respective "const static size_t min" members.

In the second example the template structure is recursive, i.e. while trying to determine seq_min_impl1< ... >::min for some template parameters the compiler will reach a point where that value, through some steps, depends on itself.

(The meta-programming in the code included is a first step towards eliminating the recursion.)

In other words: If my current understanding of my code is correct, the ICE from scheme.ii should be an error message.

Comment 5 Volker Reichelt 2008-12-28 22:11:55 UTC
Confirmed. Reduced testcase for comment #1:

=====================================================================
template<typename> struct A;

template<typename, template<typename> class = A> void foo();

void bar()
{
  foo<int>();
}
=====================================================================

bug.cc: In function 'void bar()':
bug.cc:1: internal compiler error: Segmentation fault
Please submit a full bug report, [etc.]


Removing the first template parameter yields a different error:

=====================================================================
template<typename> struct A;

template<template<typename> class = A> void foo();

void bar()
{
  foo();
}
=====================================================================

bug.cc: In function 'void bar()':
bug.cc:1: internal compiler error: in tsubst_decl, at cp/pt.c:7958
Please submit a full bug report, [etc.]
Comment 6 Andreas Beckmann 2009-04-20 17:51:03 UTC
I stumbled across this ICE on a very similar testcase (on 4.3.4, 4.4.0, 4.5.0):

---------- 8< ----------
template < typename > struct A ;
template < template < typename > class = A >
void test ()
{
        test ();
}
---------- >8 ----------

=========== 4.4.0 ==========
$ x86_64-linux-gnu-g++-4.4.x -v -std=c++0x -c ice-in-tsubst_decl-cp_pt_c_8101.min.ii

Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4_4-branch/configure --prefix=/opt/software/gcc-x86_64/gcc-4.4.x --program-suffix=-4.4.x --enable-languages=c,c++ --enable-checking
Thread model: posix
gcc version 4.4.0 20090413 (prerelease) (GCC)
COLLECT_GCC_OPTIONS='-v' '-std=c++0x' '-c' '-shared-libgcc' '-mtune=generic'
 /opt/software/gcc-x86_64/gcc-4.4.x/libexec/gcc/x86_64-unknown-linux-gnu/4.4.0/cc1plus -fpreprocessed ice-in-tsubst_decl-cp_pt_c_8101.min.ii -quiet -dumpbase ice-in-tsubst_decl-cp_pt_c_8101.min.ii -mtune=generic -auxbase ice-in-tsubst_decl-cp_pt_c_8101.min -std=c++0x -version -o /tmp/ccAHdc5J.s
GNU C++ (GCC) version 4.4.0 20090413 (prerelease) (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.4.0 20090413 (prerelease), GMP version 4.2.2, MPFR version 2.3.1.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 4c95a5cf24794a394976148039ecc611
ice-in-tsubst_decl-cp_pt_c_8101.min.ii: In function ‘void test()’:
ice-in-tsubst_decl-cp_pt_c_8101.min.ii:1: internal compiler error: in tsubst_decl, at cp/pt.c:8101
===========================

I also got the segmentation fault on this similar testcase, reported as bug #39822 before seeing this report:

---------- 8< ----------
template < typename >
struct A ;
template < typename X, template < typename > class = A >
void test ( X )
{
        A < int > T ;
        test ( T ) ;
}
---------- >8 ----------
Comment 7 Andrew Pinski 2009-04-22 23:55:34 UTC
*** Bug 39822 has been marked as a duplicate of this bug. ***
Comment 8 Jason Merrill 2009-07-07 22:04:04 UTC
Subject: Bug 35828

Author: jason
Date: Tue Jul  7 22:03:42 2009
New Revision: 149351

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149351
Log:
	PR c++/35828
	* pt.c (tsubst_decl): Don't abort if we didn't change anything
	in a TEMPLATE_DECL's args.

Added:
    trunk/gcc/testsuite/g++.dg/template/defarg12.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog

Comment 9 Jason Merrill 2009-07-07 22:11:43 UTC
Subject: Bug 35828

Author: jason
Date: Tue Jul  7 22:11:31 2009
New Revision: 149353

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149353
Log:
	PR c++/35828
	* pt.c (tsubst_decl): Don't abort if we didn't change anything
	in a TEMPLATE_DECL's args.


Added:
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/defarg12.C
      - copied unchanged from r149351, trunk/gcc/testsuite/g++.dg/template/defarg12.C
Modified:
    branches/gcc-4_4-branch/gcc/   (props changed)
    branches/gcc-4_4-branch/gcc/ChangeLog-2008   (props changed)
    branches/gcc-4_4-branch/gcc/cp/ChangeLog
    branches/gcc-4_4-branch/gcc/cp/ChangeLog-2007   (props changed)
    branches/gcc-4_4-branch/gcc/cp/ChangeLog-2008   (props changed)
    branches/gcc-4_4-branch/gcc/cp/pt.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog-2008   (props changed)
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/   (props changed)
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/cpp0x/decltype-38655.C   (props changed)
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/torture/pr36227.c   (props changed)
    branches/gcc-4_4-branch/gcc/testsuite/gcc.target/x86_64/abi/callabi/   (props changed)

Propchange: branches/gcc-4_4-branch/gcc/
            ('svn:mergeinfo' modified)

Propchange: branches/gcc-4_4-branch/gcc/ChangeLog-2008
            ('svn:mergeinfo' modified)

Propchange: branches/gcc-4_4-branch/gcc/cp/ChangeLog-2007
            ('svn:mergeinfo' modified)

Propchange: branches/gcc-4_4-branch/gcc/cp/ChangeLog-2008
            ('svn:mergeinfo' modified)

Propchange: branches/gcc-4_4-branch/gcc/testsuite/ChangeLog-2008
            ('svn:mergeinfo' modified)

Propchange: branches/gcc-4_4-branch/gcc/testsuite/g++.dg/
            ('svn:mergeinfo' modified)

Propchange: branches/gcc-4_4-branch/gcc/testsuite/g++.dg/cpp0x/decltype-38655.C
            ('svn:mergeinfo' modified)

Propchange: branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/torture/pr36227.c
            ('svn:mergeinfo' modified)

Propchange: branches/gcc-4_4-branch/gcc/testsuite/gcc.target/x86_64/abi/callabi/
            ('svn:mergeinfo' modified)


Comment 10 Jason Merrill 2009-07-07 22:16:10 UTC
Fixed for 4.4.1.