Bug 101903 - [13/14/15/16 Regression] ICE with invalid constexpr constructor in template class
Summary: [13/14/15/16 Regression] ICE with invalid constexpr constructor in template c...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.0
: P4 normal
Target Milestone: 13.5
Assignee: Not yet assigned to anyone
URL:
Keywords: error-recovery, ice-on-invalid-code
: 117969 (view as bug list)
Depends on:
Blocks: constexpr 118192
  Show dependency treegraph
 
Reported: 2021-08-13 20:15 UTC by Volker Reichelt
Modified: 2025-07-11 09:06 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 5.1.0, 6.1.0
Known to fail: 11.1.0, 12.0, 7.1.0, 9.1.0
Last reconfirmed: 2021-08-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2021-08-13 20:15:56 UTC
The following invalid code snippet triggers an ICE since GCC 7.1.0:

===============================
template<int> struct A
{
  int i{};

  A();
  constexpr A(int) : A() {}
};

constexpr A<0> a{0};
===============================

bug.cc:9:19: error: 'constexpr A<<anonymous> >::A(int) [with int <anonymous> = 0]' called in a constant expression
    9 | constexpr A<0> a{0};
      |                   ^
bug.cc:6:13: note: 'constexpr A<<anonymous> >::A(int) [with int <anonymous> = 0]' is not usable as a 'constexpr' function because:
    6 |   constexpr A(int) : A() {}
      |             ^
bug.cc:6:13: internal compiler error: in build_data_member_initialization, at cp/constexpr.c:400
0x66cf30 build_data_member_initialization
	../../gcc/gcc/cp/constexpr.c:400
0x960432 build_constexpr_constructor_member_initializers
	../../gcc/gcc/cp/constexpr.c:612
0x960432 massage_constexpr_body
	../../gcc/gcc/cp/constexpr.c:738
0x96ce3d explain_invalid_constexpr_fn(tree_node*)
	../../gcc/gcc/cp/constexpr.c:982
0x9621e1 cxx_eval_call_expression
	../../gcc/gcc/cp/constexpr.c:2594
0x96543c cxx_eval_constant_expression
	../../gcc/gcc/cp/constexpr.c:6269
0x968cc4 cxx_eval_outermost_constant_expr
	../../gcc/gcc/cp/constexpr.c:7301
0x96da7e maybe_constant_init_1
	../../gcc/gcc/cp/constexpr.c:7756
0xb9902a store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
	../../gcc/gcc/cp/typeck2.c:777
0x9b4cc6 check_initializer
	../../gcc/gcc/cp/decl.c:7185
0x9dab09 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
	../../gcc/gcc/cp/decl.c:8119
0xac5174 cp_parser_init_declarator
	../../gcc/gcc/cp/parser.c:22556
0xaa0773 cp_parser_simple_declaration
	../../gcc/gcc/cp/parser.c:15088
0xacfdb5 cp_parser_declaration
	../../gcc/gcc/cp/parser.c:14787
0xad078e cp_parser_toplevel_declaration
	../../gcc/gcc/cp/parser.c:14808
0xad078e cp_parser_translation_unit
	../../gcc/gcc/cp/parser.c:4978
0xad078e c_parse_file()
	../../gcc/gcc/cp/parser.c:46558
0xbf924d c_common_parse_file()
	../../gcc/gcc/c-family/c-opts.c:1223
Please submit a full bug report, [etc.]
Comment 1 Martin Liška 2021-08-16 07:59:36 UTC
Confirmed, started with r7-2529-g23f4e590fb4ce718.
Comment 2 Richard Biener 2022-05-27 09:46:05 UTC
GCC 9 branch is being closed
Comment 3 Jakub Jelinek 2022-06-28 10:46:04 UTC
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
Comment 4 Richard Biener 2023-07-07 10:40:43 UTC
GCC 10 branch is being closed.
Comment 5 Richard Biener 2024-07-19 13:13:23 UTC
GCC 11 branch is being closed.
Comment 6 Drea Pinski 2024-12-29 22:47:46 UTC
*** Bug 117969 has been marked as a duplicate of this bug. ***
Comment 7 Richard Biener 2025-07-11 09:06:26 UTC
GCC 12 branch is being closed.