Skip to content

Commit 02a28ee

Browse files
authored
[Clang] Update feature test macros for Clang 18 (#78991)
* Set `__cpp_auto_cast`, as per cplusplus/CWG#281 * Support `__has_extension(cxx_generalized_nttp)` in C++20 as the feature isn't stable enough for a feature test macro * Support `__has_extension(cxx_explicit_this_parameter)` in c++23 as the feature isn't stable enough for a feature test macro
1 parent 0ab9c38 commit 02a28ee

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ C++20 Feature Support
185185
^^^^^^^^^^^^^^^^^^^^^
186186
- Implemented `P1907R1 <https://wg21.link/P1907R1>` which extends allowed non-type template argument
187187
kinds with e.g. floating point values and pointers and references to subobjects.
188-
This feature is still experimental. Accordingly, `__cpp_nontype_template_args` was not updated.
188+
This feature is still experimental. Accordingly, ``__cpp_nontype_template_args`` was not updated.
189+
However, its support can be tested with ``__has_extension(cxx_generalized_nttp)``.
189190

190191
C++23 Feature Support
191192
^^^^^^^^^^^^^^^^^^^^^
@@ -194,6 +195,7 @@ C++23 Feature Support
194195
`CWG2653 <https://wg21.link/CWG2653>`_, `CWG2687 <https://wg21.link/CWG2687>`_). Because the
195196
support for this feature is still experimental, the feature test macro ``__cpp_explicit_this_parameter``
196197
was not set in this version.
198+
However, its support can be tested with ``__has_extension(cxx_explicit_this_parameter)``.
197199

198200
- Added a separate warning to warn the use of attributes on lambdas as a C++23 extension
199201
in previous language versions: ``-Wc++23-lambda-attributes``.
@@ -1045,6 +1047,8 @@ Bug Fixes to C++ Support
10451047
- Remove recorded `#pragma once` state for headers included in named modules.
10461048
Fixes (`#77995 <https://github.com/llvm/llvm-project/issues/77995>`_)
10471049

1050+
- Set the ``__cpp_auto_cast`` feature test macro in C++23 mode.
1051+
10481052
Bug Fixes to AST Handling
10491053
^^^^^^^^^^^^^^^^^^^^^^^^^
10501054
- Fixed an import failure of recursive friend class template.

clang/include/clang/Basic/Features.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ EXTENSION(cxx_fixed_enum, true)
269269
EXTENSION(cxx_binary_literals, true)
270270
EXTENSION(cxx_init_captures, LangOpts.CPlusPlus11)
271271
EXTENSION(cxx_variable_templates, LangOpts.CPlusPlus)
272+
//C++20
273+
EXTENSION(cxx_generalized_nttp, LangOpts.CPlusPlus20)
274+
//C++23
275+
EXTENSION(cxx_explicit_this_parameter, LangOpts.CPlusPlus23)
272276
// Miscellaneous language extensions
273277
EXTENSION(overloadable_unmarked, true)
274278
EXTENSION(pragma_clang_attribute_namespaces, true)

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
728728
Builder.defineMacro("__cpp_size_t_suffix", "202011L");
729729
Builder.defineMacro("__cpp_if_consteval", "202106L");
730730
Builder.defineMacro("__cpp_multidimensional_subscript", "202211L");
731+
Builder.defineMacro("__cpp_auto_cast", "202110L");
731732
}
732733

733734
// We provide those C++23 features as extensions in earlier language modes, so

clang/test/Lexer/cxx-features.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040

4141
// --- C++23 features ---
4242

43+
#if check(auto_cast, 0, 0, 0, 0, 0, 202110, 202110)
44+
#error "wrong value for __cpp_auto_cast"
45+
#endif
46+
47+
4348
#if check(implicit_move, 0, 0, 0, 0, 0, 202011, 202011)
4449
#error "wrong value for __cpp_implicit_move"
4550
#endif

clang/test/Lexer/has_extension_cxx.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 -std=c++98 -E %s -o - | FileCheck %s
22
// RUN: %clang_cc1 -std=c++11 -E %s -o - | FileCheck %s --check-prefix=CHECK11
3+
// RUN: %clang_cc1 -std=c++20 -E %s -o - | FileCheck %s --check-prefix=CHECK20
4+
// RUN: %clang_cc1 -std=c++23 -E %s -o - | FileCheck %s --check-prefix=CHECK23
35

46
// CHECK: c_static_assert
57
#if __has_extension(c_static_assert)
@@ -76,3 +78,17 @@ int has_variable_templates();
7678
#if __has_extension(cxx_init_captures)
7779
int has_init_captures();
7880
#endif
81+
82+
83+
// CHECK11-NOT: has_generalized_nttp
84+
// CHECK20: has_generalized_nttp
85+
#if __has_extension(cxx_generalized_nttp)
86+
int has_generalized_nttp();
87+
#endif
88+
89+
90+
// CHECK20-NOT: has_explicit_this_parameter
91+
// CHECK23: has_explicit_this_parameter
92+
#if __has_extension(cxx_explicit_this_parameter)
93+
int has_explicit_this_parameter();
94+
#endif

0 commit comments

Comments
 (0)