Skip to content

Commit

Permalink
Implement latest C++ feature test macro recommendations.
Browse files Browse the repository at this point in the history
We don't yet advertise init capture packs, because I found some bugs
while testing it. We reject-valid and then crash on both of these:

template<int ...a> auto x = [...y = a] {};
template<int ...a> auto x = [y = a...] {};
  • Loading branch information
zygoloid committed Dec 19, 2019
1 parent add710e commit df2e2ab
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
18 changes: 14 additions & 4 deletions clang/lib/Frontend/InitPreprocessor.cpp
Expand Up @@ -484,6 +484,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
LangOpts.CPlusPlus2a ? "201907L" :
LangOpts.CPlusPlus17 ? "201603L" :
LangOpts.CPlusPlus14 ? "201304L" : "200704");
Builder.defineMacro("__cpp_constexpr_in_decltype", "201711L");
Builder.defineMacro("__cpp_range_based_for",
LangOpts.CPlusPlus17 ? "201603L" : "200907");
Builder.defineMacro("__cpp_static_assert",
Expand All @@ -506,8 +507,9 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
if (LangOpts.CPlusPlus14) {
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_init_captures", "201304L"); // (not latest)
Builder.defineMacro("__cpp_generic_lambdas",
LangOpts.CPlusPlus2a ? "201707L" : "201304L");
Builder.defineMacro("__cpp_decltype_auto", "201304L");
Builder.defineMacro("__cpp_return_type_deduction", "201304L");
Builder.defineMacro("__cpp_aggregate_nsdmi", "201304L");
Expand All @@ -523,15 +525,16 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
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_deduction_guides", "201703L"); // (not latest)
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_nontype_template_args",
"201411L"); // (not latest)
Builder.defineMacro("__cpp_fold_expressions", "201603L");
Builder.defineMacro("__cpp_guaranteed_copy_elision", "201606L");
Builder.defineMacro("__cpp_nontype_template_parameter_auto", "201606L");
Expand All @@ -543,10 +546,17 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,

// C++20 features.
if (LangOpts.CPlusPlus2a) {
//Builder.defineMacro("__cpp_aggregate_paren_init", "201902L");
//Builder.defineMacro("__cpp_concepts", "201907L");
Builder.defineMacro("__cpp_conditional_explicit", "201806L");
//Builder.defineMacro("__cpp_consteval", "201811L");
Builder.defineMacro("__cpp_constexpr_dynamic_alloc", "201907L");
Builder.defineMacro("__cpp_constinit", "201907L");
//Builder.defineMacro("__cpp_coroutines", "201902L");
Builder.defineMacro("__cpp_designated_initializers", "201707L");
Builder.defineMacro("__cpp_impl_three_way_comparison", "201907L");
//Builder.defineMacro("__cpp_modules", "201907L");
//Builder.defineMacro("__cpp_using_enum", "201907L");
}
if (LangOpts.Char8)
Builder.defineMacro("__cpp_char8_t", "201811L");
Expand Down
18 changes: 17 additions & 1 deletion clang/test/Lexer/cxx-features.cpp
Expand Up @@ -34,14 +34,30 @@
#error "wrong value for __cpp_char8_t"
#endif

#if check(conditional_explicit, 0, 0, 0, 0, 201806)
#error "wrong value for __cpp_conditional_explicit"
#endif

// constexpr checked below

#if check(constexpr_dynamic_alloc, 0, 0, 0, 0, 201907)
#error "wrong value for __cpp_constexpr_dynamic_alloc"
#endif

#if check(constexpr_in_decltype, 0, 201711, 201711, 201711, 201711)
#error "wrong value for __cpp_constexpr_in_decltype"
#endif

#if check(constinit, 0, 0, 0, 0, 201907)
#error "wrong value for __cpp_constinit"
#endif

#if check(designated_initializers, 0, 0, 0, 0, 201707)
#error "wrong value for __cpp_designated_initializers"
#endif

// generic_lambdas checked below

#if check(impl_destroying_delete, 201806, 201806, 201806, 201806, 201806)
#error "wrong value for __cpp_impl_destroying_delete"
#endif
Expand Down Expand Up @@ -158,7 +174,7 @@
#error "wrong value for __cpp_init_captures"
#endif

#if check(generic_lambdas, 0, 0, 201304, 201304, 201304)
#if check(generic_lambdas, 0, 0, 201304, 201304, 201707)
#error "wrong value for __cpp_generic_lambdas"
#endif

Expand Down
13 changes: 3 additions & 10 deletions clang/www/cxx_status.html
Expand Up @@ -1227,22 +1227,15 @@ <h2 id="ts">Technical specifications and standing documents</h2>
</td>
</tr>
<tr>
<td class="partial" align="center">
WIP (<a href="https://wg21.link/p1353r0">P1353R0</a>)
</td>
</tr>
<tr>
<td class="none" align="center">
No (<a href="https://wg21.link/p1902r1">P1902R1</a>)</a>
<td class="full" align="center">
Clang 9 (<a href="https://wg21.link/p1353r0">P1353R0</a>)
</td>
</tr>
<!-- FIXME: Implement latest recommendations.
<tr>
<td class="svn" align="center">
SVN (<a href="https://wg21.link/p0096r3">P0096R3</a>)</a>
SVN (<a href="https://wg21.link/p1902r1">P1902R1</a>)</a>
</td>
</tr>
-->
<!-- No compiler support is known to be needed for:
* Concurrency TS
* Parallelism TS (v1, v2)
Expand Down

0 comments on commit df2e2ab

Please sign in to comment.