Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++] Deprecate and remove meaningless <cxxx> headers #111615

Merged
merged 26 commits into from
Oct 30, 2024

Conversation

frederick-vs-ja
Copy link
Contributor

@frederick-vs-ja frederick-vs-ja commented Oct 9, 2024

This PR deprecates <ccomplex>, <cstdbool>, <ctgmath>, and <ciso646> in C++17 and "removes" them in C++20 by special deprecation warnings.

<cstdalign> is previously missing. This PR also tries to add them, and then deprecates and "removes" <cstdalign>.

Papers:

Closes #99985.

`<ccomplex>`, `<cstdbool>`, `<ctgmath>`, and `<ciso646>` are deprecated
and "removed" by special deprecation warnings. `<cstdalign>` is
currently missing.
@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner October 9, 2024 02:01
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Oct 9, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 9, 2024

@llvm/pr-subscribers-libcxx

Author: A. Jiang (frederick-vs-ja)

Changes

This PR deprecates &lt;ccomplex&gt;, &lt;cstdbool&gt;, &lt;ctgmath&gt;, and &lt;ciso646&gt; in C++17 and "removes" them in C++20 by special deprecation warnings.

&lt;cstdalign&gt; and &lt;stdalign.h&gt; are previously missing. This PR also tries to add them, and then deprecates and "removes" &lt;cstdalign&gt;.

Closes #99985.


Patch is 21.59 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/111615.diff

25 Files Affected:

  • (modified) libcxx/docs/ReleaseNotes/20.rst (+6-1)
  • (modified) libcxx/docs/Status/Cxx17Papers.csv (+1-1)
  • (modified) libcxx/docs/Status/Cxx20Papers.csv (+1-1)
  • (modified) libcxx/include/CMakeLists.txt (+2)
  • (modified) libcxx/include/ccomplex (+13)
  • (modified) libcxx/include/ciso646 (+5)
  • (added) libcxx/include/cstdalign (+48)
  • (modified) libcxx/include/cstdbool (+13)
  • (modified) libcxx/include/ctgmath (+13)
  • (modified) libcxx/include/module.modulemap (+9)
  • (added) libcxx/include/stdalign.h (+42)
  • (modified) libcxx/test/libcxx/include_as_c.sh.cpp (+1)
  • (modified) libcxx/test/std/depr/depr.c.headers/ciso646.compile.pass.cpp (+3-1)
  • (added) libcxx/test/std/depr/depr.c.headers/stdalign_h.compile.pass.cpp (+27)
  • (added) libcxx/test/std/depr/depr.cpp.headers/ccomplex.verify.cpp (+21)
  • (added) libcxx/test/std/depr/depr.cpp.headers/ciso646.verify.cpp (+17)
  • (added) libcxx/test/std/depr/depr.cpp.headers/cstdalign.verify.cpp (+21)
  • (added) libcxx/test/std/depr/depr.cpp.headers/cstdbool.verify.cpp (+21)
  • (added) libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp (+21)
  • (added) libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp (+31)
  • (modified) libcxx/test/std/language.support/support.runtime/cstdbool.pass.cpp (+3-1)
  • (modified) libcxx/test/std/numerics/c.math/ctgmath.pass.cpp (+3-1)
  • (modified) libcxx/test/std/numerics/complex.number/ccmplx/ccomplex.pass.cpp (+3-1)
  • (modified) libcxx/utils/libcxx/header_information.py (+1-1)
  • (modified) llvm/utils/gn/secondary/libcxx/include/BUILD.gn (+2)
diff --git a/libcxx/docs/ReleaseNotes/20.rst b/libcxx/docs/ReleaseNotes/20.rst
index 82c8286b69e23c..a65367d9b62c81 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>``, ``<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 3b56807312d556..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",""
+"`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/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/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/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/cstdalign b/libcxx/include/cstdalign
new file mode 100644
index 00000000000000..2d9187cdbfe8ac
--- /dev/null
+++ b/libcxx/include/cstdalign
@@ -0,0 +1,48 @@
+// -*- 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
+
+#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/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/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/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.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/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/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/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/cstdalign.pass.cpp b/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp
new file mode 100644
index 00000000000000..186cd1e1c8bee8
--- /dev/null
+++ b/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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> // 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>
+
+#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/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 @@
 //
 //===-------...
[truncated]

Copy link

github-actions bot commented Oct 9, 2024

✅ With the latest revision this PR passed the Python code formatter.

Copy link

github-actions bot commented Oct 9, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also consider removing most of the headers as a DR. Most of these headers are likely almost never used in the wild except for <ciso646> (as our missing <cstdalign> shows). @ldionne @jwakely @stl any thoughts?

libcxx/include/stdalign.h Outdated Show resolved Hide resolved
Comment on lines 26 to 37
#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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a very complex way of writing

