[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 03:29:55 PDT 2024
mstorsjo wrote:
This change broke compiling Qt. The following piece of code fails: https://github.com/qt/qtbase/blob/v6.8.0-beta4/src/corelib/text/qregularexpression.cpp#L952-L962
The change can be reproduced with a small isolated snippet:
```c++
#include <memory>
#define Q_CONSTINIT [[clang::require_constant_initialization]]
typedef struct pcre2_jit_stack_16 pcre2_jit_stack_16;
void pcre2_jit_stack_free_16(pcre2_jit_stack_16 *stack);
struct PcreJitStackFree {
void operator()(pcre2_jit_stack_16 *stack) {
if (stack)
pcre2_jit_stack_free_16(stack);
}
};
Q_CONSTINIT std::unique_ptr<pcre2_jit_stack_16, PcreJitStackFree> jitStacks;
```
Compiling this produces the following errors:
```
$ clang++ -c repro.cpp
repro.cpp:15:67: error: variable does not have a constant initializer
15 | Q_CONSTINIT std::unique_ptr<pcre2_jit_stack_16, PcreJitStackFree> jitStacks;
| ^~~~~~~~~
repro.cpp:15:1: note: required by 'require_constant_initialization' attribute here
15 | Q_CONSTINIT std::unique_ptr<pcre2_jit_stack_16, PcreJitStackFree> jitStacks;
| ^~~~~~~~~~~
repro.cpp:3:23: note: expanded from macro 'Q_CONSTINIT'
3 | #define Q_CONSTINIT [[clang::require_constant_initialization]]
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/martin/clang-nightly/x86_64-w64-mingw32/include/c++/v1/__memory/unique_ptr.h:181:43: note: non-constexpr constructor '__compressed_pair_padding' cannot be used in a constant expression
181 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(), __deleter_() {}
| ^
repro.cpp:15:67: note: in call to 'unique_ptr<true, void>()'
15 | Q_CONSTINIT std::unique_ptr<pcre2_jit_stack_16, PcreJitStackFree> jitStacks;
| ^~~~~~~~~
/home/martin/clang-nightly/x86_64-w64-mingw32/include/c++/v1/__memory/compressed_pair.h:56:7: note: declared here
56 | class __compressed_pair_padding {
| ^
1 error generated.
```
This snippet does compile successfully in C++20 mode, but not in C++17 mode - while it did build successfully before.
https://github.com/llvm/llvm-project/pull/76756
More information about the libcxx-commits
mailing list