[clang] [C++20][Modules] Preserve cleanups in default argument updates (PR #240633)

Davis Rollman via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 17 13:54:26 PST 2026


================
@@ -6676,8 +6676,7 @@ void ASTWriter::WriteDeclUpdatesBlocks(ASTContext &Context,
         break;
 
       case DeclUpdateKind::CXXInstantiatedDefaultArgument:
-        Record.writeStmtRef(
-            cast<ParmVarDecl>(Update.getDecl())->getDefaultArg());
+        Record.writeStmtRef(cast<ParmVarDecl>(Update.getDecl())->getInit());
----------------
8Keep wrote:

Yes, this is the same change as #76473. This is the core of the pr, changing getDefaultArg() to getInit(). The asymmetry is actually correct imo. It's kinda the naming of these functions that is the problem, but that's beside the point of this pr.


Function | What it really does
-- | --
setDefaultArg(x) | stores x, untouched
getInit() | returns what is stored, untouched
getDefaultArg() | returns what is stored minus its outer wrapper node

`setDefaultArg(getDefaultArg())` is lossy. `setDefaultArg(x->getInit())` is the way to copy a default argument.

in clang there are 3 places where this pattern happens today:

`clang/lib/Sema/SemaDeclCXX.cpp:574`
`clang/lib/Sema/SemaDeclCXX.cpp:617` (with that comment)
`clang/lib/Parse/ParseCXXInlineMethods.cpp:469`

The earliest case I could find of someone hitting this is here: https://github.com/llvm/llvm-project/commit/e61b02bcaf8a in 2010



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


More information about the cfe-commits mailing list