Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

-Wdeprecated-declarations on members behaves unexpectedly #55774

Open
ghost opened this issue May 30, 2022 · 1 comment
Open

-Wdeprecated-declarations on members behaves unexpectedly #55774

ghost opened this issue May 30, 2022 · 1 comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@ghost
Copy link

ghost commented May 30, 2022

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:

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:

@ghost ghost changed the title -Wdeprecated-declaration on members behaves differently from MSVC and GCC -Wdeprecated-declaration on members behaves unexpectedly May 30, 2022
@ghost ghost changed the title -Wdeprecated-declaration on members behaves unexpectedly -Wdeprecated-declarations on members behaves unexpectedly May 30, 2022
@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed new issue labels May 30, 2022
@avikivity
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

No branches or pull requests

2 participants