1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++23 %s
4 consteval
int undefined(); // expected-note 2 {{declared here}}
6 void check_lambdas_unused(
7 int a
= [](int no_error
= undefined()) {
10 int b
= [](int defaulted
= undefined()) {
15 int check_lambdas_used(
16 int b
= [](int no_error
= undefined()) {
19 int c
= [](int defaulted
= undefined()) { // expected-error {{not a constant expression}} \
20 // expected-note {{declared here}} \
21 // expected-note {{undefined function 'undefined'}}
23 }(), // expected-note {{in the default initializer of 'defaulted'}}
24 int d
= [](int defaulted
= sizeof(undefined())) {
31 int test_check_lambdas_used
= check_lambdas_used();
33 struct UnusedInitWithLambda
{
35 return undefined(); // never evaluated because immediate escalating
37 // UnusedInitWithLambda is never constructed, so the initializer
38 // of b and undefined() are never evaluated.
39 int b
= [](int no_error
= undefined()) {
44 consteval
int ub(int n
) {
48 struct InitWithLambda
{ // expected-note {{'InitWithLambda' is an immediate constructor because the default initializer of 'b' contains a call to a consteval function 'undefined' and that call is not a constant expression}}
49 int b
= [](int error
= undefined()) { // expected-note {{undefined function 'undefined' cannot be used in a constant expression}}
52 int c
= [](int error
= sizeof(undefined()) + ub(0)) {
57 // expected-error@-1 {{call to immediate function 'InitWithLambda::InitWithLambda' is not a constant expression}} \
58 expected
-note@
-1 {{in call to
'InitWithLambda()'}}
60 namespace ShouldNotCrash
{
67 static constexpr auto x
= [] {};
75 template <int i
= fwd()>
77 consteval
C(int = fwd()) { }
78 consteval
int get() { return i
; }
81 consteval
int fwd() { return 42; }
82 C
<> Val
; // No error since fwd is defined already.
83 static_assert(Val
.get() == 42);
88 consteval
const char* ce() { return "Hello"; }
90 auto f2(const char* loc
= []( char const* fn
)
91 { return fn
; } ( ce() ) ) {