<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/112366>112366</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Issuing a deprecated warning when the chosen template specialization does not use the deprecated class
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
DYNIO-INTEL
</td>
</tr>
</table>
<pre>
Following code produces warning for 'deprecated_class<int>' but the class which uses deprecated class doesn't use that template specialization. It seems that specializations that are instantiated during overload resolution are diagnosing the attribute on them even if that overload is not selected.
https://godbolt.org/
```c++
#ifdef BE_THE_HEADER
#pragma clang system_header
#include <type_traits>
template<typename T>
class [[deprecated]] deprecated_class{};
template<int Dimensions, typename DataT>
class using_deprecated{
public:
template <int Dims = Dimensions,
typename = std::enable_if_t<(Dims > 0), int>>
int foo() const {
return Dims;
}
template <int Dims = Dimensions>
typename std::enable_if_t<(Dims == 0), deprecated_class<DataT>>
foo() const {
return deprecated_class<DataT>();
}
};
#else
#define BE_THE_HEADER
#include __FILE__
int main(){
using_deprecated<1, int> test_obj;
auto return_value = test_obj.foo();
}
#endif
```
Compiling output with -Wall flag
```
In file included from main.cpp:24:
main.cpp:17:42: warning: 'deprecated_class<int>' is deprecated [-Wdeprecated-declarations]
17 | typename std::enable_if_t<(Dims == 0), deprecated_class<DataT>>
| ^
main.cpp:26:28: note: in instantiation of template class 'using_deprecated<1, int>' requested here
26 | using_deprecated<1, int> test_obj;
| ^
main.cpp:5:9: note: 'deprecated_class<int>' has been explicitly marked deprecated here
5 | class [[deprecated]] deprecated_class{};
| ^
main.cpp:27:8: warning: unused variable 'return_value' [-Wunused-variable]
27 | auto return_value = test_obj.foo();
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VtuO2zYQ_Rr6ZWBDJm3LftCDr8gCQQoUAYI-CZQ4sphSpEpS3m6_vqDuyW6zvaCGY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