diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 13e6c5e8db3ea..0b37b5fc29260 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -185,7 +185,8 @@ C++20 Feature Support ^^^^^^^^^^^^^^^^^^^^^ - Implemented `P1907R1 ` which extends allowed non-type template argument kinds with e.g. floating point values and pointers and references to subobjects. - This feature is still experimental. Accordingly, `__cpp_nontype_template_args` was not updated. + This feature is still experimental. Accordingly, ``__cpp_nontype_template_args`` was not updated. + However, its support can be tested with ``__has_extension(cxx_generalized_nttp)``. C++23 Feature Support ^^^^^^^^^^^^^^^^^^^^^ @@ -194,6 +195,7 @@ C++23 Feature Support `CWG2653 `_, `CWG2687 `_). Because the support for this feature is still experimental, the feature test macro ``__cpp_explicit_this_parameter`` was not set in this version. + However, its support can be tested with ``__has_extension(cxx_explicit_this_parameter)``. - Added a separate warning to warn the use of attributes on lambdas as a C++23 extension in previous language versions: ``-Wc++23-lambda-attributes``. @@ -1045,6 +1047,8 @@ Bug Fixes to C++ Support - Remove recorded `#pragma once` state for headers included in named modules. Fixes (`#77995 `_) +- Set the ``__cpp_auto_cast`` feature test macro in C++23 mode. + Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ - Fixed an import failure of recursive friend class template. diff --git a/clang/include/clang/Basic/Features.def b/clang/include/clang/Basic/Features.def index 06efac0cf1abd..5fad5fc3623cb 100644 --- a/clang/include/clang/Basic/Features.def +++ b/clang/include/clang/Basic/Features.def @@ -269,6 +269,10 @@ EXTENSION(cxx_fixed_enum, true) EXTENSION(cxx_binary_literals, true) EXTENSION(cxx_init_captures, LangOpts.CPlusPlus11) EXTENSION(cxx_variable_templates, LangOpts.CPlusPlus) +//C++20 +EXTENSION(cxx_generalized_nttp, LangOpts.CPlusPlus20) +//C++23 +EXTENSION(cxx_explicit_this_parameter, LangOpts.CPlusPlus23) // Miscellaneous language extensions EXTENSION(overloadable_unmarked, true) EXTENSION(pragma_clang_attribute_namespaces, true) diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index fe0fd3614113c..1b91c86f91398 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -728,6 +728,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts, Builder.defineMacro("__cpp_size_t_suffix", "202011L"); Builder.defineMacro("__cpp_if_consteval", "202106L"); Builder.defineMacro("__cpp_multidimensional_subscript", "202211L"); + Builder.defineMacro("__cpp_auto_cast", "202110L"); } // We provide those C++23 features as extensions in earlier language modes, so diff --git a/clang/test/Lexer/cxx-features.cpp b/clang/test/Lexer/cxx-features.cpp index 6120b299039e5..eb0e615f9470b 100644 --- a/clang/test/Lexer/cxx-features.cpp +++ b/clang/test/Lexer/cxx-features.cpp @@ -40,6 +40,11 @@ // --- C++23 features --- +#if check(auto_cast, 0, 0, 0, 0, 0, 202110, 202110) +#error "wrong value for __cpp_auto_cast" +#endif + + #if check(implicit_move, 0, 0, 0, 0, 0, 202011, 202011) #error "wrong value for __cpp_implicit_move" #endif diff --git a/clang/test/Lexer/has_extension_cxx.cpp b/clang/test/Lexer/has_extension_cxx.cpp index 1ae6a446b300a..7941997428aca 100644 --- a/clang/test/Lexer/has_extension_cxx.cpp +++ b/clang/test/Lexer/has_extension_cxx.cpp @@ -1,5 +1,7 @@ // RUN: %clang_cc1 -std=c++98 -E %s -o - | FileCheck %s // RUN: %clang_cc1 -std=c++11 -E %s -o - | FileCheck %s --check-prefix=CHECK11 +// RUN: %clang_cc1 -std=c++20 -E %s -o - | FileCheck %s --check-prefix=CHECK20 +// RUN: %clang_cc1 -std=c++23 -E %s -o - | FileCheck %s --check-prefix=CHECK23 // CHECK: c_static_assert #if __has_extension(c_static_assert) @@ -76,3 +78,17 @@ int has_variable_templates(); #if __has_extension(cxx_init_captures) int has_init_captures(); #endif + + +// CHECK11-NOT: has_generalized_nttp +// CHECK20: has_generalized_nttp +#if __has_extension(cxx_generalized_nttp) +int has_generalized_nttp(); +#endif + + +// CHECK20-NOT: has_explicit_this_parameter +// CHECK23: has_explicit_this_parameter +#if __has_extension(cxx_explicit_this_parameter) +int has_explicit_this_parameter(); +#endif