[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaCXX / cxx2a-consteval-default-params.cpp
blobabeb27fd03e3545a3c86311bb02bb13260c23576
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(
7 int a = []
9 // The body of a lambda is not a subexpression of the lambda
10 // so this is immediately evaluated even if the parameter
11 // is never used.
12 return undefined(); // expected-error {{not a constant expression}} \
13 // expected-note {{undefined function 'undefined'}}
14 }(),
15 int b = [](int no_error = undefined()) {
16 return no_error;
17 }(0),
18 int c = [](int defaulted = undefined()) {
19 return defaulted;
20 }()
21 ) {}
23 int check_lambdas_used(
24 int b = [](int no_error = undefined()) {
25 return no_error;
26 }(0),
27 int c = [](int defaulted = undefined()) { // expected-error {{not a constant expression}} \
28 // expected-note {{declared here}} \
29 // expected-note {{undefined function 'undefined'}}
30 return defaulted;
31 }(), // expected-note {{in the default initalizer of 'defaulted'}}
32 int d = [](int defaulted = sizeof(undefined())) {
33 return defaulted;
34 }()
35 ) {
36 return 0;
39 int test_check_lambdas_used = check_lambdas_used();
41 struct UnusedInitWithLambda {
42 int a = [] {
43 return undefined(); // expected-error {{not a constant expression}} \
44 // expected-note {{undefined function 'undefined'}}
45 }();
46 // UnusedInitWithLambda is never constructed, so the initializer
47 // of b and undefined() are never evaluated.
48 int b = [](int no_error = undefined()) {
49 return no_error;
50 }();
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'}}
61 return error;
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)}}
66 return error;
67 }(); // expected-note {{in the default initalizer of 'error'}}
68 } i; // expected-note {{in implicit default constructor}}
70 namespace ShouldNotCrash {
71 template<typename T>
72 struct F {
73 template<typename U>
74 F(const U&) {}
76 struct A {
77 static constexpr auto x = [] {};
78 F<int> f = x;
80 void f(A a = A()) { }