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());
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());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits