`-Wunused-private-field` not reported for `[[gnu::warn_unused]]` annotated type when empty constructors are present
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
```cpp
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
};
```
```
:25:14: warning: private field 's2' is not used [-Wunused-private-field]
25 | const S2 s2; // warning
| ^
: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.
Contributor guide
Research direction
Reproduce the warning behavior using the C++ example in the issue and the linked Compiler Explorer case. Compare the four annotated types with the user-provided and defaulted constructors, then compare with a defaulted constructor on C. Done means -Wunused-private-field reports all four fields consistently, with regression coverage for the reproducer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100