Issue |
97365
|
Summary |
clang++-19: Incorrect warning `unused-private-field` even though member is used in constructor.
|
Labels |
clang
|
Assignees |
|
Reporter |
greg7mdp
|
### test program: `Wunused-private-field.cpp`
```
// compiling this with `clang++-19 -Wall -c Wunused-private-field.cpp`
//
// produces a warning (even though `c` is used in the lambda)
// `Wunused-private-field.cpp:19:13: warning: private field 'c' is not used [-Wunused-private-field]`
// ----------------------------------------------------------------------------------------------------
#include <functional>
struct node;
struct cluster {
void ping();
};
void register_cb(std::function<void()>);
struct node {
node(cluster&);
private:
cluster &c;
};
node::node(cluster& c) : c(c) {
register_cb([&]() { c.ping(); });
c.ping();
}
```
### compiler output:
```
~/test ❯ clang++-19 -Wall -c Wunused-private-field.cpp
Wunused-private-field.cpp:19:13: warning: private field 'c' is not used [-Wunused-private-field]
19 | cluster &c;
| ^
1 warning generated.
```
### compiler version
```
~/test ❯ clang++-19 --version
Ubuntu clang version 19.0.0 (++20240630031615+ac84ada9a169-1~exp1~20240630151739.1777)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs