[PATCH] D142214: [MC] Do not copy MCInstrDescs. NFC.
Ilya Biryukov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 24 02:53:42 PST 2023
ilya-biryukov added a comment.
To describe the problem, the following code breaks in C++20:
struct WantAggregate {
WantAggregate(const WantAggregate&) = delete;
int a;
int b;
};
WantAggregate a = {1,2}; // does not compile in C++20.
One way to workaround this would be to force an implicitly-deleted constructor:
struct NoCopy {
NoCopy() = default;
NoCopy(const &) = delete;
};
struct WantAggregate {
int a;
int b;
NoCopy delete_copy = {};
};
WantAggregate a = {1,2}; // works!
However, this approach increases the size of `MCInstrDesc` (the extra member needs to have an address). One way to workaround it is
[[no_unique_address]] NoCopy delete_copy = {}; // no increase in size, implicitly deleted copy!
Unfortunately, this attribute was added only in C++20. I am trying to figure out a way to make this work in both C++17 and C++20 without the size increase, but still struggling to find a way without a preprocessor.
(I'm assuming the size increase is undesirable, lmk if it's actually not a big deal. Using a member is probably the easiest workaround.)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142214/new/
https://reviews.llvm.org/D142214
More information about the llvm-commits
mailing list