[clang-tools-extra] [clang-tidy] Add new `construct-reusable-objects-once` check (PR #131455)

Oliver Stöneberg via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 15 08:18:54 PDT 2025


firewave wrote:

Nice.

It looks like it does not consider that static initializations within functions are only thread-safe starting with C++11.

Also this may obviously only be applied to read-only objects. That would require an existing `const` object or usage in tandem with `misc-const-correctness` (and incremental runs) - it should not duplicate any of that logic.

And shouldn't global variables also be declared `static` or in an anonymous namespace?

A similar use I came across multiples times is STL containers being constructed for each. That is something which can not be covered with this check

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


More information about the cfe-commits mailing list