Skip to content

Commit 5bdd5d0

Browse files
committed
Fix PR#62594 : static lambda call operator is not convertible to function pointer on win32
See issue #62594 This code does not work on win32: auto lstatic = []() static { return 0; }; int (*f2)(void) = lstatic; Since a calling convention such as CC_X86ThisCall can rightly interfere with the implicit pointer to function conversion if erroneously marked on a static function, the fix entails checking the 'static' specifier on the lambda declarator prior to assigning it a calling convention of an non-static member (which pre-c++23 made sense).
1 parent 8049db0 commit 5bdd5d0

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ Bug Fixes to C++ Support
283283
- Clang now properly handles out of line template specializations when there is
284284
a non-template inner-class between the function and the class template.
285285
(`#65810 <https://github.com/llvm/llvm-project/issues/65810>`_)
286+
287+
- Clang now properly converts static lambda call operator to function
288+
pointer on win32.
289+
(`#62594 <https://github.com/llvm/llvm-project/issues/62594>`_)
286290

287291
Bug Fixes to AST Handling
288292
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaType.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4095,8 +4095,9 @@ static CallingConv getCCForDeclaratorChunk(
40954095
D.getTypeObject(I).Kind == DeclaratorChunk::MemberPointer;
40964096
} else if (D.getContext() == DeclaratorContext::LambdaExpr) {
40974097
// This can only be a call operator for a lambda, which is an instance
4098-
// method.
4099-
IsCXXInstanceMethod = true;
4098+
// method, unless explicitly specified as 'static'.
4099+
IsCXXInstanceMethod =
4100+
D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static;
41004101
} else {
41014102
// We're the innermost decl chunk, so must be a function declarator.
41024103
assert(D.isFunctionDeclarator());
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
2+
3+
4+
namespace ns1 {
5+
auto lstatic = []() static { return 3; };
6+
int (*f2)(void) = lstatic;
7+
8+
}
9+
10+
namespace ns1_1 {
11+
12+
auto lstatic = []() static consteval //expected-error{{cannot take address of consteval call}} \
13+
expected-note {{declared here}}
14+
{ return 3; };
15+
16+
// FIXME: the above error should indicate that it was triggered below.
17+
int (*f2)(void) = lstatic;
18+
19+
}
20+
21+
22+
namespace ns2 {
23+
auto lstatic = []() static { return 3; };
24+
constexpr int (*f2)(void) = lstatic;
25+
static_assert(lstatic() == f2());
26+
}
27+
28+
namespace ns3 {
29+
void main() {
30+
static int x = 10;
31+
auto L = []() static { return x; };
32+
}
33+
}

0 commit comments

Comments
 (0)