[clang] [Clang][Modules] Fix crash when redefining default template argument (PR #185237)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 10 03:12:27 PDT 2026
================
@@ -2472,13 +2473,23 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
NewDefaultLoc = NewTypeParm->getDefaultArgumentLoc();
SawDefaultArgument = true;
- if (!OldTypeParm->getOwningModule())
----------------
Qayyum-Ahmed wrote:
That would fix the null dereference, but treating “not imported” as always a redefinition would regress header modules. In crash-instantiated-in-scope-cxx-modules6.cpp, co.h contains a forward declaration and later the full definition of template <typename Promise = void> struct coroutine_handle; both with the same default. This is valid for local header modules, but using only getImportedOwningModule() would treat the second declaration as a same-TU redefinition and incorrectly diagnose it.
We therefore need to distinguish the local header-module case so identical defaults are allowed there, while still keeping the GMF strict and only calling getFullModuleName() when the previous declaration actually comes from an imported module.
See this snippet from crash-instantiated-in-scope-cxx-modules6.cpp:
[https://github.com/llvm/llvm-project/blob/main/clang/test/Headers/crash-instantiated-in-scope-cxx-modules6.cpp#L78-L87](url)
https://github.com/llvm/llvm-project/pull/185237
More information about the cfe-commits
mailing list