Commit b9690e08 authored by Bill Wendling's avatar Bill Wendling
Browse files

Merging r181342:

------------------------------------------------------------------------
r181342 | rsmith | 2013-05-07 12:32:56 -0700 (Tue, 07 May 2013) | 4 lines

C++1y: Update __cplusplus to temporary value 201305L to allow detection of provisional C++1y support.
Add __has_feature and __has_extension checks for C++1y features (based on the provisional names from
the C++ features study group), and update documentation to match.

------------------------------------------------------------------------

llvm-svn: 182340
parent c9a23ab9
Loading
Loading
Loading
Loading
+92 −0
Original line number Diff line number Diff line
@@ -779,6 +779,98 @@ Use ``__has_feature(cxx_variadic_templates)`` or
``__has_extension(cxx_variadic_templates)`` to determine if support for
variadic templates is enabled.

C++1y
-----

The features listed below are part of the committee draft for the C++1y
standard.  As a result, all these features are enabled with the ``-std=c++1y``
or ``-std=gnu++1y`` option when compiling C++ code.

C++1y binary literals
^^^^^^^^^^^^^^^^^^^^^

Use ``__has_feature(cxx_binary_literals)`` or
``__has_extension(cxx_binary_literals)`` to determine whether
binary literals (for instance, ``0b10010``) are recognized. Clang supports this
feature as an extension in all language modes.

C++1y contextual conversions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Use ``__has_feature(cxx_contextual_conversions)`` or
``__has_extension(cxx_contextual_conversions)`` to determine if the C++1y rules
are used when performing an implicit conversion for an array bound in a
*new-expression*, the operand of a *delete-expression*, an integral constant
expression, or a condition in a ``switch`` statement. Clang does not yet
support this feature.

C++1y decltype(auto)
^^^^^^^^^^^^^^^^^^^^

Use ``__has_feature(cxx_decltype_auto)`` or
``__has_extension(cxx_decltype_auto)`` to determine if support
for the ``decltype(auto)`` placeholder type is enabled.

C++1y default initializers for aggregates
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Use ``__has_feature(cxx_aggregate_nsdmi)`` or
``__has_extension(cxx_aggregate_nsdmi)`` to determine if support
for default initializers in aggregate members is enabled.

