[clang] [clang] ODR hashes depth+index and not name of TemplateTypeParm (PR #144796)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 23 01:52:04 PDT 2025
================
@@ -828,7 +828,23 @@ void ODRHash::AddDecl(const Decl *D) {
return;
}
- AddDeclarationName(ND->getDeclName());
+ // For template parameters, use depth+index instead of name, because type
+ // canonicalization can change the name of the template parameter.
+ if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(ND)) {
+ ID.AddInteger(TTPD->getDepth());
+ ID.AddInteger(TTPD->getIndex());
+ AddBoolean(TTPD->isParameterPack());
----------------
ilya-biryukov wrote:
Could you split the variadic templates into a separate change?
This looks like an independent issue (the code below should detect an ODR violation, but it doesn't) and actually opens a whole other can of worms wrt to what needs to be checked (e.g. checking types of non-type template parameters, template headers of template template parameters, etc).
```cpp
namespace mytest {
#ifdef FIRST
template <class ...T>
struct FooTypePack {};
template <int ...I>
struct FooIntPack {};
template <template<class> class ...TT>
struct FooTemplateTemplatePack {};
#endif
#ifdef SECOND
template <class T>
struct FooTypePack {};
template <int I>
struct FooIntPack {};
template <template<class> class TT>
struct FooTemplateTemplatePack {};
#endif
#ifdef ACCESS
FooTypePack<int> a;
FooIntPack<0> b;
FooTemplateTemplatePack<FooTypePack> c;
#endif
}
```
https://github.com/llvm/llvm-project/pull/144796
More information about the cfe-commits
mailing list