diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -6500,7 +6500,7 @@ if (shouldBindAsTemporary(Entity)) CurInit = S.MaybeBindToTemporary(CurInit.get()); - return CurInit; + return S.CheckForImmediateInvocation(CurInit, Constructor); } namespace { 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 @@ -441,3 +441,14 @@ }; } } + +namespace constructor { + struct A { + A* ptr = nullptr; + consteval A() : ptr(this) { } + }; + + A a = A(); // expected-error {{is not a constant expression}} + // expected-note@-1 {{is not a constant expression}} expected-note@-1 {{temporary created here}} +} +