https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122283

            Bug ID: 122283
           Summary: Incomplete error and bailing out if a consteval ctor
                    delegates to a non-constexpr one
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: error-recovery, ice-on-invalid-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: blubban at gmail dot com
  Target Milestone: ---

template<int a>
struct foo {
        int b;

        foo(int) {}
        consteval foo() : foo(1) {}
};

void bar()
{
        foo<2> c;
}


-std=c++20


Expected:

<source>: In function 'void bar()':
<source>:11:16: error: call to consteval function 'a.foo<2>::foo()' is not a
constant expression
   11 |         foo<2> a;
      |                ^
<source>:11:16: error: 'consteval foo<a>::foo() [with int a = 2]' called in a
constant expression
<source>:6:19: note: 'consteval foo<a>::foo() [with int a = 2]' is not usable
as a 'constexpr' function because:
    6 |         consteval foo() : foo(1) {}
      |                   ^~~
<source>:6:32: error: call to non-'constexpr' function 'foo<a>::foo(int) [with
int a = 2]'
    6 |         consteval foo() : foo(1) {}
      |                                ^
<source>:5:9: note: 'foo<a>::foo(int) [with int a = 2]' declared here
    5 |         foo(int) {}
      |         ^~~
Compiler returned: 1


Actual:

<source>: In function 'void bar()':
<source>:11:16: error: call to consteval function 'a.foo<2>::foo()' is not a
constant expression
   11 |         foo<2> a;
      |                ^
<source>:11:16: error: 'consteval foo<a>::foo() [with int a = 2]' called in a
constant expression
<source>:6:19: note: 'consteval foo<a>::foo() [with int a = 2]' is not usable
as a 'constexpr' function because:
    6 |         consteval foo() : foo(1) {}
      |                   ^~~
<source>:6:19: internal compiler error: in build_data_member_initialization, at
cp/constexpr.cc:466
0x28de9b8 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x28d37ab internal_error(char const*, ...)
        ???:0
0xb05622 fancy_abort(char const*, int, char const*)
        ???:0
0xb8850a explain_invalid_constexpr_fn(tree_node*)
        ???:0
0xb82bb3 cxx_constant_value(tree_node*, tree_node*, int)
        ???:0
0x189208c walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        ???:0
0x18928f6 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        ???:0
0xbb18dc cp_fold_function(tree_node*)
        ???:0
0xc00ea9 finish_function(bool)
        ???:0
0xd3e213 c_parse_file()
        ???:0
0xeae8b9 c_common_parse_file()
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1


Removing the member variable makes it not ICE, but instead, it prints the final
error and note twice.


https://godbolt.org/z/KnfsKWrez


Like bug 102262, it's an incomplete error due to missing constexpr keyword, but
that one doesn't ICE, so I'm guessing it's a different root cause.

Reply via email to