This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG2fbf18b40026: [clang] Fix aggregate initialization inside lambda constexpr (authored by Fznamznon).
Changed prior to commit: https://reviews.llvm.org/D144866?vs=501084&id=502546#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D144866/new/ https://reviews.llvm.org/D144866 Files: clang/docs/ReleaseNotes.rst clang/lib/AST/ExprConstant.cpp clang/test/SemaCXX/lambda-expressions.cpp Index: clang/test/SemaCXX/lambda-expressions.cpp =================================================================== --- clang/test/SemaCXX/lambda-expressions.cpp +++ clang/test/SemaCXX/lambda-expressions.cpp @@ -689,3 +689,18 @@ } } + +#if __cplusplus > 201402L +namespace GH60936 { +struct S { + int i; + // `&i` in default initializer causes implicit `this` access. + int *p = &i; +}; + +static_assert([]() constexpr { + S r = S{2}; + return r.p != nullptr; +}()); +} // namespace GH60936 +#endif Index: clang/lib/AST/ExprConstant.cpp =================================================================== --- clang/lib/AST/ExprConstant.cpp +++ clang/lib/AST/ExprConstant.cpp @@ -8758,16 +8758,19 @@ return false; } Result = *Info.CurrentCall->This; - // If we are inside a lambda's call operator, the 'this' expression refers - // to the enclosing '*this' object (either by value or reference) which is - // either copied into the closure object's field that represents the '*this' - // or refers to '*this'. + if (isLambdaCallOperator(Info.CurrentCall->Callee)) { - // Ensure we actually have captured 'this'. (an error will have - // been previously reported if not). + // Ensure we actually have captured 'this'. If something was wrong with + // 'this' capture, the error would have been previously reported. + // Otherwise we can be inside of a default initialization of an object + // declared by lambda's body, so no need to return false. if (!Info.CurrentCall->LambdaThisCaptureField) - return false; + return true; + // If we have captured 'this', the 'this' expression refers + // to the enclosing '*this' object (either by value or reference) which is + // either copied into the closure object's field that represents the + // '*this' or refers to '*this'. // Update 'Result' to refer to the data member/field of the closure object // that represents the '*this' capture. if (!HandleLValueMember(Info, E, Result, Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -178,6 +178,8 @@ (`#57682 <https://github.com/llvm/llvm-project/issues/57682>`_) - Clang now support export declarations in the language linkage. (`#60405 <https://github.com/llvm/llvm-project/issues/60405>`_) +- Fix aggregate initialization inside lambda constexpr. + (`#60936 <https://github.com/llvm/llvm-project/issues/60936>`_) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Index: clang/test/SemaCXX/lambda-expressions.cpp =================================================================== --- clang/test/SemaCXX/lambda-expressions.cpp +++ clang/test/SemaCXX/lambda-expressions.cpp @@ -689,3 +689,18 @@ } } + +#if __cplusplus > 201402L +namespace GH60936 { +struct S { + int i; + // `&i` in default initializer causes implicit `this` access. + int *p = &i; +}; + +static_assert([]() constexpr { + S r = S{2}; + return r.p != nullptr; +}()); +} // namespace GH60936 +#endif Index: clang/lib/AST/ExprConstant.cpp =================================================================== --- clang/lib/AST/ExprConstant.cpp +++ clang/lib/AST/ExprConstant.cpp @@ -8758,16 +8758,19 @@ return false; } Result = *Info.CurrentCall->This; - // If we are inside a lambda's call operator, the 'this' expression refers - // to the enclosing '*this' object (either by value or reference) which is - // either copied into the closure object's field that represents the '*this' - // or refers to '*this'. + if (isLambdaCallOperator(Info.CurrentCall->Callee)) { - // Ensure we actually have captured 'this'. (an error will have - // been previously reported if not). + // Ensure we actually have captured 'this'. If something was wrong with + // 'this' capture, the error would have been previously reported. + // Otherwise we can be inside of a default initialization of an object + // declared by lambda's body, so no need to return false. if (!Info.CurrentCall->LambdaThisCaptureField) - return false; + return true; + // If we have captured 'this', the 'this' expression refers + // to the enclosing '*this' object (either by value or reference) which is + // either copied into the closure object's field that represents the + // '*this' or refers to '*this'. // Update 'Result' to refer to the data member/field of the closure object // that represents the '*this' capture. if (!HandleLValueMember(Info, E, Result, Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -178,6 +178,8 @@ (`#57682 <https://github.com/llvm/llvm-project/issues/57682>`_) - Clang now support export declarations in the language linkage. (`#60405 <https://github.com/llvm/llvm-project/issues/60405>`_) +- Fix aggregate initialization inside lambda constexpr. + (`#60936 <https://github.com/llvm/llvm-project/issues/60936>`_) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits