[clang] Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585, #111173)" (PR #111852)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 14 05:52:12 PDT 2024
ilya-biryukov wrote:
We are seeing some internal tests (and tools) failing because the canonical declaration for template specializations has changed in cases like this:
```cpp
template <typename T>
void Foo(T target); // #1
template <typename T>
void Foo(T defn) {} // #2
template <>
void Foo(int specialization) {} // #3
```
a matcher
```cpp
functionDecl(
hasName("Foo"), isDefinition(),
hasParameter(
0, parmVarDecl(hasType(isInt()),
mostCanonicalDecl(parmVarDecl().bind("p")))))),
```
with `mostCanonicalDecl` implemented as
```cpp
if (const auto* param = clang::dyn_cast<clang::ParmVarDecl>(&Node)) {
if (const auto* parent = clang::dyn_cast_or_null<clang::FunctionDecl>(
Node.getParentFunctionOrMethod())) {
const clang::FunctionDecl* func = parent;
if (const auto* pattern = func->getTemplateInstantiationPattern()) {
// Traverse from the instantiation to the pattern.
func = pattern;
}
func = func->getCanonicalDecl();
if (parent != func) {
/* remap indicies and get the matching parameter*/
/* ... */
}
}
}
```
has previously returned `#1` when matching the specialization. Now it returns `#2`.
Is this change in the canonical declaration intended?
https://github.com/llvm/llvm-project/pull/111852
More information about the cfe-commits
mailing list