[clang] [clang] Fix assertion failure in constexpr union deserialization (PR #140179)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri May 16 00:15:15 PDT 2025


================
@@ -414,7 +414,7 @@ let Class = PropertyTypeCase<APValue, "Union"> in {
     let Read = [{ node.getUnionValue() }];
   }
   def : Creator<[{
-    return APValue(cast<clang::FieldDecl>(fieldDecl), std::move(value));
+    return APValue(cast_if_present<clang::FieldDecl>(fieldDecl), std::move(value));
----------------
hokein wrote:

Adding more context since it wasn’t obvious to me at first glance —  In the ASTWriter, the `fieldDecl` is written as `ap_value_node.getUnionField()`, and `getUnionField()` may return a nullptr, so in the ASTReader here, we need to handle the nullptr case to construct a null-field-decl `APValue`.

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


More information about the cfe-commits mailing list