[libcxx] [llvm] [libc++] Deprecate and remove meaningless `<cxxx>` headers (PR #111615)
A. Jiang via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 8 19:01:15 PDT 2024
https://github.com/frederick-vs-ja created https://github.com/llvm/llvm-project/pull/111615
This PR deprecates `<ccomplex>`, `<cstdbool>`, `<ctgmath>`, and `<ciso646>` in C++17 and "removes" them in C++20 by special deprecation warnings.
`<cstdalign>` and `<stdalign.h>` are previously missing. This PR also tries to add them, and then deprecates and "removes" `<cstdalign>`.
Closes #99985.
>From cd7e179a34a3696cc8b6f0c1db940b842a9ce3d1 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 9 Oct 2024 09:52:29 +0800
Subject: [PATCH 1/3] [libc++] Deprecate and remove meaningless `<cxxx>`
headers
`<ccomplex>`, `<cstdbool>`, `<ctgmath>`, and `<ciso646>` are deprecated
and "removed" by special deprecation warnings. `<cstdalign>` is
currently missing.
---
libcxx/docs/ReleaseNotes/20.rst | 7 ++++++-
libcxx/docs/Status/Cxx17Papers.csv | 2 +-
libcxx/docs/Status/Cxx20Papers.csv | 2 +-
libcxx/include/ccomplex | 13 ++++++++++++
libcxx/include/ciso646 | 5 +++++
libcxx/include/cstdbool | 13 ++++++++++++
libcxx/include/ctgmath | 13 ++++++++++++
.../depr.c.headers/ciso646.compile.pass.cpp | 4 +++-
.../depr/depr.cpp.headers/ccomplex.verify.cpp | 21 +++++++++++++++++++
.../depr/depr.cpp.headers/ciso646.verify.cpp | 17 +++++++++++++++
.../depr/depr.cpp.headers/cstdbool.verify.cpp | 21 +++++++++++++++++++
.../depr/depr.cpp.headers/ctgmath.verify.cpp | 21 +++++++++++++++++++
.../support.runtime/cstdbool.pass.cpp | 4 +++-
.../test/std/numerics/c.math/ctgmath.pass.cpp | 4 +++-
.../complex.number/ccmplx/ccomplex.pass.cpp | 4 +++-
15 files changed, 144 insertions(+), 7 deletions(-)
create mode 100644 libcxx/test/std/depr/depr.cpp.headers/ccomplex.verify.cpp
create mode 100644 libcxx/test/std/depr/depr.cpp.headers/ciso646.verify.cpp
create mode 100644 libcxx/test/std/depr/depr.cpp.headers/cstdbool.verify.cpp
create mode 100644 libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp
diff --git a/libcxx/docs/ReleaseNotes/20.rst b/libcxx/docs/ReleaseNotes/20.rst
index 82c8286b69e23c..22f98bb1a2089a 100644
--- a/libcxx/docs/ReleaseNotes/20.rst
+++ b/libcxx/docs/ReleaseNotes/20.rst
@@ -38,8 +38,9 @@ What's New in Libc++ 20.0.0?
Implemented Papers
------------------
-- P2747R2: ``constexpr`` placement new (`Github <https://github.com/llvm/llvm-project/issues/105427>`__)
+- P0619R4: Reviewing Deprecated Facilities of C++17 for C++20 (`Github <https://github.com/llvm/llvm-project/issues/99985>`__)
- P2609R3: Relaxing Ranges Just A Smidge (`Github <https://github.com/llvm/llvm-project/issues/105253>`__)
+- P2747R2: ``constexpr`` placement new (`Github <https://github.com/llvm/llvm-project/issues/105427>`__)
- P2985R0: A type trait for detecting virtual base classes (`Github <https://github.com/llvm/llvm-project/issues/105432>`__)
- ``std::jthread`` and ``<stop_token>`` are not guarded behind ``-fexperimental-library`` anymore
@@ -77,6 +78,10 @@ Deprecations and Removals
supported as an extension anymore, please migrate any code that uses e.g. ``std::vector<const T>`` to be
standards conforming.
+- ``<ccomplex>``, ``<cstdbool>``, and ``<ctgmath>`` are deprecated since C++17 as specified by the standard. They,
+ together with ``<ciso646>``, are removed in C++20, but libc++ still provides these headers as an extension and only
+ deprecates them.
+
Upcoming Deprecations and Removals
----------------------------------
diff --git a/libcxx/docs/Status/Cxx17Papers.csv b/libcxx/docs/Status/Cxx17Papers.csv
index 3b56807312d556..feb2c68f60cb46 100644
--- a/libcxx/docs/Status/Cxx17Papers.csv
+++ b/libcxx/docs/Status/Cxx17Papers.csv
@@ -43,7 +43,7 @@
"","","","","",""
"`P0032R3 <https://wg21.link/P0032R3>`__","Homogeneous interface for variant, any and optional","2016-06 (Oulu)","|Complete|","4.0",""
"`P0040R3 <https://wg21.link/P0040R3>`__","Extending memory management tools","2016-06 (Oulu)","|Complete|","4.0",""
-"`P0063R3 <https://wg21.link/P0063R3>`__","C++17 should refer to C11 instead of C99","2016-06 (Oulu)","|Complete|","7.0",""
+"`P0063R3 <https://wg21.link/P0063R3>`__","C++17 should refer to C11 instead of C99","2016-06 (Oulu)","|Complete|","7.0","``<ccomplex>``, ``<cstdbool>``, and ``<ctgmath>`` are deprecated since LLVM 20."
"`P0067R3 <https://wg21.link/P0067R3>`__","Elementary string conversions","2016-06 (Oulu)","|Nothing To Do|","n/a","Resolved by `P0067R5 <https://wg21.link/P0067R5>`__"
"`P0083R3 <https://wg21.link/P0083R3>`__","Splicing Maps and Sets","2016-06 (Oulu)","|Complete|","8.0",""
"`P0084R2 <https://wg21.link/P0084R2>`__","Emplace Return Type","2016-06 (Oulu)","|Complete|","4.0",""
diff --git a/libcxx/docs/Status/Cxx20Papers.csv b/libcxx/docs/Status/Cxx20Papers.csv
index cc75d28f14aac2..daa611ccd6fded 100644
--- a/libcxx/docs/Status/Cxx20Papers.csv
+++ b/libcxx/docs/Status/Cxx20Papers.csv
@@ -34,7 +34,7 @@
"`P0528R3 <https://wg21.link/P0528R3>`__","The Curious Case of Padding Bits, Featuring Atomic Compare-and-Exchange","2018-06 (Rapperswil)","","",""
"`P0542R5 <https://wg21.link/P0542R5>`__","Support for contract based programming in C++","2018-06 (Rapperswil)","|Nothing To Do|","n/a","Pulled at the 2019-07 meeting in Cologne"
"`P0556R3 <https://wg21.link/P0556R3>`__","Integral power-of-2 operations","2018-06 (Rapperswil)","|Complete|","9.0",""
-"`P0619R4 <https://wg21.link/P0619R4>`__","Reviewing Deprecated Facilities of C++17 for C++20","2018-06 (Rapperswil)","|Partial|","","Only sections D.7, D.8, D.9, D.10, D.11, D.12, and D.13 are implemented. Section D.4 remains undone."
+"`P0619R4 <https://wg21.link/P0619R4>`__","Reviewing Deprecated Facilities of C++17 for C++20","2018-06 (Rapperswil)","|Complete|","20.0","Removed headers are still provided as an extension, but with deprecation warnings"
"`P0646R1 <https://wg21.link/P0646R1>`__","Improving the Return Value of Erase-Like Algorithms","2018-06 (Rapperswil)","|Complete|","10.0",""
"`P0722R3 <https://wg21.link/P0722R3>`__","Efficient sized delete for variable sized classes","2018-06 (Rapperswil)","|Complete|","9.0",""
"`P0758R1 <https://wg21.link/P0758R1>`__","Implicit conversion traits and utility functions","2018-06 (Rapperswil)","|Complete|","",""
diff --git a/libcxx/include/ccomplex b/libcxx/include/ccomplex
index 94d2c8d7d003d4..e498e06cad20a0 100644
--- a/libcxx/include/ccomplex
+++ b/libcxx/include/ccomplex
@@ -23,4 +23,17 @@
# pragma GCC system_header
#endif
+#if _LIBCPP_STD_VER >= 17
+# if _LIBCPP_STD_VER >= 20
+# define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED_("removed in C++20")
+# else
+# define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED
+# endif
+
+using __standard_header_ccomplex _DEPRECATION_ANNOTATION = void;
+using __use_standard_header_ccomplex = __standard_header_ccomplex;
+
+# undef _DEPRECATION_ANNOTATION
+#endif
+
#endif // _LIBCPP_CCOMPLEX
diff --git a/libcxx/include/ciso646 b/libcxx/include/ciso646
index 1d859f08fac572..4fd409ae9c6666 100644
--- a/libcxx/include/ciso646
+++ b/libcxx/include/ciso646
@@ -21,4 +21,9 @@
# pragma GCC system_header
#endif
+#if _LIBCPP_STD_VER >= 20
+using __standard_header_ciso646 _LIBCPP_DEPRECATED_("removed in C++20") = void;
+using __use_standard_header_ciso646 = __standard_header_ciso646;
+#endif
+
#endif // _LIBCPP_CISO646
diff --git a/libcxx/include/cstdbool b/libcxx/include/cstdbool
index ef731c021a4ab8..decd9ee6e9cece 100644
--- a/libcxx/include/cstdbool
+++ b/libcxx/include/cstdbool
@@ -28,4 +28,17 @@ Macros:
#undef __bool_true_false_are_defined
#define __bool_true_false_are_defined 1
+#if _LIBCPP_STD_VER >= 17
+# if _LIBCPP_STD_VER >= 20
+# define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED_("removed in C++20")
+# else
+# define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED
+# endif
+
+using __standard_header_cstdbool _DEPRECATION_ANNOTATION = void;
+using __use_standard_header_cstdbool = __standard_header_cstdbool;
+
+# undef _DEPRECATION_ANNOTATION
+#endif
+
#endif // _LIBCPP_CSTDBOOL
diff --git a/libcxx/include/ctgmath b/libcxx/include/ctgmath
index 6237979be4906c..370470576bd3d7 100644
--- a/libcxx/include/ctgmath
+++ b/libcxx/include/ctgmath
@@ -25,4 +25,17 @@
# pragma GCC system_header
#endif
+#if _LIBCPP_STD_VER >= 17
+# if _LIBCPP_STD_VER >= 20
+# define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED_("removed in C++20")
+# else
+# define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED
+# endif
+
+using __standard_header_ctgmath _DEPRECATION_ANNOTATION = void;
+using __use_standard_header_ctgmath = __standard_header_ctgmath;
+
+# undef _DEPRECATION_ANNOTATION
+#endif
+
#endif // _LIBCPP_CTGMATH
diff --git a/libcxx/test/std/depr/depr.c.headers/ciso646.compile.pass.cpp b/libcxx/test/std/depr/depr.c.headers/ciso646.compile.pass.cpp
index 4dff57f84f202c..764f4d02f44f44 100644
--- a/libcxx/test/std/depr/depr.c.headers/ciso646.compile.pass.cpp
+++ b/libcxx/test/std/depr/depr.c.headers/ciso646.compile.pass.cpp
@@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
-// <ciso646>
+// <ciso646> // removed in C++20, but still provided by libc++ as an extension
+
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
#include <ciso646>
diff --git a/libcxx/test/std/depr/depr.cpp.headers/ccomplex.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/ccomplex.verify.cpp
new file mode 100644
index 00000000000000..e012b5fd5d28ba
--- /dev/null
+++ b/libcxx/test/std/depr/depr.cpp.headers/ccomplex.verify.cpp
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <ccomplex>
+
+// check that <ccomplex> is deprecated in C++17 and removed in C++20
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 20
+# include <ccomplex> // expected-warning {{'__standard_header_ccomplex' is deprecated: removed in C++20}}
+#else
+# include <ccomplex> // expected-warning {{'__standard_header_ccomplex' is deprecated}}
+#endif
diff --git a/libcxx/test/std/depr/depr.cpp.headers/ciso646.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/ciso646.verify.cpp
new file mode 100644
index 00000000000000..2f84fd13b96698
--- /dev/null
+++ b/libcxx/test/std/depr/depr.cpp.headers/ciso646.verify.cpp
@@ -0,0 +1,17 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <ciso646>
+
+// check that <ciso646> is removed in C++20
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+#include "test_macros.h"
+
+#include <ciso646> // expected-warning {{'__standard_header_ciso646' is deprecated: removed in C++20}}
diff --git a/libcxx/test/std/depr/depr.cpp.headers/cstdbool.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/cstdbool.verify.cpp
new file mode 100644
index 00000000000000..99073ce0c9d091
--- /dev/null
+++ b/libcxx/test/std/depr/depr.cpp.headers/cstdbool.verify.cpp
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <cstdbool>
+
+// check that <cstdbool> is deprecated in C++17 and removed in C++20
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 20
+# include <cstdbool> // expected-warning {{'__standard_header_cstdbool' is deprecated: removed in C++20}}
+#else
+# include <cstdbool> // expected-warning {{'__standard_header_cstdbool' is deprecated}}
+#endif
diff --git a/libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp
new file mode 100644
index 00000000000000..f2b77f2b0c7905
--- /dev/null
+++ b/libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <ctgmath>
+
+// check that <ctgmath> is deprecated in C++17 and removed in C++20
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 20
+# include <ctgmath> // expected-warning {{'__standard_header_ctgmath' is deprecated: removed in C++20}}
+#else
+# include <ctgmath> // expected-warning {{'__standard_header_ctgmath' is deprecated}}
+#endif
diff --git a/libcxx/test/std/language.support/support.runtime/cstdbool.pass.cpp b/libcxx/test/std/language.support/support.runtime/cstdbool.pass.cpp
index 1d0e9b06a43d2e..9a35eea507c40a 100644
--- a/libcxx/test/std/language.support/support.runtime/cstdbool.pass.cpp
+++ b/libcxx/test/std/language.support/support.runtime/cstdbool.pass.cpp
@@ -6,7 +6,9 @@
//
//===----------------------------------------------------------------------===//
-// test <cstdbool>
+// test <cstdbool> // deprecated in C++17, removed in C++20, but still provided by libc++ as an extension
+
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
#include <cstdbool>
diff --git a/libcxx/test/std/numerics/c.math/ctgmath.pass.cpp b/libcxx/test/std/numerics/c.math/ctgmath.pass.cpp
index 2c8d054fbc527d..2e4679980577a9 100644
--- a/libcxx/test/std/numerics/c.math/ctgmath.pass.cpp
+++ b/libcxx/test/std/numerics/c.math/ctgmath.pass.cpp
@@ -6,7 +6,9 @@
//
//===----------------------------------------------------------------------===//
-// <ctgmath>
+// <ctgmath> // deprecated in C++17, removed in C++20, but still provided by libc++ as an extension
+
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
#include <ctgmath>
diff --git a/libcxx/test/std/numerics/complex.number/ccmplx/ccomplex.pass.cpp b/libcxx/test/std/numerics/complex.number/ccmplx/ccomplex.pass.cpp
index cc3f8cd6a9beb9..0ed116c6410639 100644
--- a/libcxx/test/std/numerics/complex.number/ccmplx/ccomplex.pass.cpp
+++ b/libcxx/test/std/numerics/complex.number/ccmplx/ccomplex.pass.cpp
@@ -6,7 +6,9 @@
//
//===----------------------------------------------------------------------===//
-// <ccomplex>
+// <ccomplex> // deprecated in C++17, removed in C++20, but still provided by libc++ as an extension
+
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
#include <ccomplex>
>From a7fdda0b0ff2c9012e14163f5f55dff8ba1dab86 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 9 Oct 2024 09:52:54 +0800
Subject: [PATCH 2/3] [libc++] Add missed `<cstdalign>` and `<stdalign.h>`
headers
---
libcxx/include/CMakeLists.txt | 2 +
libcxx/include/cstdalign | 35 ++++++++++++++++
libcxx/include/module.modulemap | 9 ++++
libcxx/include/stdalign.h | 42 +++++++++++++++++++
libcxx/test/libcxx/include_as_c.sh.cpp | 1 +
.../stdalign_h.compile.pass.cpp | 27 ++++++++++++
.../support.runtime/cstdalign.pass.cpp | 29 +++++++++++++
libcxx/utils/libcxx/header_information.py | 2 +-
.../gn/secondary/libcxx/include/BUILD.gn | 2 +
9 files changed, 148 insertions(+), 1 deletion(-)
create mode 100644 libcxx/include/cstdalign
create mode 100644 libcxx/include/stdalign.h
create mode 100644 libcxx/test/std/depr/depr.c.headers/stdalign_h.compile.pass.cpp
create mode 100644 libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 9bd1b41b8bfac4..118a5bd82fbe90 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -909,6 +909,7 @@ set(files
coroutine
csetjmp
csignal
+ cstdalign
cstdarg
cstdbool
cstddef
@@ -992,6 +993,7 @@ set(files
span
sstream
stack
+ stdalign.h
stdatomic.h
stdbool.h
stddef.h
diff --git a/libcxx/include/cstdalign b/libcxx/include/cstdalign
new file mode 100644
index 00000000000000..4ab973374130ce
--- /dev/null
+++ b/libcxx/include/cstdalign
@@ -0,0 +1,35 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CSTDALIGN
+#define _LIBCPP_CSTDALIGN
+
+/*
+ cstdalign synopsis
+
+Macros:
+
+ __alignas_is_defined
+ __alignof_is_defined
+
+*/
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+#undef __alignas_is_defined
+#define __alignas_is_defined 1
+
+#undef __alignof_is_defined
+#define __alignof_is_defined 1
+
+#endif // _LIBCPP_CSTDALIGN
diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index dee9b0b88b7948..f472335160bd84 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -1103,6 +1103,11 @@ module std [system] {
export *
}
+ module cstdalign {
+ header "cstdalign"
+ export *
+ }
+
module cstdarg {
header "cstdarg"
export *
@@ -2187,6 +2192,10 @@ module std_math_h [system] {
header "math.h"
export *
}
+module std_stdalign_h [system] {
+ // <stdalign.h>'s __alignas_is_defined and __alignof_is_defined macros require textual inclusion.
+ textual header "stdalign.h"
+}
module std_stdatomic_h [system] {
header "stdatomic.h"
export *
diff --git a/libcxx/include/stdalign.h b/libcxx/include/stdalign.h
new file mode 100644
index 00000000000000..eb03f665151bd7
--- /dev/null
+++ b/libcxx/include/stdalign.h
@@ -0,0 +1,42 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_STDALIGN_H
+#define _LIBCPP_STDALIGN_H
+
+/*
+ stdalign.h synopsis
+
+Macros:
+
+ __alignas_is_defined
+ __alignof_is_defined
+
+*/
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+#if __has_include_next(<stdalign.h>)
+# include_next <stdalign.h>
+#endif
+
+#ifdef __cplusplus
+# undef alignas
+# undef alignof
+# undef __alignas_is_defined
+# undef __alignof_is_defined
+# define __alignas_is_defined 1
+# define __alignof_is_defined 1
+#endif
+
+#endif // _LIBCPP_STDALIGN_H
diff --git a/libcxx/test/libcxx/include_as_c.sh.cpp b/libcxx/test/libcxx/include_as_c.sh.cpp
index c9f8dfd9a5a922..204b830462cf94 100644
--- a/libcxx/test/libcxx/include_as_c.sh.cpp
+++ b/libcxx/test/libcxx/include_as_c.sh.cpp
@@ -34,6 +34,7 @@
#endif
#include <math.h>
#include <setjmp.h>
+#include <stdalign.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stddef.h>
diff --git a/libcxx/test/std/depr/depr.c.headers/stdalign_h.compile.pass.cpp b/libcxx/test/std/depr/depr.c.headers/stdalign_h.compile.pass.cpp
new file mode 100644
index 00000000000000..0f1cf487d60f6d
--- /dev/null
+++ b/libcxx/test/std/depr/depr.c.headers/stdalign_h.compile.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// test <stdalign.h>
+
+#include <stdalign.h>
+
+#ifndef __alignas_is_defined
+# error __alignas_is_defined not defined
+#endif
+
+#ifndef __alignof_is_defined
+# error __alignof_is_defined not defined
+#endif
+
+#ifdef alignas
+# error alignas should not be defined
+#endif
+
+#ifdef alignof
+# error alignof should not be defined
+#endif
diff --git a/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp b/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp
new file mode 100644
index 00000000000000..6b64fa575de2a9
--- /dev/null
+++ b/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// test <cstdalign>
+
+#include <cstdalign>
+
+#ifndef __alignas_is_defined
+# error __alignas_is_defined not defined
+#endif
+
+#ifndef __alignof_is_defined
+# error __alignof_is_defined not defined
+#endif
+
+#ifdef alignas
+# error alignas should not be defined
+#endif
+
+#ifdef alignof
+# error alignof should not be defined
+#endif
+
+int main(int, char**) { return 0; }
diff --git a/libcxx/utils/libcxx/header_information.py b/libcxx/utils/libcxx/header_information.py
index fd48b35a88b558..1431ef2bfdc5ca 100644
--- a/libcxx/utils/libcxx/header_information.py
+++ b/libcxx/utils/libcxx/header_information.py
@@ -202,7 +202,7 @@ def is_modulemap_header(header):
for header in toplevel_headers
if not header.endswith(".h") and is_public_header(header)
# These headers have been removed in C++20 so are never part of a module.
- and not header in ["ccomplex", "ciso646", "cstdbool", "ctgmath"]
+ and not header in ["ccomplex", "ciso646", "cstdalign", "cstdbool", "ctgmath"]
]
# The C headers used in the std and std.compat modules.
diff --git a/llvm/utils/gn/secondary/libcxx/include/BUILD.gn b/llvm/utils/gn/secondary/libcxx/include/BUILD.gn
index d850a7f20952d9..12945c91fff9d0 100644
--- a/llvm/utils/gn/secondary/libcxx/include/BUILD.gn
+++ b/llvm/utils/gn/secondary/libcxx/include/BUILD.gn
@@ -981,6 +981,7 @@ if (current_toolchain == default_toolchain) {
"coroutine",
"csetjmp",
"csignal",
+ "cstdalign",
"cstdarg",
"cstdbool",
"cstddef",
@@ -1064,6 +1065,7 @@ if (current_toolchain == default_toolchain) {
"span",
"sstream",
"stack",
+ "stdalign.h",
"stdatomic.h",
"stdbool.h",
"stddef.h",
>From fdf253d82e5bb05d06676606795a827b06ab8745 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 9 Oct 2024 09:54:06 +0800
Subject: [PATCH 3/3] [libc++] Deprecate and remove `<cstdalign>`
---
libcxx/docs/ReleaseNotes/20.rst | 6 +++---
libcxx/docs/Status/Cxx17Papers.csv | 2 +-
libcxx/include/cstdalign | 13 ++++++++++++
.../depr.cpp.headers/cstdalign.verify.cpp | 21 +++++++++++++++++++
.../support.runtime/cstdalign.pass.cpp | 4 +++-
5 files changed, 41 insertions(+), 5 deletions(-)
create mode 100644 libcxx/test/std/depr/depr.cpp.headers/cstdalign.verify.cpp
diff --git a/libcxx/docs/ReleaseNotes/20.rst b/libcxx/docs/ReleaseNotes/20.rst
index 22f98bb1a2089a..a65367d9b62c81 100644
--- a/libcxx/docs/ReleaseNotes/20.rst
+++ b/libcxx/docs/ReleaseNotes/20.rst
@@ -78,9 +78,9 @@ Deprecations and Removals
supported as an extension anymore, please migrate any code that uses e.g. ``std::vector<const T>`` to be
standards conforming.
-- ``<ccomplex>``, ``<cstdbool>``, and ``<ctgmath>`` are deprecated since C++17 as specified by the standard. They,
- together with ``<ciso646>``, are removed in C++20, but libc++ still provides these headers as an extension and only
- deprecates them.
+- ``<ccomplex>``, ``<cstdalign>`` (previously missing), ``<cstdbool>``, and ``<ctgmath>`` are deprecated since C++17 as
+ specified by the standard. They, together with ``<ciso646>``, are removed in C++20, but libc++ still provides these
+ headers as an extension and only deprecates them.
Upcoming Deprecations and Removals
----------------------------------
diff --git a/libcxx/docs/Status/Cxx17Papers.csv b/libcxx/docs/Status/Cxx17Papers.csv
index feb2c68f60cb46..3058fd44c7250f 100644
--- a/libcxx/docs/Status/Cxx17Papers.csv
+++ b/libcxx/docs/Status/Cxx17Papers.csv
@@ -43,7 +43,7 @@
"","","","","",""
"`P0032R3 <https://wg21.link/P0032R3>`__","Homogeneous interface for variant, any and optional","2016-06 (Oulu)","|Complete|","4.0",""
"`P0040R3 <https://wg21.link/P0040R3>`__","Extending memory management tools","2016-06 (Oulu)","|Complete|","4.0",""
-"`P0063R3 <https://wg21.link/P0063R3>`__","C++17 should refer to C11 instead of C99","2016-06 (Oulu)","|Complete|","7.0","``<ccomplex>``, ``<cstdbool>``, and ``<ctgmath>`` are deprecated since LLVM 20."
+"`P0063R3 <https://wg21.link/P0063R3>`__","C++17 should refer to C11 instead of C99","2016-06 (Oulu)","|Complete|","7.0","``<ccomplex>``, ``<cstdalign>``, ``<cstdbool>``, and ``<ctgmath>`` are deprecated since LLVM 20."
"`P0067R3 <https://wg21.link/P0067R3>`__","Elementary string conversions","2016-06 (Oulu)","|Nothing To Do|","n/a","Resolved by `P0067R5 <https://wg21.link/P0067R5>`__"
"`P0083R3 <https://wg21.link/P0083R3>`__","Splicing Maps and Sets","2016-06 (Oulu)","|Complete|","8.0",""
"`P0084R2 <https://wg21.link/P0084R2>`__","Emplace Return Type","2016-06 (Oulu)","|Complete|","4.0",""
diff --git a/libcxx/include/cstdalign b/libcxx/include/cstdalign
index 4ab973374130ce..2d9187cdbfe8ac 100644
--- a/libcxx/include/cstdalign
+++ b/libcxx/include/cstdalign
@@ -32,4 +32,17 @@ Macros:
#undef __alignof_is_defined
#define __alignof_is_defined 1
+#if _LIBCPP_STD_VER >= 17
+# if _LIBCPP_STD_VER >= 20
+# define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED_("removed in C++20")
+# else
+# define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED
+# endif
+
+using __standard_header_cstdalign _DEPRECATION_ANNOTATION = void;
+using __use_standard_header_cstdalign = __standard_header_cstdalign;
+
+# undef _DEPRECATION_ANNOTATION
+#endif
+
#endif // _LIBCPP_CSTDALIGN
diff --git a/libcxx/test/std/depr/depr.cpp.headers/cstdalign.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/cstdalign.verify.cpp
new file mode 100644
index 00000000000000..c73f183640a6e1
--- /dev/null
+++ b/libcxx/test/std/depr/depr.cpp.headers/cstdalign.verify.cpp
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <cstdalign>
+
+// check that <cstdalign> is deprecated in C++17 and removed in C++20
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 20
+# include <cstdalign> // expected-warning {{'__standard_header_cstdalign' is deprecated: removed in C++20}}
+#else
+# include <cstdalign> // expected-warning {{'__standard_header_cstdalign' is deprecated}}
+#endif
diff --git a/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp b/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp
index 6b64fa575de2a9..186cd1e1c8bee8 100644
--- a/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp
+++ b/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp
@@ -6,7 +6,9 @@
//
//===----------------------------------------------------------------------===//
-// test <cstdalign>
+// test <cstdalign> // deprecated in C++17, removed in C++20, but still provided by libc++ as an extension
+
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
#include <cstdalign>
More information about the llvm-commits
mailing list