添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
坚韧的显示器  ·  three.js 学习笔记 - ...·  2 月前    · 
爱搭讪的红金鱼  ·  Fonts Matplotlib ...·  7 月前    · 
爽快的松鼠  ·  活动回顾 | ...·  10 月前    · 
活泼的棒棒糖  ·  11. ...·  1 年前    · 

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