[clang] [Clang][Modules] Fix crash when redefining default template argument (PR #185237)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 10 03:36:09 PDT 2026


================
@@ -2472,13 +2473,23 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
         NewDefaultLoc = NewTypeParm->getDefaultArgumentLoc();
         SawDefaultArgument = true;
 
-        if (!OldTypeParm->getOwningModule())
+        bool SameDefault =
+            getASTContext().isSameDefaultTemplateArgument(OldTypeParm,
+                                                          NewTypeParm);
+        if (Module *ImportedM = OldTypeParm->getImportedOwningModule()) {
+          if (!SameDefault) {
+            InconsistentDefaultArg = true;
+            PrevModuleName = ImportedM->getFullModuleName();
+          }
+        } else if (Module *LocalM = OldTypeParm->getLocalOwningModule()) {
----------------
ChuanqiXu9 wrote:

```suggestion
        } else if (Module *LocalM = OldTypeParm->getLocalOwningModule(); LocalM && LocalM->isModuleMapModule()) {
        RedundantDefaultArg = !SameDefault;
}
```

nit: 

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


More information about the cfe-commits mailing list