[clang] [clang-tools-extra] [clang] implement printing of canonical template arguments of expression kind (PR #135133)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 11 08:33:04 PDT 2025


mizvekov wrote:

Sure, but I'd have to resist the urge to fix them, so that they can end up as test cases. They probably wouldn't survive long either way.

For example, I grepped the source tree for diagnostics where we are emitting 'type-parameter-X-X', and where this is happening not because the parameter is anonymous.

Found this one in `CXX/temp/temp.decls/temp.mem/p5.cpp` (reduced):
```C++
struct X0 {
  template<typename T> operator T*() const; // expected-note{{explicit instantiation refers here}}
};
template X0::operator float*() const; // expected-error{{explicit instantiation of undefined function template 'operator type-parameter-0-0 *'}}
```

Converting this test case to one involving NTTP is easy:
```C++
template<int A> struct B {};
struct X0 {
  template<int C> operator B<C>() const;
};
template X0::operator B<0>() const;
```

And sure enough, with this patch we produce:
`error: explicit instantiation of undefined function template 'operator B<value-parameter-0-0>'`
Instead of:
`error: explicit instantiation of undefined function template 'operator B<A>'`

Now you could devise a more complicated scenario where, instead of coincidentally printing the correct template parameter name, we produce an earlier equivalent template specialization with a different parameter name, and that causes a later one to be printed incorrectly.

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


More information about the cfe-commits mailing list