[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 5 12:15:27 PST 2024


================
@@ -5563,6 +5563,12 @@ ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc,
 ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) {
   assert(Field->hasInClassInitializer());
 
+  // We do not want to aggressively cutoff parsing. Try to recover when
+  // in-class-initializer had errors.
+  if (Field->getInClassInitializer() &&
+      Field->getInClassInitializer()->containsErrors())
+    return Field->getInClassInitializer();
----------------
efriedma-quic wrote:

I guess the idea here is that we're throwing away too much if we just return an ExprError?  I assume everything would work without crashing, we'd just produce slightly different diagnostics.  So... I guess my first question is, do we really need to do this in this patch, as opposed to a followup?

BuildCXXDefaultInitExpr is supposed to, as the name suggests, return a CXXDefaultInitExpr.  As-is, this is going to produce weird results with erroneous expressions that aren't just a RecoveryExpr, like typo corrections.  Maybe we can explicitly create a RecoveryExpr here, though, nested inside the CXXDefaultInitExpr, or something like that.

https://github.com/llvm/llvm-project/pull/113049


More information about the cfe-commits mailing list