Skip to content

Forward-declared consteval function is rejected for use in a template parameter's default value #62224

@cjdb

Description

@cjdb

GCC test: g++.dg/cpp2a/consteval-defarg3.C

consteval int foober();

int g(int = foober());
struct A { int i = foober(); };
template <int i = foober()> struct B { };
struct C
{
  consteval C(int = foober()) { }
};
int h(C = C());

consteval int foober() { return 42; }

int main() {
  A a;
  B<> b;
  g();
  h();
}

Diagnostic:

<source>:5:19: error: non-type template argument is not a constant expression
template <int i = foober()> struct B { };
                  ^~~~~~~~
<source>:5:19: note: undefined function 'foober' cannot be used in a constant expression
<source>:1:15: note: declared here
consteval int foober();
              ^
<source>:16:3: error: too few template arguments for class template 'B'
  B<> b;
  ^
<source>:5:36: note: template is declared here
template <int i = foober()> struct B { };
~~~~~~~~~~~~~~~~~~~~~~~~~~~        ^

Repro: https://godbolt.org/z/dPPE5TTnr

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partyconstevalC++20 constevalrejects-valid

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions