[libcxx-commits] [PATCH] D124516: [libc++] Implement `std::expected` P0323R12

Hui via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 24 14:57:04 PST 2022


huixie90 added inline comments.


================
Comment at: libcxx/include/__expected/expected.h:619-620
+  union {
+    _Tp __val_;
+    _Err __unex_;
+  };
----------------
ldionne wrote:
> Can we use `[[no_unique_address]]` here? Can you investigate how that attribute interacts with unions? Also, does it make sense to put it on the union itself?
Here is my finding. 

For anonymous union (which is the case in the `expected`, I can't find a way to make `[[no_unique_address]]` to have any effect
https://godbolt.org/z/zebh4E94d

For a named union, if we apply `[[no_unique_address]]` on the `union` itself plus all the members of the `union`,  we can save some space.
https://godbolt.org/z/rGoa7c47d

So I think we don't need to do anything here


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124516/new/

https://reviews.llvm.org/D124516



More information about the libcxx-commits mailing list