[PATCH] D150075: Fix PR#62594 : static lambda call operator is not convertible to function pointer on win32
Faisal Vali via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun May 7 14:11:16 PDT 2023
faisalv created this revision.
faisalv added reviewers: aaron.ballman, shafik, royjacobson.
faisalv added a project: clang.
Herald added a subscriber: pengfei.
Herald added a project: All.
faisalv requested review of this revision.
Herald added a subscriber: cfe-commits.
See issue https://github.com/llvm/llvm-project/issues/62594
This code does not work on win32:
cpp
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).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D150075
Files:
clang/lib/Sema/SemaType.cpp
clang/test/SemaCXX/cxx23-static-callop-lambda-expression.cpp
Index: clang/test/SemaCXX/cxx23-static-callop-lambda-expression.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/cxx23-static-callop-lambda-expression.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
+
+
+namespace ns1 {
+ auto lstatic = []() static { return 3; };
+ int (*f2)(void) = lstatic;
+
+}
+
+namespace ns1_1 {
+
+ auto lstatic = []() static consteval //expected-note {{declared here}} expected-error{{cannot take address of consteval call}}
+ { return 3; };
+
+ // FIXME: the above error should indicate that it was triggered below.
+ int (*f2)(void) = lstatic;
+
+}
+
+
+namespace ns2 {
+ auto lstatic = []() static { return 3; };
+ constexpr int (*f2)(void) = lstatic;
+ static_assert(lstatic() == f2());
+}
+
+namespace ns3 {
+ void main() {
+ static int x = 10;
+ auto L = []() static { return x; };
+ }
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -4057,8 +4057,9 @@
D.getTypeObject(I).Kind == DeclaratorChunk::MemberPointer;
} else if (D.getContext() == DeclaratorContext::LambdaExpr) {
// This can only be a call operator for a lambda, which is an instance
- // method.
- IsCXXInstanceMethod = true;
+ // method, unless explicitly specified as 'static'.
+ IsCXXInstanceMethod =
+ D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static;
} else {
// We're the innermost decl chunk, so must be a function declarator.
assert(D.isFunctionDeclarator());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150075.520209.patch
Type: text/x-patch
Size: 1758 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230507/51f50325/attachment.bin>
More information about the cfe-commits
mailing list