[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 5 01:42:32 PST 2024
================
@@ -750,6 +750,19 @@ void InitListChecker::FillInEmptyInitForField(unsigned Init, FieldDecl *Field,
if (Field->hasInClassInitializer()) {
if (VerifyOnly)
return;
+
+ // We do not want to aggressively set the hadError flag and cutoff
+ // parsing. Try to recover when in-class-initializer had errors.
+ if (Field->getInClassInitializer() &&
----------------
yronglin wrote:
I've move the code into BuildCXXDefaultInitExpr(), the original purpose of putting it here is to return quickly and avoid entering any context again.
```c++
ExprResult DIE;
{
// Enter a default initializer rebuild context, then we can support
// lifetime extension of temporary created by aggregate initialization
// using a default member initializer.
// CWG1815 (https://wg21.link/CWG1815).
EnterExpressionEvaluationContext RebuildDefaultInit(
SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
SemaRef.currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
true;
SemaRef.currentEvaluationContext().DelayedDefaultInitializationContext =
SemaRef.parentEvaluationContext()
.DelayedDefaultInitializationContext;
SemaRef.currentEvaluationContext().InLifetimeExtendingContext =
SemaRef.parentEvaluationContext().InLifetimeExtendingContext;
DIE = SemaRef.BuildCXXDefaultInitExpr(Loc, Field);
}
```
https://github.com/llvm/llvm-project/pull/113049
More information about the cfe-commits
mailing list