Skip to content

-Wunused-private-field not reported for [[gnu::warn_unused]] annotated type when empty constructors are present #160244

@firewave

Description

@firewave
class [[gnu::warn_unused]] S1 {
public:
    S1() {}
};

class [[gnu::warn_unused]] S2 {
public:
    S2() = default;
};

class [[gnu::warn_unused]] S3 {
public:
    S3();
};

class [[gnu::warn_unused]] S4 {
};

class C {
public:
    C() {}

private:
    const S1 s1; // no warning
    const S2 s2; // warning
    const S3 s3; // no warning
    const S4 s4; // warning
};
<source>:25:14: warning: private field 's2' is not used [-Wunused-private-field]
   25 |     const S2 s2; // warning
      |              ^
<source>:27:14: warning: private field 's4' is not used [-Wunused-private-field]
   27 |     const S4 s4; // warning
      |              ^

https://godbolt.org/z/rjcEMzn96

If you change the C constructor to = default all are reported regardless of the other constructor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-negativeWarning doesn't fire when it should

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions