Bug 28787 - Internal compiler error (ICE) when trying to initialize function in template
Internal compiler error (ICE) when trying to initialize function in template
Status: RESOLVED DUPLICATE of bug 27807
Product: gcc
Classification: Unclassified
Component: c++
4.1.1
: P3 normal
: ---
Assigned To: Not yet assigned to anyone
: ice-on-invalid-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2006-08-21 10:39 UTC by vlukas
Modified: 2006-08-21 18:29 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description vlukas 2006-08-21 10:39:25 UTC
The following code snippet crashes GCC 4.1.1 and 4.2.0 20060820 (experimental):
------
template<typename T>
void f(T& r)
{
T a = r;
}

void g()
{
f(g);
}

------
Saving the code in a file a.cc and executing "c++ -c a.cc" produces:
------
a.cc: In function 'void f(T&) [with T = void ()()]':
a.cc:9:   instantiated from here
a.cc:4: internal compiler error: in digest_init, at cp/typeck2.c:709
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
------
The above output is produced by GCC 4.1.1. With the mentioned GCC CVS snapshot the linenumber where the ICE is reported changes to cp/typeck2.c:718.
This bug might be related to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27807.

GCC 3.4.6 does not ICE, and rejects the code with a diagnostic, which is correct behaviour as far as I know.
Comment 1 Richard Biener 2006-08-21 10:48:09 UTC
Indeed a dup of that PR.

*** This bug has been marked as a duplicate of 27807 ***
Comment 2 vlukas 2006-08-21 11:01:24 UTC
>Indeed a dup of that PR.
>
>*** This bug has been marked as a duplicate of 27807 ***
I do not mean to sound impertinent, but with GCC 4.2.0 20060820 (experimental), I can not reproduce bug 27807. However the code I submitted still crashes this same version. Doesn't that mean the the fix for 27807 does not at the same time fix this?
Comment 3 vlukas 2006-08-21 12:04:08 UTC
A variation of the code crashes GCC 4.2.0 20060820 (experimental) with a different ICE:
------
template<typename>
void f()
{
typedef void (t)();
t a = x;
}

void g()
{
f<int>();
}

------
This produces the following output:
------
b.cc: In function 'void f()':
b.cc:5: error: function 'void a()' is initialized like a variable
b.cc:5: error: 'x' was not declared in this scope
b.cc:5: internal compiler error: tree check: expected var_decl, have function_decl in cp_finish_decl, at cp/decl.c:5089
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
------
This latter snippet does not crash GCC 3.4.6 or 4.1.1. Should this rather get its own report?
Comment 4 Andrew Pinski 2006-08-21 18:29:04 UTC
(In reply to comment #3)
> A variation of the code crashes GCC 4.2.0 20060820 (experimental) with a
> different ICE:

That is most likely PR 27961.