Bug 15329 - [3.4/4.0 Regression] ICE on constructor of member template
Summary: [3.4/4.0 Regression] ICE on constructor of member template
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 3.4.1
Assignee: Mark Mitchell
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2004-05-06 18:36 UTC by Rob Peters
Modified: 2004-10-30 21:11 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 3.3.3
Known to fail: 3.4.0 4.0.0
Last reconfirmed: 2004-05-06 18:48:11


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Peters 2004-05-06 18:36:02 UTC
This code produces an ICE with g++-3.4.0

class Canvas
{
public:
  typedef void (Canvas::* Manip)();

  template <Manip doit>
  class Saver
  {
  public:
    Saver(Canvas& canvas) :
      itsCanvas(canvas)
    {
      (itsCanvas.*doit)(); // ICE occurs here; no ICE if 'canvas' is used
instead of 'itsCanvas'
    }

  private:
    Canvas& itsCanvas;
  };
};


Specs:
[sideswipe 18:20 52]$ /usr/local/gcc-3.4.0/bin/g++ -v
Reading specs from /usr/local/gcc-3.4.0/lib/gcc/i686-pc-linux-gnu/3.4.0/specs
Configured with: /home/rjpeters/build/gcc-3.4.0/configure
--prefix=/usr/local/gcc-3.4.0 --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
Thread model: posix
gcc version 3.4.0

There is no ICE with g++-3.3.2 for the same code and as far as I can recall
there has been no problem with this same code as I upgraded through all
successive versions including 3.1.x, 3.2.x, and 3.3.x.

There is no ICE if the problem line uses the function argument 'canvas' rather
than the member variable 'itsCanvas' as the callee of the ptr-to-memfunc.

There is no ICE if the problem line is changed to a direct member-function call
rather than a call through a ptr-to-memfunc and in this case the nested class is
not a template class:

class Canvas
{
public:
  void foo();

  class Saver
  {
  public:
    Saver(Canvas& canvas) :
      itsCanvas(canvas)
    {
      itsCanvas.foo(); // no ICE here in this case
    }

  private:
    Canvas& itsCanvas;
  };
};

-Rob Peters
Comment 1 Andrew Pinski 2004-05-06 18:48:08 UTC
Confirmed.
Here is the backtrace:
#0  size_binop (code=TRUNC_DIV_EXPR, arg0=0x0, arg1=0x4004e8ac) at /home/gates/pinskia/src/
gnu/gcc/src/gcc/fold-const.c:1641
#1  0x083b7e22 in byte_from_pos (offset=0x0, bitpos=0x0) at /home/gates/pinskia/src/gnu/gcc/src/
gcc/stor-layout.c:632
#2  0x083c75c1 in byte_position (field=0x4012b4a4) at /home/gates/pinskia/src/gnu/gcc/src/gcc/
tree.c:1194
#3  0x08101388 in build_unary_op (code=ADDR_EXPR, xarg=0x4005d0d8, noconvert=0) at /home/
gates/pinskia/src/gnu/gcc/src/gcc/cp/typeck.c:4097
#4  0x080d6f2f in build_offset_ref_call_from_tree (fn=0x4005d108, args=0x0) at /home/gates/
pinskia/src/gnu/gcc/src/gcc/cp/decl2.c:2942
#5  0x080f0af2 in cp_parser_unary_expression (parser=0x4012ac40, address_p=false) at /home/
gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:3864
#6  0x080e7704 in cp_parser_binary_expression (parser=0x4012ac40, token_tree_map=0x849ee20, 
fn=0x80f10e0 <cp_parser_simple_cast_expression>)
    at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:13972
#7  0x080e7704 in cp_parser_binary_expression (parser=0x4012ac40, token_tree_map=0x849ee10, 
fn=0x80e78d0 <cp_parser_pm_expression>)
    at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:13972
#8  0x080e7704 in cp_parser_binary_expression (parser=0x4012ac40, token_tree_map=0x849ee04, 
fn=0x80e78b0 <cp_parser_multiplicative_expression>)
    at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:13972
#9  0x080e7704 in cp_parser_binary_expression (parser=0x4012ac40, token_tree_map=0x849edf8, 
fn=0x80e7890 <cp_parser_additive_expression>)
    at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:13972
#10 0x080e7704 in cp_parser_binary_expression (parser=0x4012ac40, token_tree_map=0x849eddc, 
fn=0x80e7870 <cp_parser_shift_expression>)
    at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:13972
#11 0x080e7704 in cp_parser_binary_expression (parser=0x4012ac40, token_tree_map=0x849edd0, 
fn=0x80e7850 <cp_parser_relational_expression>)
    at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:13972
#12 0x080e7704 in cp_parser_binary_expression (parser=0x4012ac40, token_tree_map=0x849edc8, 
fn=0x80e7830 <cp_parser_equality_expression>)
    at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:13972
#13 0x080e7704 in cp_parser_binary_expression (parser=0x4012ac40, token_tree_map=0x849edc0, 
fn=0x80e7810 <cp_parser_and_expression>)
    at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:13972
#14 0x080e7704 in cp_parser_binary_expression (parser=0x4012ac40, token_tree_map=0x849edb8, 
fn=0x80e77f0 <cp_parser_exclusive_or_expression>)
    at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:13972
#15 0x080e7704 in cp_parser_binary_expression (parser=0x4012ac40, token_tree_map=0x849edb0, 
fn=0x80e77d0 <cp_parser_inclusive_or_expression>)
    at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:13972
#16 0x080e7704 in cp_parser_binary_expression (parser=0x4012ac40, token_tree_map=0x849efc4, 
fn=0x80e77b0 <cp_parser_logical_and_expression>)
    at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:13972
#17 0x080e8703 in cp_parser_assignment_expression (parser=0x4012ac40) at /home/gates/pinskia/
src/gnu/gcc/src/gcc/cp/parser.c:5151
#18 0x080e8ec7 in cp_parser_expression (parser=0x4012ac40) at /home/gates/pinskia/src/gnu/gcc/
src/gcc/cp/parser.c:5366
#19 0x080e904c in cp_parser_expression_statement (parser=0x4012ac40, in_statement_expr_p=false) 
at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:5670
#20 0x080ec90a in cp_parser_statement (parser=0x4012ac40, in_statement_expr_p=false) at /home/
gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:5554
#21 0x080ecf6b in cp_parser_compound_statement (parser=0x4012ac40, in_statement_expr_p=false) 
at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:5735
#22 0x080f1812 in cp_parser_ctor_initializer_opt_and_function_body (parser=0x4012ac40) at /home/
gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:11431
#23 0x080f1948 in cp_parser_function_definition_after_declarator (parser=0x4012ac40, inline_p=true) 
at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:14300
#24 0x080eaa78 in cp_parser_type_specifier (parser=0x4012ac40, flags=Variable "flags" is not 
available.
) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:14702
#25 0x080eb44e in cp_parser_decl_specifier_seq (parser=0x4012ac40, 
flags=CP_PARSER_FLAGS_OPTIONAL, attributes=0xbffec2b8, declares_class_or_enum=0xbffec2bc)
    at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:6799
#26 0x080f1f42 in cp_parser_simple_declaration (parser=0x4012ac40, 
function_definition_allowed_p=true) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:6525
#27 0x080f2118 in cp_parser_block_declaration (parser=0x4012ac40, statement_p=false) at /home/
gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:6485
#28 0x080f2cde in cp_parser_declaration (parser=0x4012ac40) at /home/gates/pinskia/src/gnu/gcc/
src/gcc/cp/parser.c:6405
#29 0x080f2faf in cp_parser_declaration_seq_opt (parser=0x4012ac40) at /home/gates/pinskia/src/
gnu/gcc/src/gcc/cp/parser.c:6303
#30 0x080f319e in c_parse_file () at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:2393
#31 0x0818183b in c_common_parse_file (set_yydebug=0) at /home/gates/pinskia/src/gnu/gcc/src/
gcc/c-opts.c:1244
#32 0x083c081e in toplev_main (argc=0, argv=0xbffec494) at /home/gates/pinskia/src/gnu/gcc/src/
gcc/toplev.c:1596
#33 0x0818540e in main (argc=0, argv=0x0) at /home/gates/pinskia/src/gnu/gcc/src/gcc/main.c:35
Comment 2 Wolfgang Bangerth 2004-05-06 21:28:29 UTC
This is marginally smaller: 
--------------- 
struct S {}; 
 
