[clang] [AST] Iterate redecls starting from the canonical one in getRawCommentsForAnyRedecl() (PR #108475)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 17 07:53:27 PDT 2024


zyn0217 wrote:

Sorry, it might be I forgot to save the changes before I ran the tests yesterday!

I looked into it again, and I think I have begun to understand `TemplateParameterListsInfo`:

The first intent is to describe out-of-line member functions that live in a templated scope. For example,

```cpp
template <class T>
struct S {
  void foo();
};

template <class T>
void S<T>::foo() {}
```

So the member function `foo`, which is *not* a template, doesn't have any associated template declaration, whereas it has a structure `TemplateParameterListsInfo` that describes its specifier `S<T>`.

However, for non-member function explicit specialization in question, `ActOnFunctionDeclarator()` would also set up its `TemplateParameterListsInfo` for the "spelled" explicit specialization, and wire up the "implicit" declaration to the "spelled" declaration, in the form of a redeclaration.

Seemingly we might fix the problem in `ActOnFunctionDeclarator()` (we shouldn't do that in `CheckFunctionTemplateSpecialization()` because that has more clients than `ActOnFunctionDeclarator()`, e.g. CXXMethod instantiator that we probably don't need to deal with.) and thereby we don't have to take care of these odd canonical declarations in `ASTContext::getRawCommentForAnyRedecl()`.

I tried that approach locally and now I have all check-clang tests passed but some of the check-clangd tests failed

```
Clangd :: include-cleaner-batch-fix.test
Clangd Unit Tests :: ./ClangdTests/DefineInlineTest/AddInline (DefineInlineTest.AddInline, around line 990)
```

I don't know if people already have some assumptions that an "implicit" explicit specialization shouldn't have its `TemplateParameterListsInfo`, though :(

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


More information about the cfe-commits mailing list