#if defined(__DEPRECATED) && __DEPRECATED
#  warning "<ccomplex> is deprecated"
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're only doing this for <hash_map> & <hash_set>. I guess the deprecation warnings should be controllable by _LIBCPP_DISABLE_DEPRECATION_WARNINGS (which is mentioned in __config).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we should probably slap a && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we need to switch back to the [[deprecated]]-based method...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frederick-vs-ja Does that solve the issue with modules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that works as CI is green now.

libcxx/include/ciso646 Outdated Show resolved Hide resolved
@jwakely
Copy link
Contributor

jwakely commented Oct 10, 2024

I don't think we'll ever physically remove these from libstdc++, nor make including them a hard error, certainly not as a DR. But I should add #warning to them saying they're deprecated/removed.

libcxx/include/stdalign.h Outdated Show resolved Hide resolved
Comment on lines 26 to 37
#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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we should probably slap a && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) at the end.

libcxx/include/cstdalign Show resolved Hide resolved
libcxx/docs/ReleaseNotes/20.rst Show resolved Hide resolved
libcxx/docs/Status/Cxx17Papers.csv Outdated Show resolved Hide resolved
@@ -23,4 +23,12 @@
# pragma GCC system_header
#endif

#if _LIBCPP_STD_VER >= 17 && defined(__DEPRECATED) && __DEPRECATED && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of checking __DEPRECATED here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's so people don't get deprecation warnings when specifying -Wno-deprecated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we instead set _LIBCPP_DISABLE_DEPRECATION_WARNINGS when -Wno-deprecated is passed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. You can have -Wno-deprecated -Wdeprecated-declarations, which disables deprecation warnings but keeps [[deprecated]] warnings. I'm not sure it makes a ton of sense to support this weird combination either though.

libcxx/include/tgmath.h Outdated Show resolved Hide resolved
libcxx/include/complex.h Outdated Show resolved Hide resolved
libcxx/test/std/depr/depr.cpp.headers/ciso646.verify.cpp Outdated Show resolved Hide resolved
libcxx/docs/ReleaseNotes/20.rst Outdated Show resolved Hide resolved
frederick-vs-ja and others added 3 commits October 22, 2024 22:06
# Conflicts:
#	libcxx/test/libcxx/header_inclusions.gen.py
#	libcxx/utils/libcxx/header_information.py
@ldionne
Copy link
Member

ldionne commented Oct 22, 2024

I'm fine with the patch in principle, but we do have a problem that the modules for these now-deprecated headers get built whenever the std module is built, which breaks the compilation of anything that builds the std module. I pulled this down locally to play around and even making these modules explicit module ccomplex doesn't fix the issue, so I'm not certain how to fix this.

@ian-twilightcoder Do you have ideas? Basically, the TLDR is that we have headers that now contain an unconditional #warning directive and we'd like these headers not to be pulled into the std module's compilation unless they are requested explicitly. Making these headers textual solves the problem but that seems like a hack.

@ian-twilightcoder
Copy link
Contributor

I'm fine with the patch in principle, but we do have a problem that the modules for these now-deprecated headers get built whenever the std module is built, which breaks the compilation of anything that builds the std module. I pulled this down locally to play around and even making these modules explicit module ccomplex doesn't fix the issue, so I'm not certain how to fix this.

@ian-twilightcoder Do you have ideas? Basically, the TLDR is that we have headers that now contain an unconditional #warning directive and we'd like these headers not to be pulled into the std module's compilation unless they are requested explicitly. Making these headers textual solves the problem but that seems like a hack.

You really can't use #error or #warning in modules because the headers all build with the module, and there's no way to trigger a diagnostic on import rather than during build. textual will cause issues with duplicate declarations, that can only really be used if 1) there aren't declarations (e.g. x-macro headers) or 2) there is only one includer.

So for now I think you have to check if modules are enabled and don't #warning. We're investigating syntax to mark submodules as deprecated, and also entire headers.

@ldionne
Copy link
Member

ldionne commented Oct 22, 2024

Thanks for the information. It's unfortunate that there isn't a way to do this right now.

libcxx/include/ccomplex Outdated Show resolved Hide resolved
// When built with modules, <ciso646> should be omitted.

// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: clang-modules-build
Copy link
Member

@ldionne ldionne Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, these diagnostics are not emitted under Clang modules? So then the clever using _LIBCPP_DEPRECATED(...) approach is equivalent to

#if !__has_feature(cxx_modules) // whatever the right way of checking that is
# warning "this header is deprecated"
#endif

I'm not super strongly attached, but I do think that using a plain #warning makes this easier to understand than the clever using trick.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__has_feature(modules) We want this for clang modules and cxx_modules is C++20 modules

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid that currently we can't reliably detect -fmodules, as __has_feature(modules) is currently 1 in C++20 mode even when -fno-modules is used, see #57432.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we use #if __building_module(std)?

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@frederick-vs-ja frederick-vs-ja merged commit 63eb40e into llvm:main Oct 30, 2024
65 checks passed
@frederick-vs-ja frederick-vs-ja deleted the cxx20-removed-headers branch October 30, 2024 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

P0619R4: Reviewing Deprecated Facilities of C++17 for C++20
6 participants