<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55774>55774</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            `-Wdeprecated-declaration` on members behaves differently from MSVC and GCC
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mgovers-philips
      </td>
    </tr>
</table>

<pre>
    ## Issue

A deprecated member variable in a `struct` or `class` makes the entire entity deprecated, even if the user does not actually use the deprecated member (it may even be private). This is behaviour is not mentioned by the [C++ reference](https://en.cppreference.com/w/cpp/language/attributes/deprecated).

In particular, the behaviour differs from MSVC and GCC:

* **MSVC:** no warning is raised](https://godbolt.org/z/T49h6e1c8)). This is actually an issue, because it may cause instances to go unnoticed.
* **GCC:** [the warning is raised, even if no implicit move constructor was used](https://godbolt.org/z/1YPGx89dG). This difference may be explained as a compiler optimization.

## Expected behaviour

The deprecation warning is raised only when the member variable is actually used by the user.

At the very least, the difference in behaviour between Clang and MSVC should be removed.

## Minimal example 

A full minimal example can be found in (this godbolt example)[https://godbolt.org/z/ajnWPqW4P). The code is also below. Note in particular, the implicit move constructor.

```cpp
namespace {
struct Foo {
    [[deprecated]] bool bar{};
};
auto baz() {
    auto foo = Foo{};
    return foo;
}
}
```

### Class

Note that the above [also happens for otherwise fully private members in `classes`](https://godbolt.org/z/7n193j3Wb).

### Non-triggering edge case

Note that if no (implicit) `move` constructor is used, [the warning is not raised](https://godbolt.org/z/hbjY3zeEE):

```cpp
namespace {
struct Foo {
    [[deprecated]] bool bar{};
};
auto baz() {
    return Foo{};
}
}
```

### Class

Note that the above bug also happens for otherwise fully private members in `classes`:


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNVt9vozgQ_mvIi5WIQsiPhzykSVvtw64qXXXVPhoYwD1jc7ZJmv71N2NIQ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