Fznamznon created this revision. Herald added a project: All. Fznamznon requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
When a potential immediate invocation is met, it is immediately wrapped by a `ConstantExpr`. There is also a TreeTransform that removes this `ConstantExpr` wrapper when corresponding expression evaluation context is popped. So, in case initializer was an immediate invocation, `CXXTemporaryObjectExpr` was wrapped by a `ConstantExpr`, and that caused additional unnecessary `CXXFunctionalCastExpr` to be added, which later confused the TreeTransform that rebuilds immediate invocations, so it was adding unnecessary constructor call. Fixes https://github.com/llvm/llvm-project/issues/60286 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D146801 Files: clang/lib/Sema/SemaExprCXX.cpp clang/test/SemaCXX/cxx2a-consteval.cpp Index: clang/test/SemaCXX/cxx2a-consteval.cpp =================================================================== --- clang/test/SemaCXX/cxx2a-consteval.cpp +++ clang/test/SemaCXX/cxx2a-consteval.cpp @@ -1050,3 +1050,18 @@ } } + +namespace GH60286 { + +struct A { + int i = 0; + + consteval A() {} + A(const A&) { i = 1; } + consteval int f() { return i; } +}; + +constexpr auto B = A{A{}}.f(); +static_assert(B == 0); + +} Index: clang/lib/Sema/SemaExprCXX.cpp =================================================================== --- clang/lib/Sema/SemaExprCXX.cpp +++ clang/lib/Sema/SemaExprCXX.cpp @@ -1590,6 +1590,9 @@ Expr *Inner = Result.get(); if (CXXBindTemporaryExpr *BTE = dyn_cast_or_null<CXXBindTemporaryExpr>(Inner)) Inner = BTE->getSubExpr(); + if (ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(Inner)) + if (CE->isImmediateInvocation()) + Inner = CE->getSubExpr(); if (!isa<CXXTemporaryObjectExpr>(Inner) && !isa<CXXScalarValueInitExpr>(Inner)) { // If we created a CXXTemporaryObjectExpr, that node also represents the
Index: clang/test/SemaCXX/cxx2a-consteval.cpp =================================================================== --- clang/test/SemaCXX/cxx2a-consteval.cpp +++ clang/test/SemaCXX/cxx2a-consteval.cpp @@ -1050,3 +1050,18 @@ } } + +namespace GH60286 { + +struct A { + int i = 0; + + consteval A() {} + A(const A&) { i = 1; } + consteval int f() { return i; } +}; + +constexpr auto B = A{A{}}.f(); +static_assert(B == 0); + +} Index: clang/lib/Sema/SemaExprCXX.cpp =================================================================== --- clang/lib/Sema/SemaExprCXX.cpp +++ clang/lib/Sema/SemaExprCXX.cpp @@ -1590,6 +1590,9 @@ Expr *Inner = Result.get(); if (CXXBindTemporaryExpr *BTE = dyn_cast_or_null<CXXBindTemporaryExpr>(Inner)) Inner = BTE->getSubExpr(); + if (ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(Inner)) + if (CE->isImmediateInvocation()) + Inner = CE->getSubExpr(); if (!isa<CXXTemporaryObjectExpr>(Inner) && !isa<CXXScalarValueInitExpr>(Inner)) { // If we created a CXXTemporaryObjectExpr, that node also represents the
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits