Bug 84655 - internal compiler error: unexpected expression 'a' of kind template_parm_index
Summary: internal compiler error: unexpected expression 'a' of kind template_parm_index
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0.1
: P4 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2018-03-01 20:10 UTC by Vegard Nossum
Modified: 2020-11-30 18:11 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-03-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vegard Nossum 2018-03-01 20:10:42 UTC
Input (you gotta love this one!):

template<int... a>
struct b {
  int &&c;
  int d[] = [] { auto f(a); };
} const __attribute__((noinline(b<>())));

Output:

$ xgcc -x c++ -S -
<stdin>: In lambda function:
<stdin>:4:23: internal compiler error: unexpected expression 'a' of kind template_parm_index
0xa3d06b cxx_eval_constant_expression
        /home/vegard/git/gcc/gcc/cp/constexpr.c:4767
0xa4e0da cxx_eval_outermost_constant_expr
        /home/vegard/git/gcc/gcc/cp/constexpr.c:4827
0xa5b966 maybe_constant_value(tree_node*, tree_node*)
        /home/vegard/git/gcc/gcc/cp/constexpr.c:5044
0xaba942 cp_fully_fold(tree_node*)
        /home/vegard/git/gcc/gcc/cp/cp-gimplify.c:2040
0x142d41f store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
        /home/vegard/git/gcc/gcc/cp/typeck2.c:848
0xb48878 check_initializer
        /home/vegard/git/gcc/gcc/cp/decl.c:6430
0xbdcd8e cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
        /home/vegard/git/gcc/gcc/cp/decl.c:7084
0x10cc38d tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        /home/vegard/git/gcc/gcc/cp/pt.c:16331
0x10c0128 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        /home/vegard/git/gcc/gcc/cp/pt.c:16464
0x10c0128 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        /home/vegard/git/gcc/gcc/cp/pt.c:16464
0x11d483f tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
        /home/vegard/git/gcc/gcc/cp/pt.c:17203
0x10f7dcb tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
        /home/vegard/git/gcc/gcc/cp/pt.c:18486
0xd27a93 get_nsdmi(tree_node*, bool, int)
        /home/vegard/git/gcc/gcc/cp/init.c:581
0xdc6d74 walk_field_subobs
        /home/vegard/git/gcc/gcc/cp/method.c:1354
0xdd46a3 synthesized_method_walk
        /home/vegard/git/gcc/gcc/cp/method.c:1744
0xde62f2 get_defaulted_eh_spec(tree_node*, int)
        /home/vegard/git/gcc/gcc/cp/method.c:1776
0x11d647a maybe_instantiate_noexcept(tree_node*, int)
        /home/vegard/git/gcc/gcc/cp/pt.c:23088
0xc64811 mark_used(tree_node*, int)
        /home/vegard/git/gcc/gcc/cp/decl2.c:5229
0x921ac0 build_over_call
        /home/vegard/git/gcc/gcc/cp/call.c:7680
0x9346ff build_new_method_call_1
        /home/vegard/git/gcc/gcc/cp/call.c:9285

$ xgcc --version
xgcc (GCC) 8.0.1 20180301 (experimental)

Built from git c435a9e730c6e8f10da09d58b4fc9aaeb401b0d5 (r258097).

7.3.0 seems to be fine with this.

Test case was minimised by C-Reduce.
Comment 1 Marek Polacek 2018-03-01 20:20:25 UTC
Confirmed.

Started with r251433.
Comment 2 Marek Polacek 2018-03-01 20:21:06 UTC
Before that we printed a boatload of errors:

q.cc: In lambda function:
q.cc:4:26: error: parameter packs not expanded with ‘...’:
   int d[] = [] { auto f(a); };
                          ^
q.cc:4:26: note:         ‘a’
q.cc: At global scope:
q.cc:5:33: error: array must be initialized with a brace-enclosed initializer
 } const __attribute__((noinline(b<>())));
                                 ^~~~~
q.cc:5:33: error: use of deleted function ‘b<>::b()’
q.cc:2:8: error: array must be initialized with a brace-enclosed initializer
 struct b {
        ^
q.cc:2:8: note: ‘b<>::b()’ is implicitly deleted because the default definition would be ill-formed:
q.cc:2:8: error: uninitialized reference member in ‘struct b<>’
q.cc:3:9: note: ‘int&& b<>::c’ should be initialized
   int &&c;
         ^
q.cc:5:3: error: ‘const’ can only be specified for objects and functions
 } const __attribute__((noinline(b<>())));
   ^~~~~
q.cc:2:8: warning: attribute ignored in declaration of ‘struct b<a>’ [-Wattributes]
 struct b {
        ^
q.cc:2:8: note: attribute for ‘struct b<a>’ must follow the ‘struct’ keyword
Comment 3 Arseny Solokha 2019-05-01 08:58:25 UTC
I cannot reproduce the ICE w/ any released version of gcc, from 8.1.0 through the current trunk.
Comment 4 David Binderman 2019-05-01 09:07:07 UTC
I tried out various versions of gcc trunk, from revision 269700
to 270600 and could see no ice.

I'd be interested to find out what Marek did to reproduce it.
Comment 5 Vegard Nossum 2019-11-16 13:58:39 UTC
I can't seem to reproduce this anymore, I suppose it could be closed.
Comment 6 Marek Polacek 2020-11-30 18:11:34 UTC
Fixed.