llvm / llvm/llvm-project

[clang] -Wdeprecated-declarations reports multiplied when on deducing this method

Open
#165,205 0 comments 0 reactions 0 assignees View on GitHub
clang:diagnostics
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.