Bug 87409 - Implement -Wunused-private-field
Summary: Implement -Wunused-private-field
Status: RESOLVED DUPLICATE of bug 72789
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: new-warning, new_warning
  Show dependency treegraph
 
Reported: 2018-09-24 10:53 UTC by Martin Liška
Modified: 2023-09-05 11:30 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-09-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liška 2018-09-24 10:53:24 UTC
The warning is reported by clang, can help to remove an unused code.
Comment 1 Martin Liška 2018-09-24 10:54:01 UTC
Example:

private field 'm_next' is not used: -Wunused-private-field
Comment 2 Andrew Pinski 2018-09-24 10:56:44 UTC
Note removal of private fields can change the ABI of a structure so this warning should never be turned on by -Wextra or -Wall.
Comment 3 Andrew Pinski 2018-09-24 10:58:22 UTC
Also I don't see how this warning can be implemented without seeing all functions and implementation of functions for a class which dont need to be in a header.
Comment 4 Martin Liška 2018-09-24 11:04:38 UTC
Sure, has limitations, but it was able to catch some dead code in GCC source files.
Comment 5 Jonathan Wakely 2018-09-24 11:18:16 UTC
Yes, it can only warn when there are no member functions that aren't defined in the current TU. Even then, it might need additional work to check at the end of a TU if there are non-inline function definitions:

struct A {
  A();
  void f();
private:
  int i = 0;
};

A::A() { }

void A::f() { }

Here we'd need to do the check at the end of the TU, after everything has been defined. Clang does warn for this example.

Clang suppresses the warning if the member declaration has attribute unused, which we would need to do too.
Comment 6 Eric Gallager 2018-09-30 01:07:12 UTC
Dup of bug 72789

*** This bug has been marked as a duplicate of bug 72789 ***