Input: struct { } a[1]; template<int &&> void b() { __attribute__((noinline(a[0]))) int c = 0; } Output: $ xgcc -x c++ -S - <stdin>: In function 'void b()': <stdin>:6:38: internal compiler error: in build_value_init, at cp/init.c:343 0xcfbe2b build_value_init(tree_node*, int) /home/vegard/git/gcc/gcc/cp/init.c:342 0xa47056 cxx_eval_array_reference /home/vegard/git/gcc/gcc/cp/constexpr.c:2458 0xa339b0 cxx_eval_constant_expression /home/vegard/git/gcc/gcc/cp/constexpr.c:4470 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 0xc43ac2 cp_check_const_attributes /home/vegard/git/gcc/gcc/cp/decl2.c:1415 0xc43ac2 cplus_decl_attributes(tree_node**, tree_node*, int) /home/vegard/git/gcc/gcc/cp/decl2.c:1531 0xc1974a start_decl(cp_declarator const*, cp_decl_specifier_seq*, int, tree_node*, tree_node*, tree_node**) /home/vegard/git/gcc/gcc/cp/decl.c:5050 0xfa391c cp_parser_init_declarator /home/vegard/git/gcc/gcc/cp/parser.c:19591 0xfa9757 cp_parser_simple_declaration /home/vegard/git/gcc/gcc/cp/parser.c:13063 0xfaf948 cp_parser_block_declaration /home/vegard/git/gcc/gcc/cp/parser.c:12881 0xfb1e14 cp_parser_declaration_statement /home/vegard/git/gcc/gcc/cp/parser.c:12474 0xefdd8b cp_parser_statement /home/vegard/git/gcc/gcc/cp/parser.c:10923 0xf0184b cp_parser_statement_seq_opt /home/vegard/git/gcc/gcc/cp/parser.c:11272 0xf022ea cp_parser_compound_statement /home/vegard/git/gcc/gcc/cp/parser.c:11226 0xf967eb cp_parser_function_body /home/vegard/git/gcc/gcc/cp/parser.c:21769 0xf967eb cp_parser_ctor_initializer_opt_and_function_body /home/vegard/git/gcc/gcc/cp/parser.c:21804 0xf9f9f5 cp_parser_function_definition_after_declarator /home/vegard/git/gcc/gcc/cp/parser.c:26809 0xfa604d cp_parser_function_definition_from_specifiers_and_declarator /home/vegard/git/gcc/gcc/cp/parser.c:26726 0xfa604d cp_parser_init_declarator /home/vegard/git/gcc/gcc/cp/parser.c:19493 $ xgcc --version xgcc (GCC) 8.0.1 20180301 (experimental) Built from git c435a9e730c6e8f10da09d58b4fc9aaeb401b0d5 (r258097). Seems to have appeared between 6.3.0 and 7.1.0. Test case was minimised by C-Reduce.
struct S {} a[1]; template <int N> void foo () { __attribute__ ((noinline (a[0]))) int c = 0; } Started with r239267, before it has been rejected: pr84665.C: In function ‘void foo()’: pr84665.C:7:41: error: wrong number of arguments specified for ‘noinline’ attribute __attribute__ ((noinline (a[0]))) int c = 0; ^
We don't ICE with struct S { int s; } a[1]; but do ICE with e.g. struct S { constexpr S () {} } a[1]; build_value_init has: 341 /* The AGGR_INIT_EXPR tweaking below breaks in templates. */ 342 gcc_assert (!processing_template_decl 343 || (SCALAR_TYPE_P (type) || TREE_CODE (type) == ARRAY_TYPE)); early, and type in this case is RECORD_TYPE S. Called from: 2456 /* If it's within the array bounds but doesn't have an explicit 2457 initializer, it's value-initialized. */ 2458 tree val = build_value_init (elem_type, tf_warning_or_error); 2459 return cxx_eval_constant_expression (ctx, val, lval, non_constant_p, 2460 overflow_p); because a doesn't have explicit initializer. No idea what to do here...
Related to PR84940.
Author: jason Date: Thu Apr 5 16:04:08 2018 New Revision: 259132 URL: https://gcc.gnu.org/viewcvs?rev=259132&root=gcc&view=rev Log: PR c++/84665 - ICE with array of empty class. * decl2.c (cp_check_const_attributes): Use fold_non_dependent_expr. Added: trunk/gcc/testsuite/g++.dg/ext/attr-noinline-4.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl2.c
Author: jason Date: Thu Apr 5 18:27:43 2018 New Revision: 259146 URL: https://gcc.gnu.org/viewcvs?rev=259146&root=gcc&view=rev Log: PR c++/84665 - ICE with array of empty class. * decl2.c (cp_check_const_attributes): Use fold_non_dependent_expr. Added: branches/gcc-7-branch/gcc/testsuite/g++.dg/ext/attr-noinline-4.C Modified: branches/gcc-7-branch/gcc/cp/ChangeLog branches/gcc-7-branch/gcc/cp/decl2.c
Fixed.