Skip to content

Don't warn about deprecated fields in implicitly generated special member functionsΒ #147293

@HolyBlackCat

Description

@HolyBlackCat

This gives a warning:

struct A
{
    [[deprecated]] int x = 42;
};

int main()
{
    A a;
    A b = a;
    a = b;
}
<source>:1:8: warning: 'A::x' is deprecated [-Wdeprecated-declarations]
    1 | struct A
      |        ^
<source>:3:24: note: declared here
    3 |     [[deprecated]] int x = 42;
      |                        ^
<source>:1:8: warning: 'A::x' is deprecated [-Wdeprecated-declarations]
    1 | struct A
      |        ^
<source>:3:24: note: declared here
    3 |     [[deprecated]] int x = 42;
      |                        ^
<source>: In function 'int main()':
<source>:8:7: note: synthesized method 'constexpr A::A()' first required here
    8 |     A a;
      |       ^

IMO this isn't very useful. Only the manual uses of this field should warn, not the implicit ones.

GCC has the same issue, but MSVC doesn't. I've tested on Clang 20 and trunk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions