Skip to content

Commit 63eb40e

Browse files
[libc++] Deprecate and remove meaningless <cxxx> headers (#111615)
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: - https://wg21.link/P0063R3 - https://wg21.link/P0619R4 Closes #99985. --------- Co-authored-by: Louis Dionne <[email protected]>
1 parent 8800b73 commit 63eb40e

38 files changed

+394
-44
lines changed

libcxx/docs/ReleaseNotes/20.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ What's New in Libc++ 20.0.0?
3838
Implemented Papers
3939
------------------
4040

41+
- P0619R4: Reviewing Deprecated Facilities of C++17 for C++20 (`Github <https://github.com/llvm/llvm-project/issues/99985>`__)
4142
- P2747R2: ``constexpr`` placement new (`Github <https://github.com/llvm/llvm-project/issues/105427>`__)
4243
- P2609R3: Relaxing Ranges Just A Smidge (`Github <https://github.com/llvm/llvm-project/issues/105253>`__)
4344
- P2985R0: A type trait for detecting virtual base classes (`Github <https://github.com/llvm/llvm-project/issues/105432>`__)
@@ -89,6 +90,11 @@ Deprecations and Removals
8990
the ``_LIBCPP_VERBOSE_ABORT_NOT_NOEXCEPT`` macro can be defined to make the function non-``noexcept``. That macro
9091
will be removed in LLVM 21.
9192

93+
- ``<ccomplex>``, ``<cstdalign>`` (previously missing), ``<cstdbool>``, and ``<ctgmath>`` are deprecated since C++17 as
94+
specified by the standard. They, together with ``<ciso646>``, are removed in C++20, but libc++ still provides these
95+
headers as an extension and only deprecates them. The ``_LIBCPP_DISABLE_DEPRECATION_WARNINGS`` macro can be defined to
96+
suppress deprecation for these headers.
97+
9298
Upcoming Deprecations and Removals
9399
----------------------------------
94100

libcxx/docs/Status/Cxx20Papers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"`P0528R3 <https://wg21.link/P0528R3>`__","The Curious Case of Padding Bits, Featuring Atomic Compare-and-Exchange","2018-06 (Rapperswil)","","",""
3535
"`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"
3636
"`P0556R3 <https://wg21.link/P0556R3>`__","Integral power-of-2 operations","2018-06 (Rapperswil)","|Complete|","9.0",""
37-
"`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."
37+
"`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"
3838
"`P0646R1 <https://wg21.link/P0646R1>`__","Improving the Return Value of Erase-Like Algorithms","2018-06 (Rapperswil)","|Complete|","10.0",""
3939
"`P0722R3 <https://wg21.link/P0722R3>`__","Efficient sized delete for variable sized classes","2018-06 (Rapperswil)","|Complete|","9.0",""
4040
"`P0758R1 <https://wg21.link/P0758R1>`__","Implicit conversion traits and utility functions","2018-06 (Rapperswil)","|Complete|","",""

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ set(files
923923
coroutine
924924
csetjmp
925925
csignal
926+
cstdalign
926927
cstdarg
927928
cstdbool
928929
cstddef

libcxx/include/ccomplex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,16 @@
2323
# pragma GCC system_header
2424
#endif
2525

26+
#if _LIBCPP_STD_VER >= 20
27+
28+
using __standard_header_ccomplex _LIBCPP_DEPRECATED_("removed in C++20. Include <complex> instead.") = void;
29+
using __use_standard_header_ccomplex = __standard_header_ccomplex;
30+
31+
#elif _LIBCPP_STD_VER >= 17
32+
33+
using __standard_header_ccomplex _LIBCPP_DEPRECATED_("Include <complex> instead.") = void;
34+
using __use_standard_header_ccomplex = __standard_header_ccomplex;
35+
36+
#endif
37+
2638
#endif // _LIBCPP_CCOMPLEX

libcxx/include/ciso646

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,11 @@
2121
# pragma GCC system_header
2222
#endif
2323

24+
#if _LIBCPP_STD_VER >= 20
25+
26+
using __standard_header_ciso646 _LIBCPP_DEPRECATED_("removed in C++20. Include <version> instead.") = void;
27+
using __use_standard_header_ciso646 = __standard_header_ciso646;
28+
29+
#endif
30+
2431
#endif // _LIBCPP_CISO646

libcxx/include/complex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#endif
2525

2626
#ifdef __cplusplus
27-
# include <ccomplex>
27+
# include <complex>
2828
#elif __has_include_next(<complex.h>)
2929
# include_next <complex.h>
3030
#endif

libcxx/include/cstdalign

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP_CSTDALIGN
11+
#define _LIBCPP_CSTDALIGN
12+
13+
/*
14+
cstdalign synopsis
15+
16+
Macros:
17+
18+
__alignas_is_defined
19+
__alignof_is_defined
20+
21+
*/
22+
23+
#include <__config>
24+
25+
// <stdalign.h> is not provided by libc++
26+
#if __has_include(<stdalign.h>)
27+
# include <stdalign.h>
28+
# ifdef _LIBCPP_STDALIGN_H
29+
# error "If libc++ starts defining <stdalign.h>, the __has_include check should move to libc++'s <stdalign.h>"
30+
# endif
31+
#endif
32+
33+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
34+
# pragma GCC system_header
35+
#endif
36+
37+
#undef __alignas_is_defined
38+
#define __alignas_is_defined 1
39+
40+
#undef __alignof_is_defined
41+
#define __alignof_is_defined 1
42+
43+
#if _LIBCPP_STD_VER >= 20
44+
45+
using __standard_header_cstdalign _LIBCPP_DEPRECATED_("removed in C++20.") = void;
46+
using __use_standard_header_cstdalign = __standard_header_cstdalign;
47+
48+
#elif _LIBCPP_STD_VER >= 17
49+
50+
using __standard_header_cstdalign _LIBCPP_DEPRECATED = void;
51+
using __use_standard_header_cstdalign = __standard_header_cstdalign;
52+
53+
#endif
54+
55+
#endif // _LIBCPP_CSTDALIGN

libcxx/include/cstdbool

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,16 @@ Macros:
2828
#undef __bool_true_false_are_defined
2929
#define __bool_true_false_are_defined 1
3030

31+
#if _LIBCPP_STD_VER >= 20
32+
33+
using __standard_header_cstdbool _LIBCPP_DEPRECATED_("removed in C++20.") = void;
34+
using __use_standard_header_cstdbool = __standard_header_cstdbool;
35+
36+
#elif _LIBCPP_STD_VER >= 17
37+
38+
using __standard_header_cstdbool _LIBCPP_DEPRECATED = void;
39+
using __use_standard_header_cstdbool = __standard_header_cstdbool;
40+
41+
#endif
42+
3143
#endif // _LIBCPP_CSTDBOOL

libcxx/include/ctgmath

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,23 @@
1818
1919
*/
2020

21-
#include <ccomplex>
2221
#include <cmath>
22+
#include <complex>
2323

2424
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2525
# pragma GCC system_header
2626
#endif
2727

28+
#if _LIBCPP_STD_VER >= 20
29+
30+
using __standard_header_ctgmath _LIBCPP_DEPRECATED_("removed in C++20. Include <cmath> and <complex> instead.") = void;
31+
using __use_standard_header_ctgmath = __standard_header_ctgmath;
32+
33+
#elif _LIBCPP_STD_VER >= 17
34+
35+
using __standard_header_ctgmath _LIBCPP_DEPRECATED_("Include <cmath> and <complex> instead.") = void;
36+
using __use_standard_header_ctgmath = __standard_header_ctgmath;
37+
38+
#endif
39+
2840
#endif // _LIBCPP_CTGMATH

libcxx/include/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,11 @@ module std [system] {
11091109
export *
11101110
}
11111111

1112+
module cstdalign {
1113+
header "cstdalign"
1114+
export *
1115+
}
1116+
11121117
module cstdarg {
11131118
header "cstdarg"
11141119
export *

libcxx/include/tgmath.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#endif
2525

2626
#ifdef __cplusplus
27-
# include <ctgmath>
27+
# include <cmath>
28+
# include <complex>
2829
#else
2930
# if __has_include_next(<tgmath.h>)
3031
# include_next <tgmath.h>

libcxx/test/libcxx/clang_modules_include.gen.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717

1818
import sys
1919
sys.path.append(sys.argv[1])
20-
from libcxx.header_information import lit_header_restrictions, public_headers
20+
from libcxx.header_information import (
21+
lit_header_restrictions,
22+
lit_header_undeprecations,
23+
public_headers,
24+
)
2125

2226
for header in public_headers:
23-
print(f"""\
27+
print(
28+
f"""\
2429
//--- {header}.compile.pass.cpp
2530
// RUN: %{{cxx}} %s %{{flags}} %{{compile_flags}} -fmodules -fcxx-modules -fmodules-cache-path=%t -fsyntax-only
2631
@@ -41,9 +46,11 @@
4146
// UNSUPPORTED: LIBCXX-PICOLIBC-FIXME
4247
4348
{lit_header_restrictions.get(header, '')}
49+
{lit_header_undeprecations.get(header, '')}
4450
4551
#include <{header}>
46-
""")
52+
"""
53+
)
4754

4855
print(
4956
f"""\

libcxx/test/libcxx/double_include.gen.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@
1515

1616
import sys
1717
sys.path.append(sys.argv[1])
18-
from libcxx.header_information import lit_header_restrictions, public_headers
18+
from libcxx.header_information import (
19+
lit_header_restrictions,
20+
lit_header_undeprecations,
21+
public_headers,
22+
)
1923

2024
for header in public_headers:
21-
print(f"""\
25+
print(
26+
f"""\
2227
//--- {header}.sh.cpp
2328
{lit_header_restrictions.get(header, '')}
29+
{lit_header_undeprecations.get(header, '')}
2430
2531
// RUN: %{{cxx}} -c %s -o %t.first.o %{{flags}} %{{compile_flags}}
2632
// RUN: %{{cxx}} -c %s -o %t.second.o -DWITH_MAIN %{{flags}} %{{compile_flags}}
@@ -32,4 +38,5 @@
3238
#if defined(WITH_MAIN)
3339
int main(int, char**) {{ return 0; }}
3440
#endif
35-
""")
41+
"""
42+
)

libcxx/test/libcxx/header_inclusions.gen.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,43 @@
1212
# RUN: %{python} %s %{libcxx-dir}/utils
1313

1414
import sys
15+
1516
sys.path.append(sys.argv[1])
16-
from libcxx.header_information import lit_header_restrictions, public_headers, mandatory_inclusions
17+
from libcxx.header_information import (
18+
lit_header_restrictions,
19+
lit_header_undeprecations,
20+
public_headers,
21+
mandatory_inclusions,
22+
)
1723

1824
for header in public_headers:
19-
header_guard = lambda h: f"_LIBCPP_{str(h).upper().replace('.', '_').replace('/', '_')}"
25+
header_guard = (
26+
lambda h: f"_LIBCPP_{str(h).upper().replace('.', '_').replace('/', '_')}"
27+
)
2028

21-
# <cassert> has no header guards
22-
if header == 'cassert':
23-
checks = ''
24-
else:
25-
checks = f'''
29+
# <cassert> has no header guards
30+
if header == "cassert":
31+
checks = ""
32+
else:
33+
checks = f"""
2634
#ifndef {header_guard(header)}
2735
# error <{header}> was expected to define a header guard {header_guard(header)}
2836
#endif
29-
'''
30-
for includee in mandatory_inclusions.get(header, []):
31-
checks += f'''
37+
"""
38+
for includee in mandatory_inclusions.get(header, []):
39+
checks += f"""
3240
#ifndef {header_guard(includee)}
3341
# error <{header}> was expected to include <{includee}>
3442
#endif
35-
'''
43+
"""
3644

37-
print(f"""\
45+
print(
46+
f"""\
3847
//--- {header}.compile.pass.cpp
3948
{lit_header_restrictions.get(header, '')}
49+
{lit_header_undeprecations.get(header, '')}
4050
4151
#include <{header}>
4252
{checks}
43-
""")
53+
"""
54+
)

libcxx/test/libcxx/include_as_c.sh.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#endif
3535
#include <math.h>
3636
#include <setjmp.h>
37+
#include <stdalign.h>
3738
#include <stdatomic.h>
3839
#include <stdbool.h>
3940
#include <stddef.h>

libcxx/test/libcxx/libcpp_version.gen.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@
1212

1313
import sys
1414
sys.path.append(sys.argv[1])
15-
from libcxx.header_information import lit_header_restrictions, public_headers
15+
from libcxx.header_information import (
16+
lit_header_restrictions,
17+
lit_header_undeprecations,
18+
public_headers,
19+
)
1620

1721
for header in public_headers:
18-
print(f"""\
22+
print(
23+
f"""\
1924
//--- {header}.compile.pass.cpp
2025
{lit_header_restrictions.get(header, '')}
26+
{lit_header_undeprecations.get(header, '')}
2127
2228
#include <{header}>
2329
2430
#ifndef _LIBCPP_VERSION
2531
# error <{header}> does not seem to define _LIBCPP_VERSION
2632
#endif
27-
""")
33+
"""
34+
)

libcxx/test/libcxx/no_assert_include.gen.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,28 @@
1212
# RUN: %{python} %s %{libcxx-dir}/utils
1313

1414
import sys
15+
1516
sys.path.append(sys.argv[1])
16-
from libcxx.header_information import lit_header_restrictions, public_headers
17+
from libcxx.header_information import (
18+
lit_header_restrictions,
19+
lit_header_undeprecations,
20+
public_headers,
21+
)
1722

1823
for header in public_headers:
19-
if header == 'cassert':
20-
continue
24+
if header == "cassert":
25+
continue
2126

22-
print(f"""\
27+
print(
28+
f"""\
2329
//--- {header}.compile.pass.cpp
2430
{lit_header_restrictions.get(header, '')}
31+
{lit_header_undeprecations.get(header, '')}
2532
2633
#include <{header}>
2734
2835
#ifdef assert
2936
# error "Do not include cassert or assert.h in standard header files"
3037
#endif
31-
""")
38+
"""
39+
)

0 commit comments

Comments
 (0)