[clang] [llvm] [Clang] Fix cleanup attribute by delaying type checks after the type is deduced (PR #164440)
Guillot Tony via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 4 14:48:11 PST 2025
to268 wrote:
Basically, it is about the way template type parameters are deduced.
The `Ty` template type parameter should be referring to the `int` type in the following example:
```cpp
int open() { return 0; }
void close(decltype(open()) *) {}
template <typename Ty>
void test() {
Ty fd [[gnu::cleanup(close)]] = open(); // error: 'cleanup' function 'close' parameter has type 'decltype(open()) *' (aka 'int *') which is incompatible with type 'Ty *'
}
int main() {
test<int>();
}
```
The fix would be to trigger the deduction of the template parameter, which should transform the `Ty *` to a `int *` type, which would be a compatible type.
I have heard that the deducing logic is triggered based on a TableGen file, but I do not find where would it be.
https://github.com/llvm/llvm-project/pull/164440
More information about the llvm-commits
mailing list