| Issue |
165205
|
| Summary |
[clang] -Wdeprecated-declarations reports multiplied when on deducing this method
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
adambadura
|
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
<source>:17:7: warning: 'foo' is deprecated: Don't use foo! [-Wdeprecated-declarations]
17 | d.foo() = x;
| ^
<source>: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 <utility>
class demo
{
public:
template <typename Self>
[[deprecated("Don't use foo!")]]
auto& foo(this Self&& self) { return std::forward<Self>(self).value; }
private:
int value{};
};
void test(const int x)
{
demo d{};
d.foo() = x;
}
```
the output somehow expands to 4 warnings:
```plain
<source>:17:7: warning: 'foo' is deprecated: Don't use foo! [-Wdeprecated-declarations]
17 | d.foo() = x;
| ^
<source>:8:11: note: 'foo' has been explicitly marked deprecated here
8 | auto& foo(this Self&& self) { return std::forward<Self>(self).value; }
| ^
<source>:17:7: warning: 'foo<demo &>' is deprecated: Don't use foo! [-Wdeprecated-declarations]
17 | d.foo() = x;
| ^
<source>:7:7: note: 'foo<demo &>' has been explicitly marked deprecated here
7 | [[deprecated("Don't use foo!")]]
| ^
<source>:17:7: warning: 'foo' is deprecated: Don't use foo! [-Wdeprecated-declarations]
17 | d.foo() = x;
| ^
<source>:8:11: note: 'foo' has been explicitly marked deprecated here
8 | auto& foo(this Self&& self) { return std::forward<Self>(self).value; }
| ^
<source>:17:7: warning: 'foo<demo &>' is deprecated: Don't use foo! [-Wdeprecated-declarations]
17 | d.foo() = x;
| ^
<source>:7:7: note: 'foo<demo &>' has been explicitly marked deprecated here
7 | [[deprecated("Don't use foo!")]]
| ^
4 warnings generated.
Compiler returned: 0
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs