diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -17624,9 +17624,13 @@ Transformer.AllowSkippingFirstCXXConstructExpr = false; ExprResult Res = Transformer.TransformExpr(It->getPointer()->getSubExpr()); - assert(Res.isUsable()); - Res = SemaRef.MaybeCreateExprWithCleanups(Res); - It->getPointer()->setSubExpr(Res.get()); + // The result may not be usable in case of previous compilation errors. + // In this case evaluation of the expression may result in crash so just + // don't do anything further with the result. + if (Res.isUsable()) { + Res = SemaRef.MaybeCreateExprWithCleanups(Res); + It->getPointer()->setSubExpr(Res.get()); + } } static void diff --git a/clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp b/clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp @@ -0,0 +1,11 @@ +// RUN: not %clang_cc1 -fsyntax-only -verify -std=gnu++20 -ferror-limit 19 %s +// Creduced test case for the crash in RemoveNestedImmediateInvocation after compliation errros. + +a, class b { template < typename c> consteval b(c +} template using d = b; +auto e(d<>) -> int:; +} +f +} +g() { + auto h = "":(::i(e(h))