Author: faisal vali Date: 2023-09-16T13:29:59-05:00 New Revision: 5bdd5d064d5171b2d5ff6268528cfffd2f86b8ea
URL: https://github.com/llvm/llvm-project/commit/5bdd5d064d5171b2d5ff6268528cfffd2f86b8ea DIFF: https://github.com/llvm/llvm-project/commit/5bdd5d064d5171b2d5ff6268528cfffd2f86b8ea.diff LOG: Fix PR#62594 : static lambda call operator is not convertible to function pointer on win32 See issue https://github.com/llvm/llvm-project/issues/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). Added: clang/test/SemaCXX/cxx23-static-callop-lambda-expression.cpp Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaType.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index d558705f16ca3be..e9bfefd40bbbf82 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -283,6 +283,10 @@ Bug Fixes to C++ Support - Clang now properly handles out of line template specializations when there is a non-template inner-class between the function and the class template. (`#65810 <https://github.com/llvm/llvm-project/issues/65810>`_) + +- Clang now properly converts static lambda call operator to function + pointer on win32. + (`#62594 <https://github.com/llvm/llvm-project/issues/62594>`_) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index ffd29446b4f2edd..d13a5564e9ad64c 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -4095,8 +4095,9 @@ static CallingConv getCCForDeclaratorChunk( 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()); diff --git a/clang/test/SemaCXX/cxx23-static-callop-lambda-expression.cpp b/clang/test/SemaCXX/cxx23-static-callop-lambda-expression.cpp new file mode 100644 index 000000000000000..fab76ffc423a3b2 --- /dev/null +++ b/clang/test/SemaCXX/cxx23-static-callop-lambda-expression.cpp @@ -0,0 +1,33 @@ +// 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-error{{cannot take address of consteval call}} \ + expected-note {{declared here}} + { 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; }; + } +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits