diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -229,6 +229,9 @@ antecipation of `CWG2563 _`. - Fix highlighting issue with ``_Complex`` and initialization list with more than 2 items. (`#61518 `_) +- Fix false-positive diagnostic issued for consteval initializers of temporary + objects. + (`#60286 `_) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -1590,6 +1590,9 @@ Expr *Inner = Result.get(); if (CXXBindTemporaryExpr *BTE = dyn_cast_or_null(Inner)) Inner = BTE->getSubExpr(); + if (auto *CE = dyn_cast(Inner); + CE && CE->isImmediateInvocation()) + Inner = CE->getSubExpr(); if (!isa(Inner) && !isa(Inner)) { // If we created a CXXTemporaryObjectExpr, that node also represents the diff --git a/clang/test/SemaCXX/cxx2a-consteval.cpp b/clang/test/SemaCXX/cxx2a-consteval.cpp --- a/clang/test/SemaCXX/cxx2a-consteval.cpp +++ b/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); + +}