Bug 27961 - [4.1 regression] ICE on invalid template declaration
Summary: [4.1 regression] ICE on invalid template declaration
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P4 minor
Target Milestone: 4.2.0
Assignee: Lee Millward
URL:
Keywords: error-recovery, ice-on-invalid-code, monitored
Depends on:
Blocks: 30156
  Show dependency treegraph
 
Reported: 2006-06-08 15:26 UTC by Volker Reichelt
Modified: 2008-07-04 15:35 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.2.0
Known to fail: 4.1.3
Last reconfirmed: 2006-09-23 16:28:31


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2006-06-08 15:26:00 UTC
The following testcase causes an ICE on the 4.1 branch and mainline:

====================================
struct A
{
    template<int> void foo(X);
};
====================================

bug.cc:7: error: 'X' was not declared in this scope
bug.cc:7: error: variable or field 'foo' declared void
bug.cc:7: internal compiler error: tree check: expected var_decl, have field_decl in cp_finish_decl, at cp/decl.c:4933
Please submit a full bug report, [etc.]

This is a very recent regression, since GCC 4.1.1 is not affected.

Mark, your patch for PR 27819 seems to have caused this:
http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00198.html
Comment 1 Volker Reichelt 2006-07-18 10:48:02 UTC
Here's a testcase with a slightly different error message:

========================================
template<int> void f()(0);
========================================

bug.cc:1: error: function 'void f()' is initialized like a variable
bug.cc:1: internal compiler error: tree check: expected var_decl, have function_decl in cp_finish_decl, at cp/decl.c:5083
Please submit a full bug report, [etc.]
Comment 2 Janis Johnson 2006-08-12 21:28:38 UTC
A regression hunt on powerpc-linux using the testcase from the submitter's description identified the following patch:

    http://gcc.gnu.org/viewcvs?view=rev&rev=114119

    r114119 | mmitchel | 2006-05-25 20:18:26 +0000 (Thu, 25 May 2006)
Comment 3 Volker Reichelt 2006-08-14 19:06:35 UTC
Reproduced by Janis.
Comment 4 patchapp@dberlin.org 2006-09-23 16:30:17 UTC
Subject: Bug number PR c++/27961

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-09/msg01018.html
Comment 5 Lee Millward 2006-10-12 20:03:02 UTC
Subject: Bug 27961

Author: lmillward
Date: Thu Oct 12 20:02:53 2006
New Revision: 117671

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117671
Log:
       PR c++/27961
       * decl.c (start_decl): Return error_mark_node if a
       function is initialized like a variable.
       (check_var_type): If a variable of field is declared void,
       set the type to error_mark_node.
       (grokdeclarator): Check the return type of check_var_type.
       * class.c (finish_struct_1): Robustify.

       * g++.dg/template/crash60.C: New test.
       * g++.dg/other/large-size-array.C: Adjust error markers.
       * g++.dg/parse/crash27.C: Likewise.
       * g++.dg/template/crash1.C: Likewise.


Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/other/large-size-array.C
    trunk/gcc/testsuite/g++.dg/parse/crash27.C
    trunk/gcc/testsuite/g++.dg/template/crash1.C

Comment 6 Lee Millward 2006-10-12 20:06:46 UTC
Subject: Bug 27961

Author: lmillward
Date: Thu Oct 12 20:06:36 2006
New Revision: 117672

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117672
Log:
	PR c++/27961
	* g++.dg/template/crash60.C: New test.


Added:
    trunk/gcc/testsuite/g++.dg/template/crash60.C

Comment 7 Lee Millward 2006-10-12 20:06:59 UTC
Fixed on mainline.
Comment 8 Volker Reichelt 2006-12-11 21:00:14 UTC
> Fixed on mainline.

Alas this is only partially true:
Although the original testcase is indeed fixed on mainline (and 4.2 branch),
the following variant (which only differs in the return type of the template
function) still crashes:

====================================
struct A
{
    template<int> int foo(X);
};
====================================

I'll open a new PR for this failure.


Btw, the testcase from comment #1 is also fixed on the 4.1 branch
(with "void" or "int" as return type).
Comment 9 Joseph S. Myers 2008-07-04 15:35:58 UTC
Closing 4.1 branch.