From 252e09f6c1a1e090aacb7fb4f6220c92f76883d9 Mon Sep 17 00:00:00 2001 From: Richard Smith <richard-llvm@metafoo.co.uk> Date: Wed, 28 Sep 2016 19:44:50 +0000 Subject: [PATCH] P0096R2: Implement more recent revision of SD-6 (C++ feature test macros). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@282622 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/InitPreprocessor.cpp | 17 ++++++- test/Lexer/cxx-features.cpp | 75 ++++++++++++++++++++++++++----- www/cxx_status.html | 7 ++- 3 files changed, 84 insertions(+), 15 deletions(-) diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index 26878429d30..8f669c7179c 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -468,7 +468,8 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts, Builder.defineMacro("__cpp_constexpr", LangOpts.CPlusPlus14 ? "201304" : "200704"); Builder.defineMacro("__cpp_range_based_for", "200907"); - Builder.defineMacro("__cpp_static_assert", "200410"); + Builder.defineMacro("__cpp_static_assert", + LangOpts.CPlusPlus1z ? "201411" : "200410"); Builder.defineMacro("__cpp_decltype", "200707"); Builder.defineMacro("__cpp_attributes", "200809"); Builder.defineMacro("__cpp_rvalue_references", "200610"); @@ -476,7 +477,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts, Builder.defineMacro("__cpp_initializer_lists", "200806"); Builder.defineMacro("__cpp_delegating_constructors", "200604"); Builder.defineMacro("__cpp_nsdmi", "200809"); - Builder.defineMacro("__cpp_inheriting_constructors", "200802"); + Builder.defineMacro("__cpp_inheriting_constructors", "201511"); Builder.defineMacro("__cpp_ref_qualifiers", "200710"); Builder.defineMacro("__cpp_alias_templates", "200704"); } @@ -494,6 +495,18 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts, } if (LangOpts.SizedDeallocation) Builder.defineMacro("__cpp_sized_deallocation", "201309"); + + // C++17 features. + if (LangOpts.CPlusPlus1z) { + //Builder.defineMacro("__cpp_noexcept_function_type", "201510"); + Builder.defineMacro("__cpp_fold_expressions", "201411"); + Builder.defineMacro("__cpp_namespace_attributes", "201411"); + Builder.defineMacro("__cpp_enumerator_attributes", "201411"); + Builder.defineMacro("__cpp_nested_namespace_definitions", "201411"); + Builder.defineMacro("__cpp_nontype_template_args", "201411"); + } + + // TS features. if (LangOpts.ConceptsTS) Builder.defineMacro("__cpp_experimental_concepts", "1"); if (LangOpts.Coroutines) diff --git a/test/Lexer/cxx-features.cpp b/test/Lexer/cxx-features.cpp index e047ec3dfb1..a616e7f423c 100644 --- a/test/Lexer/cxx-features.cpp +++ b/test/Lexer/cxx-features.cpp @@ -1,10 +1,11 @@ -// RUN: %clang_cc1 -std=c++98 -verify %s -// RUN: %clang_cc1 -std=c++11 -verify %s -// RUN: %clang_cc1 -std=c++1y -fsized-deallocation -verify %s -// RUN: %clang_cc1 -std=c++14 -fsized-deallocation -verify %s -// RUN: %clang_cc1 -std=c++1z -fsized-deallocation -verify %s -// RUN: %clang_cc1 -std=c++1z -fsized-deallocation -fconcepts-ts -DCONCEPTS_TS=1 -verify %s -// RUN: %clang_cc1 -fcoroutines -DCOROUTINES -verify %s +// 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 -fno-rtti -verify %s -DNO_EXCEPTIONS -DNO_RTTI +// RUN: %clang_cc1 -fcoroutines -DNO_EXCEPTIONS -DCOROUTINES -verify %s // expected-no-diagnostics @@ -19,10 +20,44 @@ #define check(macro, cxx98, cxx11, cxx14, cxx1z) cxx1z == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx1z #endif +// --- C++17 features --- + +#if check(noexcept_function_type, 0, 0, 0, 0) +// FIXME +#error "wrong value for __cpp_noexcept_function_type" +#endif + +#if check(fold_expressions, 0, 0, 0, 201411) +#error "wrong value for __cpp_fold_expressions" +#endif + +// static_assert checked below + +#if check(namespace_attributes, 0, 0, 0, 201411) +// FIXME: allowed without warning in C++14 and C++11 +#error "wrong value for __cpp_namespace_attributes" +#endif + +#if check(enumerator_attributes, 0, 0, 0, 201411) +// FIXME: allowed without warning in C++14 and C++11 +#error "wrong value for __cpp_enumerator_attributes" +#endif + +#if check(nested_namespace_definitions, 0, 0, 0, 201411) +#error "wrong value for __cpp_nested_namespace_definitions" +#endif + +#if check(nontype_template_args, 0, 0, 0, 201411) +#error "wrong value for __cpp_nontype_template_args" +#endif + +// --- C++14 features --- + #if check(binary_literals, 0, 0, 201304, 201304) #error "wrong value for __cpp_binary_literals" #endif +// (Removed from SD-6.) #if check(digit_separators, 0, 0, 201309, 201309) #error "wrong value for __cpp_digit_separators" #endif @@ -39,9 +74,7 @@ #error "wrong value for __cpp_sized_deallocation" #endif -#if check(constexpr, 0, 200704, 201304, 201304) -#error "wrong value for __cpp_constexpr" -#endif +// constexpr checked below #if check(decltype_auto, 0, 0, 201304, 201304) #error "wrong value for __cpp_decltype_auto" @@ -63,6 +96,8 @@ #error "wrong value for __cpp_variable_templates" #endif +// --- C++11 features --- + #if check(unicode_characters, 0, 200704, 200704, 200704) #error "wrong value for __cpp_unicode_characters" #endif @@ -83,11 +118,15 @@ #error "wrong value for __cpp_lambdas" #endif +#if check(constexpr, 0, 200704, 201304, 201304) +#error "wrong value for __cpp_constexpr" +#endif + #if check(range_based_for, 0, 200907, 200907, 200907) #error "wrong value for __cpp_range_based_for" #endif -#if check(static_assert, 0, 200410, 200410, 200410) +#if check(static_assert, 0, 200410, 200410, 201411) #error "wrong value for __cpp_static_assert" #endif @@ -119,7 +158,7 @@ #error "wrong value for __cpp_nsdmi" #endif -#if check(inheriting_constructors, 0, 200802, 200802, 200802) +#if check(inheriting_constructors, 0, 201511, 201511, 201511) #error "wrong value for __cpp_inheriting_constructors" #endif @@ -131,6 +170,18 @@ #error "wrong value for __cpp_alias_templates" #endif +// --- C++98 features --- + +#if defined(NO_RTTI) ? check(rtti, 0, 0, 0, 0) : check(rtti, 199711, 199711, 199711, 199711) +#error "wrong value for __cpp_rtti" +#endif + +#if defined(NO_EXCEPTIONS) ? check(exceptions, 0, 0, 0, 0) : check(exceptions, 199711, 199711, 199711, 199711) +#error "wrong value for __cpp_exceptions" +#endif + +// --- TS features -- + #if check(experimental_concepts, 0, 0, CONCEPTS_TS, CONCEPTS_TS) #error "wrong value for __cpp_experimental_concepts" #endif diff --git a/www/cxx_status.html b/www/cxx_status.html index a53f855ce2e..3f57a95a082 100644 --- a/www/cxx_status.html +++ b/www/cxx_status.html @@ -772,10 +772,15 @@ Clang version they became available:</p> Clang 3.6 (<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4200">N4200</a>)</a> </td> </tr> + <tr> + <td class="svn" align="center"> + SVN (<a href="http://wg21.link/p0096r2">P0096R2</a>)</a> + </td> + </tr> <!-- FIXME: Implement latest recommendations. <tr> <td class="svn" align="center"> - SVN (<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0096r0">P0096R0</a>)</a> + SVN (<a href="http://wg21.link/p0096r3">P0096R3</a>)</a> </td> </tr> --> -- GitLab