[clang-tools-extra] [clang-tidy] Fix false positive in cert-ctr56-cpp(PointerArithmeticOnPolymorphicObjectCheck) (PR #187452)

Zeyi Xu via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 20 23:30:50 PDT 2026


zeyi2 wrote:

Sorry for the late reply (for some reason I didn't get the notification)

> Is it okay to define a class with operator[]?

I think it would be better to use a mock std like this:

```c++
namespace std {
template <typename K, typename V>
struct map {
  V &operator[](const K &);
};
}
```

(Currently we still don't have `<map>` in clang-tidy's `input/headers`, so I guess we would have to mock this ourselves).

Then we could do something like:

```c++
template <typename T>
struct TemplateHolder : Base, T {
  std::map<Base *, int> M;
  void test() {
    auto &x = M[this];
    // no-warning here?
    (void)x;
  }
};
```

https://github.com/llvm/llvm-project/pull/187452


More information about the cfe-commits mailing list