[libcxx-commits] [libcxx] [libc++] Replace `__compressed_pair` with `[[no_unique_address]]` (PR #76756)

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 17 04:12:29 PDT 2024


mstorsjo wrote:

> @mstorsjo it looks like the problem is just that we don't initialize the padding: https://godbolt.org/z/ErETWTdoc. Could you check that this fixes your problem too? Initializing the padding bytes seems fairly low cost, especially since the common cases don't actually have any padding bytes (`basic_string<T>`, `vector<T>`, `unique_ptr<T>`).

Thanks for the quick reply! So essentially, I'd apply the following change:
```diff
diff --git a/libcxx/include/__memory/compressed_pair.h b/libcxx/include/__memory/compressed_pair.h
index 629e3ad8848f..12404953a715 100644
--- a/libcxx/include/__memory/compressed_pair.h
+++ b/libcxx/include/__memory/compressed_pair.h
@@ -56,7 +56,7 @@ template <class _ToPad>
 class __compressed_pair_padding {
   char __padding_[((is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value) || is_reference<_ToPad>::value)
                       ? 0
-                      : sizeof(_ToPad) - __datasizeof_v<_ToPad>];
+                      : sizeof(_ToPad) - __datasizeof_v<_ToPad>]{};
 };
 
 #  define _LIBCPP_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2)                                                  \
```

That does seem to fix building Qt, thanks!

(I guess this can be considered a gap in our testsuite coverage, that we should patch at some point as well?)

However it does break including these headers in C++98/03 mode:
```
/home/martin/clang-nightly/x86_64-w64-mingw32/include/c++/v1/__memory/compressed_pair.h:57:8: error: function definition does not declare parameters
   57 |   char __padding_[((is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value) || is_reference<_ToPad>::value)
      |        ^
1 error generated.
```



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


More information about the libcxx-commits mailing list