template <typename> struct X { 
    S s; 
    void foo (void (S::*p)()) 
      { (s.*p)(); } 
}; 
--------------- 
 
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -c x.cc 
x.cc: In member function `void X< <template-parameter-1-1> >::foo(void (S::*)
())': 
x.cc:6: 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. 
 
Comment 3 CVS Commits 2004-05-24 02:23:48 UTC
Subject: Bug 15329

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2004-05-24 02:22:19

Modified files:
	gcc/testsuite  : ChangeLog 
	gcc/cp         : ChangeLog parser.c typeck.c 
Added files:
	gcc/testsuite/g++.dg/ext: attrib14.C 
	gcc/testsuite/g++.dg/template: error12.C ptrmem9.C 

Log message:
	PR c++/15044
	* parser.c (cp_parser_class_head): Robustify.
	
	PR c++/15317
	* parser.c (cp_parser_decl_specifier_seq): Correct error in
	comment.
	(cp_parser_constructor_declarator_p): Treat attributes
	as decl-specifiers.
	
	PR c++/15329
	* typeck.c (build_unary_op): Do not attempt to resolve casts to
	base classes in templates.
	
	PR c++/15044
	* g++.dg/template/error12.C: New test.
	
	PR c++/15317
	* g++.dg/ext/attrib14.C: New test.
	
	PR c++/15329
	* g++.dg/template/ptrmem9.C: New test.

Patches:
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.182&r2=1.3389.2.183
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.105&r2=1.3892.2.106
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.157.2.27&r2=1.157.2.28
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.519.2.15&r2=1.519.2.16
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/attrib14.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.2.16.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/error12.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/ptrmem9.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 4 CVS Commits 2004-05-24 02:29:49 UTC
Subject: Bug 15329

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-05-24 02:29:35

Modified files:
	gcc/testsuite  : ChangeLog 
	gcc/cp         : ChangeLog parser.c typeck.c 
Added files:
	gcc/testsuite/g++.dg/ext: attrib15.C 
	gcc/testsuite/g++.dg/template: error12.C ptrmem9.C 

Log message:
	PR c++/15044
	* parser.c (cp_parser_class_head): Robustify.
	
	PR c++/15317
	* parser.c (cp_parser_decl_specifier_seq): Correct error in
	comment.
	(cp_parser_constructor_declarator_p): Treat attributes
	as decl-specifiers.
	
	PR c++/15329
	* typeck.c (build_unary_op): Do not attempt to resolve casts to
	base classes in templates.
	
	PR c++/15044
	* g++.dg/template/error12.C: New test.
	
	PR c++/15317
	* g++.dg/ext/attrib15.C: New test.
	
	PR c++/15329
	* g++.dg/template/ptrmem9.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3777&r2=1.3778
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4056&r2=1.4057
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.194&r2=1.195
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.543&r2=1.544
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/attrib15.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/error12.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/ptrmem9.C.diff?cvsroot=gcc&r1=1.1&r2=1.2

Comment 5 CVS Commits 2004-05-24 02:30:44 UTC
Subject: Bug 15329

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2004-05-24 02:30:28

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/ext: attrib15.C 

Log message:
	PR c++/15044
	* parser.c (cp_parser_class_head): Robustify.
	
	PR c++/15317
	* parser.c (cp_parser_decl_specifier_seq): Correct error in
	comment.
	(cp_parser_constructor_declarator_p): Treat attributes
	as decl-specifiers.
	
	PR c++/15329
	* typeck.c (build_unary_op): Do not attempt to resolve casts to
	base classes in templates.
	
	PR c++/15044
	* g++.dg/template/error12.C: New test.
	
	PR c++/15317
	* g++.dg/ext/attrib15.C: New test.
	
	PR c++/15329
	* g++.dg/template/ptrmem9.C: New test.

Patches:
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.183&r2=1.3389.2.184
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/attrib15.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 6 Mark Mitchell 2004-05-24 02:35:17 UTC
Fixed in GCC 3.4.1.