Diff Detail
- Repository
- rCXX libc++
- Build Status
Buildable 17710 Build 17710: arc lint + arc unit
Event Timeline
I believe this header has been deprecated. According to http://eel.is/c++draft/diff.cpp17.library, the effect of this header is nothing. @mclow.lists can you chime in?
The resolution of LWG 2828 means that <cstdalign> exists in C++11 and C++14. The rationale from https://reviews.llvm.org/D96786#2566110 can be taken as saying that adding this header for C++11 conformance is reasonable.
Yes, I agree, let's add it. But the header needs to be added in include/CMakeLists.txt. There also needs to be a test added to check for the contents of the headers, and the auto-generated header tests should be modified. Take a look at what I did in https://reviews.llvm.org/D97870 for <cuchar>.
libcxx/test/libcxx/utilities/any/size_and_alignment.pass.cpp | ||
---|---|---|
16 ↗ | (On Diff #328524) | You are right its not necessary in C++ since its a keyword. My memory of exactly why I added to this file in the original version of the CL back in 2018 is ... missing. Maybe its to ensure that the inclusion of the C header and the macro don't interfere with C++ usage? I'm happy to revert this line and find a better way to test. |
libcxx/include/cstdalign | ||
---|---|---|
19–22 ↗ | (On Diff #328524) | Done. As you can see there is not much to tests since in C++ this is essentially an empty header. |
libcxx/test/std/language.support/cstdalign/cstdalign.pass.cpp | ||
---|---|---|
8 ↗ | (On Diff #328538) | I think we should add // REQUIRES: c++03 || c++11 || c++14 || c++17, because a conforming implementation could be not shipping the header in C++20 and beyond. |
14–28 ↗ | (On Diff #328538) | This can be moved outside of main(). |
27 ↗ | (On Diff #328538) | I'm not seeing __alignof_is_defined anywhere in the spec? |
LGTM but please wait for libc++ group approval.
If you need someone to land it for you, please provide "Firstname Name <email@org>" for attribution.
libcxx/include/cstdalign | ||
---|---|---|
24 ↗ | (On Diff #328561) | This seems to be assuming that the underlying C library's stdalign.h is C++ friendly. A C11 stdalign.h does define alignof and alignas as macros. |
libcxx/test/std/language.support/cstdalign/cstdalign.pass.cpp | ||
27 ↗ | (On Diff #328538) | Seems like a defect in the old standard. The prose doesn't match the synopsis. __alignof_is_defined is a macro in C11's stdalign.h (and so is alignof). That the C++ committee did not intend for an alignof macro can probably be assumed. I suspect the lack of an __alignof_is_defined macro was also unintended. |
libcxx/include/cstdalign | ||
---|---|---|
24 ↗ | (On Diff #328561) | The idea would be to add a stdalign.h alongside this header that doesn't #include_next the underlying C library's stdalign.h. |
libcxx/test/std/language.support/cstdalign/cstdalign.pass.cpp | ||
27 ↗ | (On Diff #328538) | I think so (in addition to also checking that alignof is not defined as a macro). I think the patch needs to be confirmed again either way by the libc++ approvers though. |
libcxx/include/cstdalign | ||
---|---|---|
24 ↗ | (On Diff #328561) | I'm not sure if that should be the solution. At least gcc's libstdc++ assumes that stdalign.h is C++-compatbile (cf. https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/libstdc%2B%2B-v3/include/c_global/cstdalign). Clang provides a compatible header: https://github.com/llvm/llvm-project/commit/8acb4044d83ecc9df81b1c9f327d5bd4325e1756. MSVC's STL on the other hand, doesn't include <stdalign.h> (https://github.com/microsoft/STL/blob/main/stl/inc/cstdalign). @hubert.reinterpretcast, are you aware of an environment which has non-friendly stdalign.h? |
libcxx/include/cstdalign | ||
---|---|---|
24 ↗ | (On Diff #328561) | FYI, musl is also C++ friendly: https://git.musl-libc.org/cgit/musl/tree/include/stdalign.h. |
libcxx/include/cstdalign | ||
---|---|---|
24 ↗ | (On Diff #328561) | The one GCC provides disagrees with the interpretation I gave of which macros should be present. The one that Clang provides does match my interpretation. It seems the GCC one is non-friendly (albeit a different form of non-friendly than the one I opened with). |
libcxx/include/cstdalign | ||
---|---|---|
24 ↗ | (On Diff #328561) | Oh, you mean that __alignas_is_defined and __alignof_is_defined won't be defined in this case, right? bin/llvm-lit -vv ../../libcxx/test/std/language.support/cstdalign/ --param=std=c++17 --param=cxx_under_test=`which g++` ... libcxx/test/std/language.support/cstdalign/cstdalign.pass.cpp:21:2: error: #error __alignas_is_defined not defined 21 | #error __alignas_is_defined not defined | ^~~~~ That's unfortunately a configuration which is not tested in the CI. |
libcxx/test/std/language.support/cstdalign/cstdalign.pass.cpp | ||
16–18 ↗ | (On Diff #328561) | Please do the same for alignof. |
27 ↗ | (On Diff #328538) | Please check __alignof_is_defined as well, but guard it with #ifdef _LIBCPP_VERSION to be conforming. |
libcxx/include/cstdalign | ||
---|---|---|
24 ↗ | (On Diff #328561) | Yes, it looks like adding a stdalign.h for libc++ is needed to reliably get __alignas_is_defined and __alignof_is_defined. |
libcxx/include/cstdalign | ||
---|---|---|
24 ↗ | (On Diff #328561) | Alternatively, could we just defined them if they are not already and skip including stdalign.h here? |
libcxx/include/cstdalign | ||
---|---|---|
24 ↗ | (On Diff #328561) | stdalign.h is a header defined in C++17 like stdbool.h is one. libc++ has a stdbool.h, so I think having a stdalign.h makes sense (since we know that stdalign.h in some environments does not do what we want). |
Trying to summarize the discussion here for the author:
- Please add a <stdalign.h> header to libc++ that does #include_next <stdalign.h> and then defines both __alignof_is_defined and __alignas_is_defined.
- Please re-add a test checking for __alignof_is_defined, but guard it with #if defined(_LIBCPP_VER) so that we only test it on libc++ (since technically the Standard doesn't require it, even if it's a defect).
- Please re-run libcxx/utils/generate_header_tests.py and make sure that creates no diff.
libcxx/include/cstdalign | ||
---|---|---|
24 ↗ | (On Diff #328561) | However, http://eel.is/c++draft/depr.stdalign.h.syn#1 says:
I think the most efficient way of ensuring that is to use #include_next, which requires a C++ friendly <stdalign.h> on the platform. Generally speaking, I'm not in favour of trying to work around platforms that do not provide C++ friendly headers. If we're trying to make C++ work on those platforms, they need to minimally provide C++ friendly headers. |