[clang] -Wdeprecated-declarations reports multiplied when on deducing this method
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Consider the following code ([Compiler Explorer](https://godbolt.org/z/fx61ffj93))
```c++
class demo
{
public:
[[deprecated("Don't use foo!")]]
auto& foo() const { return value; }
[[deprecated("Don't use foo!")]]
auto& foo() { return value; }
private:
int value{};
};
void test(const int x)
{
demo d{};
d.foo() = x;
}
```
which produces (as expected) the following output:
```plain
:17:7: warning: 'foo' is deprecated: Don't use foo! [-Wdeprecated-declarations]
17 | d.foo() = x;
| ^
:7:7: note: 'foo' has been explicitly marked deprecated here
7 | [[deprecated("Don't use foo!")]]
| ^
1 warning generated.
Compiler returned: 0
```
However, if the `demo::foo` is rewritten to use "deducing this" (P0847, C++23 feature; [Compiler Explorer](https://godbolt.org/z/jYfTfGnY8)):
```c++
#include
class demo
{
public:
template
[[deprecated("Don't use foo!")]]
auto& foo(this Self&& self) { return std::forward(self).value; }
private:
int value{};
};
void test(const int x)
{
demo d{};
d.foo() = x;
}
```
the output somehow expands to 4 warnings:
```plain
:17:7: warning: 'foo' is deprecated: Don't use foo! [-Wdeprecated-declarations]
17 | d.foo() = x;
| ^
:8:11: note: 'foo' has been explicitly marked deprecated here
8 | auto& foo(this Self&& self) { return std::forward(self).value; }
| ^
:17:7: warning: 'foo' is deprecated: Don't use foo! [-Wdeprecated-declarations]
17 | d.foo() = x;
| ^
:7:7: note: 'foo' has been explicitly marked deprecated here
7 | [[deprecated("Don't use foo!")]]
| ^
:17:7: warning: 'foo' is deprecated: Don't use foo! [-Wdeprecated-declarations]
17 | d.foo() = x;
| ^
:8:11: note: 'foo' has been explicitly marked deprecated here
8 | auto& foo(this Self&& self) { return std::forward(self).value; }
| ^
:17:7: warning: 'foo' is deprecated: Don't use foo! [-Wdeprecated-declarations]
17 | d.foo() = x;
| ^
:7:7: note: 'foo' has been explicitly marked deprecated here
7 | [[deprecated("Don't use foo!")]]
| ^
4 warnings generated.
Compiler returned: 0
```
Contributor guide
Assessment
This issue has not been assessed yet.