File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,11 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
61
61
MD->getParent ()->getCaptureFields (LC, LTC);
62
62
63
63
for (auto Cap : LC) {
64
+ // Static lambdas cannot have any captures. If this one does,
65
+ // it has already been diagnosed and we can only ignore it.
66
+ if (MD->isStatic ())
67
+ return nullptr ;
68
+
64
69
unsigned Offset = R->getField (Cap.second )->Offset ;
65
70
this ->LambdaCaptures [Cap.first ] = {
66
71
Offset, Cap.second ->getType ()->isReferenceType ()};
Original file line number Diff line number Diff line change 4
4
// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=expected23 %s -fexperimental-new-constant-interpreter
5
5
6
6
7
- // expected23-no-diagnostics
8
-
9
-
10
7
// / FIXME: The new interpreter is missing all the 'control flows through...' diagnostics.
11
8
12
9
constexpr int f (int n) { // ref20-error {{constexpr function never produces a constant expression}} \
@@ -82,3 +79,27 @@ constexpr int k(int n) {
82
79
return m;
83
80
}
84
81
constexpr int k0 = k(0 );
82
+
83
+ namespace StaticLambdas {
84
+ constexpr auto static_capture_constexpr () {
85
+ char n = ' n' ;
86
+ return [n] static { return n; }(); // expected23-error {{a static lambda cannot have any captures}} \
87
+ // expected20-error {{a static lambda cannot have any captures}} \
88
+ // expected20-warning {{are a C++23 extension}} \
89
+ // expected20-warning {{is a C++23 extension}} \
90
+ // ref23-error {{a static lambda cannot have any captures}} \
91
+ // ref20-error {{a static lambda cannot have any captures}} \
92
+ // ref20-warning {{are a C++23 extension}} \
93
+ // ref20-warning {{is a C++23 extension}}
94
+ }
95
+ static_assert (static_capture_constexpr()); // expected23-error {{static assertion expression is not an integral constant expression}} \
96
+ // expected20-error {{static assertion expression is not an integral constant expression}} \
97
+ // ref23-error {{static assertion expression is not an integral constant expression}} \
98
+ // ref20-error {{static assertion expression is not an integral constant expression}}
99
+
100
+ constexpr auto capture_constexpr () {
101
+ char n = ' n' ;
102
+ return [n] { return n; }();
103
+ }
104
+ static_assert (capture_constexpr());
105
+ }
You can’t perform that action at this time.
0 commit comments