C++1y generalized lambda capture
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Use ``__has_feature(cxx_generalized_capture)`` or
``__has_extension(cxx_generalized_capture`` to determine if support for
generalized lambda captures is enabled
(for instance, ``[n(0)] { return ++n; }``).
Clang does not yet support this feature.

C++1y generic lambdas
^^^^^^^^^^^^^^^^^^^^^

Use ``__has_feature(cxx_generic_lambda)`` or
``__has_extension(cxx_generic_lambda)`` to determine if support for generic
(polymorphic) lambdas is enabled
(for instance, ``[] (auto x) { return x + 1; }``).
Clang does not yet support this feature.

C++1y relaxed constexpr
^^^^^^^^^^^^^^^^^^^^^^^

Use ``__has_feature(cxx_relaxed_constexpr)`` or
``__has_extension(cxx_relaxed_constexpr)`` to determine if variable
declarations, local variable modification, and control flow constructs
are permitted in ``constexpr`` functions.
Clang's implementation of this feature is incomplete.

C++1y return type deduction
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Use ``__has_feature(cxx_return_type_deduction)`` or
``__has_extension(cxx_return_type_deduction)`` to determine if support
for return type deduction for functions (using ``auto`` as a return type)
is enabled.
Clang's implementation of this feature is incomplete.

C++1y runtime-sized arrays
^^^^^^^^^^^^^^^^^^^^^^^^^^

Use ``__has_feature(cxx_runtime_array)`` or
``__has_extension(cxx_runtime_array)`` to determine if support
for arrays of runtime bound (a restricted form of variable-length arrays)
is enabled.
Clang's implementation of this feature is incomplete.

C++1y variable templates
^^^^^^^^^^^^^^^^^^^^^^^^

Use ``__has_feature(cxx_variable_templates)`` or
``__has_extension(cxx_variable_templates)`` to determine if support for
templated variable declarations is enabled.
Clang does not yet support this feature.

C11
---

+4 −3
Original line number Diff line number Diff line
@@ -302,12 +302,13 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
    else if (!LangOpts.GNUMode && LangOpts.Digraphs)
      Builder.defineMacro("__STDC_VERSION__", "199409L");
  } else {
    // FIXME: LangOpts.CPlusPlus1y

    // FIXME: Use the right value for __cplusplus for C++1y once one is chosen.
    if (LangOpts.CPlusPlus1y)
      Builder.defineMacro("__cplusplus", "201305L");
    // C++11 [cpp.predefined]p1:
    //   The name __cplusplus is defined to the value 201103L when compiling a
    //   C++ translation unit.
    if (LangOpts.CPlusPlus11)
    else if (LangOpts.CPlusPlus11)
      Builder.defineMacro("__cplusplus", "201103L");
    // C++03 [cpp.predefined]p1:
    //   The name __cplusplus is defined to the value 199711L when compiling a
+13 −1
Original line number Diff line number Diff line
@@ -792,6 +792,16 @@ static bool HasFeature(const Preprocessor &PP, const IdentifierInfo *II) {
           .Case("cxx_unrestricted_unions", LangOpts.CPlusPlus11)
           .Case("cxx_user_literals", LangOpts.CPlusPlus11)
           .Case("cxx_variadic_templates", LangOpts.CPlusPlus11)
           // C++1y features
           .Case("cxx_binary_literals", LangOpts.CPlusPlus1y)
           //.Case("cxx_contextual_conversions", LangOpts.CPlusPlus1y)
           //.Case("cxx_generalized_capture", LangOpts.CPlusPlus1y)
           //.Case("cxx_generic_lambda", LangOpts.CPlusPlus1y)
           //.Case("cxx_relaxed_constexpr", LangOpts.CPlusPlus1y)
           //.Case("cxx_return_type_deduction", LangOpts.CPlusPlus1y)
           //.Case("cxx_runtime_array", LangOpts.CPlusPlus1y)
           .Case("cxx_aggregate_nsdmi", LangOpts.CPlusPlus1y)
           //.Case("cxx_variable_templates", LangOpts.CPlusPlus1y)
           // Type traits
           .Case("has_nothrow_assign", LangOpts.CPlusPlus)
           .Case("has_nothrow_copy", LangOpts.CPlusPlus)
@@ -852,7 +862,7 @@ static bool HasExtension(const Preprocessor &PP, const IdentifierInfo *II) {
           .Case("c_atomic", true)
           .Case("c_generic_selections", true)
           .Case("c_static_assert", true)
           // C++0x features supported by other languages as extensions.
           // C++11 features supported by other languages as extensions.
           .Case("cxx_atomic", LangOpts.CPlusPlus)
           .Case("cxx_deleted_functions", LangOpts.CPlusPlus)
           .Case("cxx_explicit_conversions", LangOpts.CPlusPlus)
@@ -863,6 +873,8 @@ static bool HasExtension(const Preprocessor &PP, const IdentifierInfo *II) {
           .Case("cxx_range_for", LangOpts.CPlusPlus)
           .Case("cxx_reference_qualified_functions", LangOpts.CPlusPlus)
           .Case("cxx_rvalue_references", LangOpts.CPlusPlus)
           // C++1y features supported by other languages as extensions.
           .Case("cxx_binary_literals", true)
           .Default(false);
}

+6 −0
Original line number Diff line number Diff line
@@ -47,3 +47,9 @@ int no_local_type_template_args();
#endif

// CHECK: has_local_type_template_args

#if __has_extension(cxx_binary_literals)
int has_binary_literals();
#endif

// CHECK: has_binary_literals
+118 −64
Original line number Diff line number Diff line
// RUN: %clang_cc1 -E -triple x86_64-linux-gnu -std=c++11 %s -o - | FileCheck --check-prefix=CHECK-0X %s
// RUN: %clang_cc1 -E -triple x86_64-linux-gnu -std=c++11 %s -o - | FileCheck --check-prefix=CHECK-11 %s
// RUN: %clang_cc1 -E -triple armv7-apple-darwin -std=c++11 %s -o - | FileCheck --check-prefix=CHECK-NO-TLS %s
// RUN: %clang_cc1 -E -triple x86_64-linux-gnu %s -o - | FileCheck --check-prefix=CHECK-NO-0X %s
// RUN: %clang_cc1 -E -triple x86_64-linux-gnu %s -o - | FileCheck --check-prefix=CHECK-NO-11 %s
// RUN: %clang_cc1 -E -triple x86_64-linux-gnu -std=c++1y %s -o - | FileCheck --check-prefix=CHECK-1Y %s

#if __has_feature(cxx_atomic)
int has_atomic();
@@ -8,8 +9,9 @@ int has_atomic();
int no_atomic();
#endif

// CHECK-0X: has_atomic
// CHECK-NO-0X: no_atomic
// CHECK-1Y: has_atomic
// CHECK-11: has_atomic
// CHECK-NO-11: no_atomic

#if __has_feature(cxx_lambdas)
int has_lambdas();
@@ -17,8 +19,9 @@ int has_lambdas();
int no_lambdas();
#endif

// CHECK-0X: has_lambdas
// CHECK-NO-0X: no_lambdas
// CHECK-1Y: has_lambdas
// CHECK-11: has_lambdas
// CHECK-NO-11: no_lambdas


#if __has_feature(cxx_nullptr)
@@ -27,8 +30,9 @@ int has_nullptr();
int no_nullptr();
#endif

// CHECK-0X: has_nullptr
// CHECK-NO-0X: no_nullptr
// CHECK-1Y: has_nullptr
// CHECK-11: has_nullptr
// CHECK-NO-11: no_nullptr


#if __has_feature(cxx_decltype)
@@ -37,8 +41,9 @@ int has_decltype();
int no_decltype();
#endif

// CHECK-0X: has_decltype
// CHECK-NO-0X: no_decltype
// CHECK-1Y: has_decltype
// CHECK-11: has_decltype
// CHECK-NO-11: no_decltype


#if __has_feature(cxx_decltype_incomplete_return_types)
@@ -47,8 +52,9 @@ int has_decltype_incomplete_return_types();
int no_decltype_incomplete_return_types();
#endif

// CHECK-0X: has_decltype_incomplete_return_types
// CHECK-NO-0X: no_decltype_incomplete_return_types
// CHECK-1Y: has_decltype_incomplete_return_types
// CHECK-11: has_decltype_incomplete_return_types
// CHECK-NO-11: no_decltype_incomplete_return_types


#if __has_feature(cxx_auto_type)
@@ -57,8 +63,9 @@ int has_auto_type();
int no_auto_type();
#endif

// CHECK-0X: has_auto_type
// CHECK-NO-0X: no_auto_type
// CHECK-1Y: has_auto_type
// CHECK-11: has_auto_type
// CHECK-NO-11: no_auto_type


#if __has_feature(cxx_trailing_return)
@@ -67,8 +74,9 @@ int has_trailing_return();
int no_trailing_return();
#endif

// CHECK-0X: has_trailing_return
// CHECK-NO-0X: no_trailing_return
// CHECK-1Y: has_trailing_return
// CHECK-11: has_trailing_return
// CHECK-NO-11: no_trailing_return


#if __has_feature(cxx_attributes)
@@ -77,8 +85,9 @@ int has_attributes();
int no_attributes();
#endif

// CHECK-0X: has_attributes
// CHECK-NO-0X: no_attributes
// CHECK-1Y: has_attributes
// CHECK-11: has_attributes
// CHECK-NO-11: no_attributes


#if __has_feature(cxx_static_assert)
@@ -87,8 +96,9 @@ int has_static_assert();
int no_static_assert();
#endif

// CHECK-0X: has_static_assert
// CHECK-NO-0X: no_static_assert
// CHECK-1Y: has_static_assert
// CHECK-11: has_static_assert
// CHECK-NO-11: no_static_assert

#if __has_feature(cxx_deleted_functions)
int has_deleted_functions();
@@ -96,8 +106,9 @@ int has_deleted_functions();
int no_deleted_functions();
#endif

// CHECK-0X: has_deleted_functions
// CHECK-NO-0X: no_deleted_functions
// CHECK-1Y: has_deleted_functions
// CHECK-11: has_deleted_functions
// CHECK-NO-11: no_deleted_functions

#if __has_feature(cxx_defaulted_functions)
int has_defaulted_functions();
@@ -105,8 +116,9 @@ int has_defaulted_functions();
int no_defaulted_functions();
#endif

// CHECK-0X: has_defaulted_functions
// CHECK-NO-0X: no_defaulted_functions
// CHECK-1Y: has_defaulted_functions
// CHECK-11: has_defaulted_functions
// CHECK-NO-11: no_defaulted_functions

#if __has_feature(cxx_rvalue_references)
int has_rvalue_references();
@@ -114,8 +126,9 @@ int has_rvalue_references();
int no_rvalue_references();
#endif

// CHECK-0X: has_rvalue_references
// CHECK-NO-0X: no_rvalue_references
// CHECK-1Y: has_rvalue_references
// CHECK-11: has_rvalue_references
// CHECK-NO-11: no_rvalue_references


#if __has_feature(cxx_variadic_templates)
@@ -124,8 +137,9 @@ int has_variadic_templates();
int no_variadic_templates();
#endif

// CHECK-0X: has_variadic_templates
// CHECK-NO-0X: no_variadic_templates
// CHECK-1Y: has_variadic_templates
// CHECK-11: has_variadic_templates
// CHECK-NO-11: no_variadic_templates


#if __has_feature(cxx_inline_namespaces)
@@ -134,8 +148,9 @@ int has_inline_namespaces();
int no_inline_namespaces();
#endif

// CHECK-0X: has_inline_namespaces
// CHECK-NO-0X: no_inline_namespaces
// CHECK-1Y: has_inline_namespaces
// CHECK-11: has_inline_namespaces
// CHECK-NO-11: no_inline_namespaces


#if __has_feature(cxx_range_for)
@@ -144,8 +159,9 @@ int has_range_for();
int no_range_for();
#endif

// CHECK-0X: has_range_for
// CHECK-NO-0X: no_range_for
// CHECK-1Y: has_range_for
// CHECK-11: has_range_for
// CHECK-NO-11: no_range_for


#if __has_feature(cxx_reference_qualified_functions)
@@ -154,8 +170,9 @@ int has_reference_qualified_functions();
int no_reference_qualified_functions();
#endif

// CHECK-0X: has_reference_qualified_functions
// CHECK-NO-0X: no_reference_qualified_functions
// CHECK-1Y: has_reference_qualified_functions
// CHECK-11: has_reference_qualified_functions
// CHECK-NO-11: no_reference_qualified_functions

#if __has_feature(cxx_default_function_template_args)
int has_default_function_template_args();
@@ -163,8 +180,9 @@ int has_default_function_template_args();
int no_default_function_template_args();
#endif

// CHECK-0X: has_default_function_template_args
// CHECK-NO-0X: no_default_function_template_args
// CHECK-1Y: has_default_function_template_args
// CHECK-11: has_default_function_template_args
// CHECK-NO-11: no_default_function_template_args

#if __has_feature(cxx_noexcept)
int has_noexcept();
@@ -172,8 +190,9 @@ int has_noexcept();
int no_noexcept();
#endif

// CHECK-0X: has_noexcept
// CHECK-NO-0X: no_noexcept
// CHECK-1Y: has_noexcept
// CHECK-11: has_noexcept
// CHECK-NO-11: no_noexcept

#if __has_feature(cxx_override_control)
int has_override_control();
@@ -181,8 +200,9 @@ int has_override_control();
int no_override_control();
#endif

// CHECK-0X: has_override_control
// CHECK-NO-0X: no_override_control
// CHECK-1Y: has_override_control
// CHECK-11: has_override_control
// CHECK-NO-11: no_override_control

#if __has_feature(cxx_alias_templates)
int has_alias_templates();
@@ -190,8 +210,9 @@ int has_alias_templates();
int no_alias_templates();
#endif

// CHECK-0X: has_alias_templates
// CHECK-NO-0X: no_alias_templates
// CHECK-1Y: has_alias_templates
// CHECK-11: has_alias_templates
// CHECK-NO-11: no_alias_templates

#if __has_feature(cxx_implicit_moves)
int has_implicit_moves();
@@ -199,8 +220,9 @@ int has_implicit_moves();
int no_implicit_moves();
#endif

// CHECK-0X: has_implicit_moves
// CHECK-NO-0X: no_implicit_moves
// CHECK-1Y: has_implicit_moves
// CHECK-11: has_implicit_moves
// CHECK-NO-11: no_implicit_moves

#if __has_feature(cxx_alignas)
int has_alignas();
@@ -208,8 +230,9 @@ int has_alignas();
int no_alignas();
#endif

// CHECK-0X: has_alignas
// CHECK-NO-0X: no_alignas
// CHECK-1Y: has_alignas
// CHECK-11: has_alignas
// CHECK-NO-11: no_alignas

#if __has_feature(cxx_raw_string_literals)
int has_raw_string_literals();
@@ -217,8 +240,9 @@ int has_raw_string_literals();
int no_raw_string_literals();
#endif

// CHECK-0X: has_raw_string_literals
// CHECK-NO-0X: no_raw_string_literals
// CHECK-1Y: has_raw_string_literals
// CHECK-11: has_raw_string_literals
// CHECK-NO-11: no_raw_string_literals

#if __has_feature(cxx_unicode_literals)
int has_unicode_literals();
@@ -226,8 +250,9 @@ int has_unicode_literals();
int no_unicode_literals();
#endif

// CHECK-0X: has_unicode_literals
// CHECK-NO-0X: no_unicode_literals
// CHECK-1Y: has_unicode_literals
// CHECK-11: has_unicode_literals
// CHECK-NO-11: no_unicode_literals

#if __has_feature(cxx_constexpr)
int has_constexpr();
@@ -235,8 +260,9 @@ int has_constexpr();
int no_constexpr();
#endif

// CHECK-0X: has_constexpr
// CHECK-NO-0X: no_constexpr
// CHECK-1Y: has_constexpr
// CHECK-11: has_constexpr
// CHECK-NO-11: no_constexpr

#if __has_feature(cxx_generalized_initializers)
int has_generalized_initializers();
@@ -244,8 +270,9 @@ int has_generalized_initializers();
int no_generalized_initializers();
#endif

// CHECK-0X: has_generalized_initializers
// CHECK-NO-0X: no_generalized_initializers
// CHECK-1Y: has_generalized_initializers
// CHECK-11: has_generalized_initializers
// CHECK-NO-11: no_generalized_initializers

#if __has_feature(cxx_unrestricted_unions)
int has_unrestricted_unions();
@@ -253,8 +280,9 @@ int has_unrestricted_unions();
int no_unrestricted_unions();
#endif

// CHECK-0X: has_unrestricted_unions
// CHECK-NO-0X: no_unrestricted_unions
// CHECK-1Y: has_unrestricted_unions
// CHECK-11: has_unrestricted_unions
// CHECK-NO-11: no_unrestricted_unions

#if __has_feature(cxx_user_literals)
int has_user_literals();
@@ -262,8 +290,9 @@ int has_user_literals();
int no_user_literals();
#endif

// CHECK-0X: has_user_literals
// CHECK-NO-0X: no_user_literals
// CHECK-1Y: has_user_literals
// CHECK-11: has_user_literals
// CHECK-NO-11: no_user_literals

#if __has_feature(cxx_local_type_template_args)
int has_local_type_template_args();
@@ -271,8 +300,9 @@ int has_local_type_template_args();
int no_local_type_template_args();
#endif

// CHECK-0X: has_local_type_template_args
// CHECK-NO-0X: no_local_type_template_args
// CHECK-1Y: has_local_type_template_args
// CHECK-11: has_local_type_template_args
// CHECK-NO-11: no_local_type_template_args

#if __has_feature(cxx_inheriting_constructors)
int has_inheriting_constructors();
@@ -280,8 +310,9 @@ int has_inheriting_constructors();
int no_inheriting_constructors();
#endif

// CHECK-0X: has_inheriting_constructors
// CHECK-NO-0X: no_inheriting_constructors
// CHECK-1Y: has_inheriting_constructors
// CHECK-11: has_inheriting_constructors
// CHECK-NO-11: no_inheriting_constructors

#if __has_feature(cxx_thread_local)
int has_thread_local();
@@ -289,6 +320,29 @@ int has_thread_local();
int no_thread_local();
#endif

// CHECK-0X: has_thread_local
// CHECK-NO-0X: no_thread_local
// CHECK-1Y: has_thread_local
// CHECK-11: has_thread_local
// CHECK-NO-11: no_thread_local
// CHECK-NO-TLS: no_thread_local

// === C++1y features ===

#if __has_feature(cxx_binary_literals)
int has_binary_literals();
#else
int no_binary_literals();
#endif

// CHECK-1Y: has_binary_literals
// CHECK-11: no_binary_literals
// CHECK-NO-11: no_binary_literals

#if __has_feature(cxx_aggregate_nsdmi)
int has_aggregate_nsdmi();
#else
int no_aggregate_nsdmi();
#endif

// CHECK-1Y: has_aggregate_nsdmi
// CHECK-11: no_aggregate_nsdmi
// CHECK-NO-11: no_aggregate_nsdmi
Loading