kazutakahirata wrote:
I haven't looked closely at the implementation side of this PR, so please take
this with a grain of salt. My LLM came up with the standalone `lit` testcases
below, and each one currently fails `-verify` with an unexpected
`-Wunused-private-field` warning when dropped into `clang/test/SemaCXX/` with
this PR applied. You might want to look into these cases:
`__builtin_offsetof` in a discarded `if constexpr` branch:
```cpp
// RUN: %clang_cc1 -fsyntax-only -Wunused-private-field -verify -std=c++17 %s
// expected-no-diagnostics
namespace offsetof_if_constexpr {
template <bool B>
class Slab {
public:
static int offset() {
if constexpr (B)
return __builtin_offsetof(Slab, node_);
return 0;
}
private:
int node_;
};
int k = Slab<true>::offset() + Slab<false>::offset();
} // namespace offsetof_if_constexpr
```
Nested class field in a discarded `if constexpr` branch:
```cpp
// RUN: %clang_cc1 -fsyntax-only -Wunused-private-field -verify -std=c++17 %s
// expected-no-diagnostics
namespace nested_if_constexpr {
template <bool B>
struct Outer {
class Inner {
friend struct Outer;
int field_;
};
static int use(Inner &i) {
if constexpr (B)
return i.field_;
return 0;
}
};
int test() {
Outer<true>::Inner i1;
Outer<false>::Inner i2;
return Outer<true>::use(i1) + Outer<false>::use(i2);
}
} // namespace nested_if_constexpr
```
Structured binding in a discarded `if constexpr` branch:
```cpp
// RUN: %clang_cc1 -fsyntax-only -Wunused-private-field -verify -std=c++17 %s
// expected-no-diagnostics
namespace structured_binding_if_constexpr {
template <bool B>
class Box {
public:
int get() const {
if constexpr (B) {
auto [x] = *this;
return x;
}
return 0;
}
private:
int x_ = 0;
};
int k = Box<true>().get() + Box<false>().get();
} // namespace structured_binding_if_constexpr
```
Member template inside a `friend` class's nested class:
```cpp
// RUN: %clang_cc1 -fsyntax-only -Wunused-private-field -verify -std=c++11 %s
// expected-no-diagnostics
namespace friend_nested_template {
struct Friend {
struct Nested {
template <class T>
static int get(const T &x) { return x.value_; }
};
};
template <class>
class Holder {
friend struct Friend;
int value_;
};
Holder<int> h;
} // namespace friend_nested_template
```
Field used by one explicit member specialization and not another:
```cpp
// RUN: %clang_cc1 -fsyntax-only -Wunused-private-field -verify -std=c++11 %s
// expected-no-diagnostics
namespace explicit_member_spec {
template <class>
class Packet {
int header_;
int read();
};
template <> int Packet<int>::read() { return header_; }
template <> int Packet<void>::read() { return 0; }
} // namespace explicit_member_spec
```
https://github.com/llvm/llvm-project/pull/244396
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits