You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
By clicking “Sign up for GitHub”, you agree to our
terms of service
and
privacy statement
. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
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
.
In particular, the behaviour differs from MSVC and GCC:
MSVC:
no warning is raised
. 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
. 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.
The difference in behaviour between Clang and MSVC is removed.
Alternative solution
Report bug to MSVC to remove the difference between Clang and MSVC.
Minimal example
A full minimal example can be found in
this godbolt example
. The code is also below. Note in particular, the implicit move constructor.
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.
Non-triggering edge case
Note that if no (implicit) move constructor is used, the warning is not raised:
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:
changed the title
-Wdeprecated-declaration on members behaves differently from MSVC and GCC
-Wdeprecated-declaration on members behaves unexpectedly
May 30, 2022
-Wdeprecated-declaration on members behaves unexpectedly
-Wdeprecated-declarations on members behaves unexpectedly
May 30, 2022
clang:diagnostics
Request new/improved warning or error messages in the Clang compiler itself
and removed
new issue
labels
May 30, 2022