1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2b %s
4 consteval
int undefined(); // expected-note 4 {{declared here}}
6 void check_lambdas_unused(
9 // The body of a lambda is not a subexpression of the lambda
10 // so this is immediately evaluated even if the parameter
12 return undefined(); // expected-error {{not a constant expression}} \
13 // expected-note {{undefined function 'undefined'}}
15 int b
= [](int no_error
= undefined()) {
18 int c
= [](int defaulted
= undefined()) {
23 int check_lambdas_used(
24 int b
= [](int no_error
= undefined()) {
27 int c
= [](int defaulted
= undefined()) { // expected-error {{not a constant expression}} \
28 // expected-note {{declared here}} \
29 // expected-note {{undefined function 'undefined'}}
31 }(), // expected-note {{in the default initalizer of 'defaulted'}}
32 int d
= [](int defaulted
= sizeof(undefined())) {
39 int test_check_lambdas_used
= check_lambdas_used();
41 struct UnusedInitWithLambda
{
43 return undefined(); // expected-error {{not a constant expression}} \
44 // expected-note {{undefined function 'undefined'}}
46 // UnusedInitWithLambda is never constructed, so the initializer
47 // of b and undefined() are never evaluated.
48 int b
= [](int no_error
= undefined()) {
53 consteval
int ub(int n
) {
54 return 0/n
; // expected-note {{division}}
57 struct InitWithLambda
{
58 int b
= [](int error
= undefined()) { // expected-error {{not a constant expression}} \
59 // expected-note {{declared here}} \
60 // expected-note {{undefined function 'undefined'}}
62 }(); // expected-note {{in the default initalizer of 'error'}}
63 int c
= [](int error
= sizeof(undefined()) + ub(0)) { // expected-error {{'ub' is not a constant expression}} \
64 // expected-note {{declared here}} \
65 // expected-note {{in call to 'ub(0)}}
67 }(); // expected-note {{in the default initalizer of 'error'}}
68 } i
; // expected-note {{in implicit default constructor}}
70 namespace ShouldNotCrash
{
77 static constexpr auto x
= [] {};