From 7652941f0aa0811a7ac205a74d3413a4e1ae08a4 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 14 Jun 2018 00:40:20 +0000 Subject: [PATCH] P0096R5, P0941R2: Update to match latest feature test macro specification. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@334677 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/InitPreprocessor.cpp | 102 ++++++++++++++++-------------- test/Lexer/cxx-features.cpp | 31 ++++++--- www/cxx_status.html | 25 +++++--- 3 files changed, 91 insertions(+), 67 deletions(-) diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index 6fbc810ca5..e3f4f92b9d 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -487,82 +487,86 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts, MacroBuilder &Builder) { // C++98 features. if (LangOpts.RTTI) - Builder.defineMacro("__cpp_rtti", "199711"); + Builder.defineMacro("__cpp_rtti", "199711L"); if (LangOpts.CXXExceptions) - Builder.defineMacro("__cpp_exceptions", "199711"); + Builder.defineMacro("__cpp_exceptions", "199711L"); // C++11 features. if (LangOpts.CPlusPlus11) { - Builder.defineMacro("__cpp_unicode_characters", "200704"); - Builder.defineMacro("__cpp_raw_strings", "200710"); - Builder.defineMacro("__cpp_unicode_literals", "200710"); - Builder.defineMacro("__cpp_user_defined_literals", "200809"); - Builder.defineMacro("__cpp_lambdas", "200907"); + Builder.defineMacro("__cpp_unicode_characters", "200704L"); + Builder.defineMacro("__cpp_raw_strings", "200710L"); + Builder.defineMacro("__cpp_unicode_literals", "200710L"); + Builder.defineMacro("__cpp_user_defined_literals", "200809L"); + Builder.defineMacro("__cpp_lambdas", "200907L"); Builder.defineMacro("__cpp_constexpr", - LangOpts.CPlusPlus17 ? "201603" : - LangOpts.CPlusPlus14 ? "201304" : "200704"); + LangOpts.CPlusPlus17 ? "201603L" : + LangOpts.CPlusPlus14 ? "201304L" : "200704"); Builder.defineMacro("__cpp_range_based_for", - LangOpts.CPlusPlus17 ? "201603" : "200907"); + LangOpts.CPlusPlus17 ? "201603L" : "200907"); Builder.defineMacro("__cpp_static_assert", - LangOpts.CPlusPlus17 ? "201411" : "200410"); - Builder.defineMacro("__cpp_decltype", "200707"); - Builder.defineMacro("__cpp_attributes", "200809"); - Builder.defineMacro("__cpp_rvalue_references", "200610"); - Builder.defineMacro("__cpp_variadic_templates", "200704"); - Builder.defineMacro("__cpp_initializer_lists", "200806"); - Builder.defineMacro("__cpp_delegating_constructors", "200604"); - Builder.defineMacro("__cpp_nsdmi", "200809"); - Builder.defineMacro("__cpp_inheriting_constructors", "201511"); - Builder.defineMacro("__cpp_ref_qualifiers", "200710"); - Builder.defineMacro("__cpp_alias_templates", "200704"); + LangOpts.CPlusPlus17 ? "201411L" : "200410"); + Builder.defineMacro("__cpp_decltype", "200707L"); + Builder.defineMacro("__cpp_attributes", "200809L"); + Builder.defineMacro("__cpp_rvalue_references", "200610L"); + Builder.defineMacro("__cpp_variadic_templates", "200704L"); + Builder.defineMacro("__cpp_initializer_lists", "200806L"); + Builder.defineMacro("__cpp_delegating_constructors", "200604L"); + Builder.defineMacro("__cpp_nsdmi", "200809L"); + Builder.defineMacro("__cpp_inheriting_constructors", "201511L"); + Builder.defineMacro("__cpp_ref_qualifiers", "200710L"); + Builder.defineMacro("__cpp_alias_templates", "200704L"); } if (LangOpts.ThreadsafeStatics) - Builder.defineMacro("__cpp_threadsafe_static_init", "200806"); + Builder.defineMacro("__cpp_threadsafe_static_init", "200806L"); // C++14 features. if (LangOpts.CPlusPlus14) { - Builder.defineMacro("__cpp_binary_literals", "201304"); - Builder.defineMacro("__cpp_digit_separators", "201309"); - Builder.defineMacro("__cpp_init_captures", "201304"); - Builder.defineMacro("__cpp_generic_lambdas", "201304"); - Builder.defineMacro("__cpp_decltype_auto", "201304"); - Builder.defineMacro("__cpp_return_type_deduction", "201304"); - Builder.defineMacro("__cpp_aggregate_nsdmi", "201304"); - Builder.defineMacro("__cpp_variable_templates", "201304"); + Builder.defineMacro("__cpp_binary_literals", "201304L"); + Builder.defineMacro("__cpp_digit_separators", "201309L"); + Builder.defineMacro("__cpp_init_captures", "201304L"); + Builder.defineMacro("__cpp_generic_lambdas", "201304L"); + Builder.defineMacro("__cpp_decltype_auto", "201304L"); + Builder.defineMacro("__cpp_return_type_deduction", "201304L"); + Builder.defineMacro("__cpp_aggregate_nsdmi", "201304L"); + Builder.defineMacro("__cpp_variable_templates", "201304L"); } if (LangOpts.SizedDeallocation) - Builder.defineMacro("__cpp_sized_deallocation", "201309"); + Builder.defineMacro("__cpp_sized_deallocation", "201309L"); // C++17 features. if (LangOpts.CPlusPlus17) { - Builder.defineMacro("__cpp_hex_float", "201603"); - Builder.defineMacro("__cpp_inline_variables", "201606"); - Builder.defineMacro("__cpp_noexcept_function_type", "201510"); - Builder.defineMacro("__cpp_capture_star_this", "201603"); - Builder.defineMacro("__cpp_if_constexpr", "201606"); - Builder.defineMacro("__cpp_deduction_guides", "201703"); - Builder.defineMacro("__cpp_template_auto", "201606"); - Builder.defineMacro("__cpp_namespace_attributes", "201411"); - Builder.defineMacro("__cpp_enumerator_attributes", "201411"); - Builder.defineMacro("__cpp_nested_namespace_definitions", "201411"); - Builder.defineMacro("__cpp_variadic_using", "201611"); - Builder.defineMacro("__cpp_aggregate_bases", "201603"); - Builder.defineMacro("__cpp_structured_bindings", "201606"); - Builder.defineMacro("__cpp_nontype_template_args", "201411"); - Builder.defineMacro("__cpp_fold_expressions", "201603"); + Builder.defineMacro("__cpp_hex_float", "201603L"); + Builder.defineMacro("__cpp_inline_variables", "201606L"); + Builder.defineMacro("__cpp_noexcept_function_type", "201510L"); + Builder.defineMacro("__cpp_capture_star_this", "201603L"); + Builder.defineMacro("__cpp_if_constexpr", "201606L"); + Builder.defineMacro("__cpp_deduction_guides", "201703L"); + Builder.defineMacro("__cpp_template_auto", "201606L"); // (old name) + Builder.defineMacro("__cpp_namespace_attributes", "201411L"); + Builder.defineMacro("__cpp_enumerator_attributes", "201411L"); + Builder.defineMacro("__cpp_nested_namespace_definitions", "201411L"); + Builder.defineMacro("__cpp_variadic_using", "201611L"); + Builder.defineMacro("__cpp_aggregate_bases", "201603L"); + Builder.defineMacro("__cpp_structured_bindings", "201606L"); + Builder.defineMacro("__cpp_nontype_template_args", "201411L"); + Builder.defineMacro("__cpp_fold_expressions", "201603L"); + Builder.defineMacro("__cpp_guaranteed_copy_elision", "201606L"); + Builder.defineMacro("__cpp_nontype_template_parameter_auto", "201606L"); } if (LangOpts.AlignedAllocation) - Builder.defineMacro("__cpp_aligned_new", "201606"); + Builder.defineMacro("__cpp_aligned_new", "201606L"); + if (LangOpts.RelaxedTemplateTemplateArgs) + Builder.defineMacro("__cpp_template_template_args", "201611L"); // TS features. if (LangOpts.ConceptsTS) - Builder.defineMacro("__cpp_experimental_concepts", "1"); + Builder.defineMacro("__cpp_experimental_concepts", "1L"); if (LangOpts.CoroutinesTS) Builder.defineMacro("__cpp_coroutines", "201703L"); // Potential future breaking changes. if (LangOpts.Char8) - Builder.defineMacro("__cpp_char8_t", "201803"); + Builder.defineMacro("__cpp_char8_t", "201803L"); } static void InitializePredefinedMacros(const TargetInfo &TI, diff --git a/test/Lexer/cxx-features.cpp b/test/Lexer/cxx-features.cpp index a0058511eb..772fa26e96 100644 --- a/test/Lexer/cxx-features.cpp +++ b/test/Lexer/cxx-features.cpp @@ -1,9 +1,11 @@ // RUN: %clang_cc1 -std=c++98 -fcxx-exceptions -verify %s // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -verify %s -// RUN: %clang_cc1 -std=c++1y -fcxx-exceptions -fsized-deallocation -verify %s // RUN: %clang_cc1 -std=c++14 -fcxx-exceptions -fsized-deallocation -verify %s -// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fsized-deallocation -verify %s -// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fsized-deallocation -fconcepts-ts -DCONCEPTS_TS=1 -verify %s +// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -verify %s +// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -fsized-deallocation -verify %s +// +// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -frelaxed-template-template-args -DRELAXED_TEMPLATE_TEMPLATE_ARGS=1 -verify %s +// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -fconcepts-ts -DCONCEPTS_TS=1 -verify %s // RUN: %clang_cc1 -fno-rtti -fno-threadsafe-statics -verify %s -DNO_EXCEPTIONS -DNO_RTTI -DNO_THREADSAFE_STATICS -fsized-deallocation // RUN: %clang_cc1 -fcoroutines-ts -DNO_EXCEPTIONS -DCOROUTINES -verify -fsized-deallocation %s // RUN: %clang_cc1 -fchar8_t -DNO_EXCEPTIONS -DCHAR8_T -verify -fsized-deallocation %s @@ -12,13 +14,13 @@ // FIXME using `defined` in a macro has undefined behavior. #if __cplusplus < 201103L -#define check(macro, cxx98, cxx11, cxx14, cxx1z) cxx98 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx98 +#define check(macro, cxx98, cxx11, cxx14, cxx17) cxx98 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx98 #elif __cplusplus < 201402L -#define check(macro, cxx98, cxx11, cxx14, cxx1z) cxx11 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx11 +#define check(macro, cxx98, cxx11, cxx14, cxx17) cxx11 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx11 #elif __cplusplus < 201406L -#define check(macro, cxx98, cxx11, cxx14, cxx1z) cxx14 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx14 +#define check(macro, cxx98, cxx11, cxx14, cxx17) cxx14 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx14 #else -#define check(macro, cxx98, cxx11, cxx14, cxx1z) cxx1z == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx1z +#define check(macro, cxx98, cxx11, cxx14, cxx17) cxx17 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx17 #endif // --- C++17 features --- @@ -35,6 +37,10 @@ #error "wrong value for __cpp_aligned_new" #endif +#if check(guaranteed_copy_elision, 0, 0, 0, 201606) +#error "wrong value for __cpp_guaranteed_copy_elision" +#endif + #if check(noexcept_function_type, 0, 0, 0, 201510) #error "wrong value for __cpp_noexcept_function_type" #endif @@ -61,6 +67,12 @@ #error "wrong value for __cpp_deduction_guides" #endif +#if check(nontype_template_parameter_auto, 0, 0, 0, 201606) +#error "wrong value for __cpp_nontype_template_parameter_auto" +#endif + +// This is the old name (from P0096R4) for +// __cpp_nontype_template_parameter_auto #if check(template_auto, 0, 0, 0, 201606) #error "wrong value for __cpp_template_auto" #endif @@ -75,6 +87,7 @@ #error "wrong value for __cpp_enumerator_attributes" #endif +// This is an old name (from P0096R4), now removed from SD-6. #if check(nested_namespace_definitions, 0, 0, 0, 201411) #error "wrong value for __cpp_nested_namespace_definitions" #endif @@ -97,7 +110,9 @@ #error "wrong value for __cpp_nontype_template_args" #endif -#if check(template_template_args, 0, 0, 0, 0) // FIXME: should be 201611 when feature is enabled +#if defined(RELAXED_TEMPLATE_TEMPLATE_ARGS) \ + ? check(template_template_args, 0, 0, 0, 201611) \ + : check(template_template_args, 0, 0, 0, 0) #error "wrong value for __cpp_template_template_args" #endif diff --git a/www/cxx_status.html b/www/cxx_status.html index dfd05575e3..b935e72186 100644 --- a/www/cxx_status.html +++ b/www/cxx_status.html @@ -962,7 +962,7 @@ as the draft C++2a standard evolves. Feature test macros P0941R2 - (see below) + (see below) explicit(bool) @@ -1002,9 +1002,9 @@ and library features that are not part of standard C++.

Available in Clang? - SD-6: SG10 feature test recommendations - SD-6 - N/A + SD-6: SG10 feature test recommendations + SD-6 + N/A Clang 3.4 (N3745)
@@ -1024,6 +1024,11 @@ and library features that are not part of standard C++.

Clang 5 (P0096R4) + + + SVN (P0096R5) + +