Skip to content

Commit

Permalink
[libc++] Deprecate and remove meaningless <cxxx> headers (#111615)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
frederick-vs-ja and ldionne authored Oct 30, 2024
1 parent 8800b73 commit 63eb40e
Show file tree
Hide file tree
Showing 38 changed files with 394 additions and 44 deletions.
6 changes: 6 additions & 0 deletions libcxx/docs/ReleaseNotes/20.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ What's New in Libc++ 20.0.0?
Implemented Papers
------------------

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

- ``<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. The ``_LIBCPP_DISABLE_DEPRECATION_WARNINGS`` macro can be defined to
suppress deprecation for these headers.

Upcoming Deprecations and Removals
----------------------------------

Expand Down
2 changes: 1 addition & 1 deletion libcxx/docs/Status/Cxx20Papers.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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|","",""
Expand Down
1 change: 1 addition & 0 deletions libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ set(files
coroutine
csetjmp
csignal
cstdalign
cstdarg
cstdbool
cstddef
Expand Down
12 changes: 12 additions & 0 deletions libcxx/include/ccomplex
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@
# pragma GCC system_header
#endif

#if _LIBCPP_STD_VER >= 20

using __standard_header_ccomplex _LIBCPP_DEPRECATED_("removed in C++20. Include <complex> instead.") = void;
using __use_standard_header_ccomplex = __standard_header_ccomplex;

#elif _LIBCPP_STD_VER >= 17

using __standard_header_ccomplex _LIBCPP_DEPRECATED_("Include <complex> instead.") = void;
using __use_standard_header_ccomplex = __standard_header_ccomplex;

#endif

#endif // _LIBCPP_CCOMPLEX
7 changes: 7 additions & 0 deletions libcxx/include/ciso646
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@
# pragma GCC system_header
#endif

#if _LIBCPP_STD_VER >= 20

using __standard_header_ciso646 _LIBCPP_DEPRECATED_("removed in C++20. Include <version> instead.") = void;
using __use_standard_header_ciso646 = __standard_header_ciso646;

#endif

#endif // _LIBCPP_CISO646
2 changes: 1 addition & 1 deletion libcxx/include/complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#endif

#ifdef __cplusplus
# include <ccomplex>
# include <complex>
#elif __has_include_next(<complex.h>)
# include_next <complex.h>
#endif
Expand Down
55 changes: 55 additions & 0 deletions libcxx/include/cstdalign
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// -*- 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>

// <stdalign.h> is not provided by libc++
#if __has_include(<stdalign.h>)
# include <stdalign.h>
# ifdef _LIBCPP_STDALIGN_H
# error "If libc++ starts defining <stdalign.h>, the __has_include check should move to libc++'s <stdalign.h>"
# endif
#endif

#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 >= 20

using __standard_header_cstdalign _LIBCPP_DEPRECATED_("removed in C++20.") = void;
using __use_standard_header_cstdalign = __standard_header_cstdalign;

#elif _LIBCPP_STD_VER >= 17

using __standard_header_cstdalign _LIBCPP_DEPRECATED = void;
using __use_standard_header_cstdalign = __standard_header_cstdalign;

#endif

#endif // _LIBCPP_CSTDALIGN
12 changes: 12 additions & 0 deletions libcxx/include/cstdbool
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,16 @@ Macros:
#undef __bool_true_false_are_defined
#define __bool_true_false_are_defined 1

#if _LIBCPP_STD_VER >= 20

using __standard_header_cstdbool _LIBCPP_DEPRECATED_("removed in C++20.") = void;
using __use_standard_header_cstdbool = __standard_header_cstdbool;

#elif _LIBCPP_STD_VER >= 17

using __standard_header_cstdbool _LIBCPP_DEPRECATED = void;
using __use_standard_header_cstdbool = __standard_header_cstdbool;

#endif

#endif // _LIBCPP_CSTDBOOL
14 changes: 13 additions & 1 deletion libcxx/include/ctgmath
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@
*/

#include <ccomplex>
#include <cmath>
#include <complex>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

#if _LIBCPP_STD_VER >= 20

using __standard_header_ctgmath _LIBCPP_DEPRECATED_("removed in C++20. Include <cmath> and <complex> instead.") = void;
using __use_standard_header_ctgmath = __standard_header_ctgmath;

#elif _LIBCPP_STD_VER >= 17

using __standard_header_ctgmath _LIBCPP_DEPRECATED_("Include <cmath> and <complex> instead.") = void;
using __use_standard_header_ctgmath = __standard_header_ctgmath;

#endif

#endif // _LIBCPP_CTGMATH
5 changes: 5 additions & 0 deletions libcxx/include/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,11 @@ module std [system] {
export *
}

module cstdalign {
header "cstdalign"
export *
}

module cstdarg {
header "cstdarg"
export *
Expand Down
3 changes: 2 additions & 1 deletion libcxx/include/tgmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#endif

#ifdef __cplusplus
# include <ctgmath>
# include <cmath>
# include <complex>
#else
# if __has_include_next(<tgmath.h>)
# include_next <tgmath.h>
Expand Down
13 changes: 10 additions & 3 deletions libcxx/test/libcxx/clang_modules_include.gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@

import sys
sys.path.append(sys.argv[1])
from libcxx.header_information import lit_header_restrictions, public_headers
from libcxx.header_information import (
lit_header_restrictions,
lit_header_undeprecations,
public_headers,
)

for header in public_headers:
print(f"""\
print(
f"""\
//--- {header}.compile.pass.cpp
// RUN: %{{cxx}} %s %{{flags}} %{{compile_flags}} -fmodules -fcxx-modules -fmodules-cache-path=%t -fsyntax-only
Expand All @@ -41,9 +46,11 @@
// UNSUPPORTED: LIBCXX-PICOLIBC-FIXME
{lit_header_restrictions.get(header, '')}
{lit_header_undeprecations.get(header, '')}
#include <{header}>
""")
"""
)

print(
f"""\
Expand Down
13 changes: 10 additions & 3 deletions libcxx/test/libcxx/double_include.gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@

import sys
sys.path.append(sys.argv[1])
from libcxx.header_information import lit_header_restrictions, public_headers
from libcxx.header_information import (
lit_header_restrictions,
lit_header_undeprecations,
public_headers,
)

for header in public_headers:
print(f"""\
print(
f"""\
//--- {header}.sh.cpp
{lit_header_restrictions.get(header, '')}
{lit_header_undeprecations.get(header, '')}
// RUN: %{{cxx}} -c %s -o %t.first.o %{{flags}} %{{compile_flags}}
// RUN: %{{cxx}} -c %s -o %t.second.o -DWITH_MAIN %{{flags}} %{{compile_flags}}
Expand All @@ -32,4 +38,5 @@
#if defined(WITH_MAIN)
int main(int, char**) {{ return 0; }}
#endif
""")
"""
)
37 changes: 24 additions & 13 deletions libcxx/test/libcxx/header_inclusions.gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,43 @@
# RUN: %{python} %s %{libcxx-dir}/utils

import sys

sys.path.append(sys.argv[1])
from libcxx.header_information import lit_header_restrictions, public_headers, mandatory_inclusions
from libcxx.header_information import (
lit_header_restrictions,
lit_header_undeprecations,
public_headers,
mandatory_inclusions,
)

for header in public_headers:
header_guard = lambda h: f"_LIBCPP_{str(h).upper().replace('.', '_').replace('/', '_')}"
header_guard = (
lambda h: f"_LIBCPP_{str(h).upper().replace('.', '_').replace('/', '_')}"
)

# <cassert> has no header guards
if header == 'cassert':
checks = ''
else:
checks = f'''
# <cassert> has no header guards
if header == "cassert":
checks = ""
else:
checks = f"""
#ifndef {header_guard(header)}
# error <{header}> was expected to define a header guard {header_guard(header)}
#endif
'''
for includee in mandatory_inclusions.get(header, []):
checks += f'''
"""
for includee in mandatory_inclusions.get(header, []):
checks += f"""
#ifndef {header_guard(includee)}
# error <{header}> was expected to include <{includee}>
#endif
'''
"""

print(f"""\
print(
f"""\
//--- {header}.compile.pass.cpp
{lit_header_restrictions.get(header, '')}
{lit_header_undeprecations.get(header, '')}
#include <{header}>
{checks}
""")
"""
)
1 change: 1 addition & 0 deletions libcxx/test/libcxx/include_as_c.sh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#endif
#include <math.h>
#include <setjmp.h>
#include <stdalign.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stddef.h>
Expand Down
13 changes: 10 additions & 3 deletions libcxx/test/libcxx/libcpp_version.gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@

import sys
sys.path.append(sys.argv[1])
from libcxx.header_information import lit_header_restrictions, public_headers
from libcxx.header_information import (
lit_header_restrictions,
lit_header_undeprecations,
public_headers,
)

for header in public_headers:
print(f"""\
print(
f"""\
//--- {header}.compile.pass.cpp
{lit_header_restrictions.get(header, '')}
{lit_header_undeprecations.get(header, '')}
#include <{header}>
#ifndef _LIBCPP_VERSION
# error <{header}> does not seem to define _LIBCPP_VERSION
#endif
""")
"""
)
18 changes: 13 additions & 5 deletions libcxx/test/libcxx/no_assert_include.gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,28 @@
# RUN: %{python} %s %{libcxx-dir}/utils

import sys

sys.path.append(sys.argv[1])
from libcxx.header_information import lit_header_restrictions, public_headers
from libcxx.header_information import (
lit_header_restrictions,
lit_header_undeprecations,
public_headers,
)

for header in public_headers:
if header == 'cassert':
continue
if header == "cassert":
continue

print(f"""\
print(
f"""\
//--- {header}.compile.pass.cpp
{lit_header_restrictions.get(header, '')}
{lit_header_undeprecations.get(header, '')}
#include <{header}>
#ifdef assert
# error "Do not include cassert or assert.h in standard header files"
#endif
""")
"""
)
Loading

0 comments on commit 63eb40e

Please sign in to comment.