I’m trying to implement a Clang-Tidy that reorders fields of a RecordDecl to improve memory locality.
However, for the given code snippet below:
// Decl
struct Impl_ {
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::tutorial::Person > people_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
};
// Usage
new (&_impl_) Impl_{
decltype(_impl_.people_){from._impl_.people_}
, /*decltype(_impl_._cached_size_)*/{}};
The code will actually fail to compile if I swap the order of people_
and _cached_size_
due to it initializing the members by order instead of names?
How can I detect if a RecordDecl has usages like this and skip reordering for such Records