BDE 4.14.0 Production release
|
Macros | |
#define | BSLS_COMPILERFEATURES_CPLUSPLUS 199711L |
#define | BSLS_COMPILERFEATURES_SUPPORT_THROW_SPECIFICATIONS 1 |
#define | BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES 1 |
#define | BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES 1 |
#define | BSLS_COMPILERFEATURES_SIMULATE_FORWARD_WORKAROUND 1 |
#define | BSLS_COMPILERFEATURES_FORWARD_REF(T) const T& |
#define | BSLS_COMPILERFEATURES_FORWARD(T, V) ::BloombergLP::bslmf::Util::forward(V) |
Provide macros to identify compiler support for C++11 features.
__cplusplus
T
to be forwardedV
of type T
__LINE__
value for multi-linealignas
[[fallthrough]]
[[maybe_unused]]
[[nodiscard]]
[[noreturn]]
attributeconstexpr
specifierconstexpr
spec.constexpr
spec.decltype
= default
= deleted
enum class
extern template
final
keyword__has_include
0x1.5p+5
supportedinline namespace
inline
variablesnoexcept
operatornoexcept
fnctype diffnullptr
explicit
operatoroverride
keyword<=>
operator<type_traits>
headerchar(16|32)_t
char8_t
This component provides a suite of preprocessor macros to identify compiler-specific support of language features that may not be available on all compilers in use across an organization. For example, as post-classic (C++11 and beyond) language facilities become more broadly available with sufficient quality (such as extern template
) macros will be defined here to indicate whether the current platform/compiler combination supports the corresponding language features. Note that in some cases, support for a given feature may need to be explicitly enabled by using an appropriate compiler command-line option.
This header is a large and complex mesh of fairly unrelated and deep preprocessor conditionals with defining and undefining of many features macros. It is hard for a human to scan this file and understand how and where particular feature macros are set. To make matter more difficult in certain circumstances we also unset/undefine macros. For this reason this header file uses a few special formatting rules to allow faster scanning:
1
(replacement text) of {Binary Macros} may be 79 characters long (plus newline). Line continuation characters in long preprocessor conditionals etc. must be placed onto column 78. This is to allow a human to easily scan the file for places where feature macros are being defined.#if*
) and the unusually long feature macro names defined in this header we use 2 spaces indentation to ensure that most preprocessor directives don't wrap (and become hard to read).Binary macros defined in this file (such as the BSLS_COMPILERFEATURES_SUPPORT_*
macros, and the BSLS_COMPILERFEATURES_INITIALIZER_LIST_LEAKS_ON_EXCEPTIONS
, and the BSLS_COMPILERFEATURES_PP_LINE_IS_ON_FIRST
macros) that represents a true/false preprocessor value are either undefined or defined to be the integer value 1. This allows the traditional, idiomatic use of these macros where more brief preprocessor conditions rely on the fact that the C and C++ preprocessors replace these unknown tokens with the value 0 in conditions: The following short condition
works identical to the following, longer one.
Note that the line continuation backslash has been replaced with /
to silence "multiline comment" warnings.
The following are the macros provided by this component. Note that they are not defined for all platform/compiler combinations.
BSLS_COMPILERFEATURES_CPLUSPLUS
This macro provides a portable way to determine the version of the C++ standard mode that is being used. In general, this has the same value as the standard
__cplusplus
macro, but on some compilers with some settings the standard macro does not get assigned the correct value. The values generally set (as defined in the C++ Standard) are the year and month when the Standard was completed, and the value of this macro should be compared with the appropriate constants:
- 199711L – before C++11
- 201103L – C++11
- 201402L – C++14
- 201703L – C++17
- 202002L – C++20
- 202302L – C++23 Note that compilers may report "in-between" values to indicate partial support of a standard, so
BSLS_COMPILERFEATURES_CPLUSPLUS > 201402L
normally means that some C++17 features are available. Since those values are not standardized their meaning varies.
BSLS_COMPILERFEATURES_FORWARD_REF(T)
This macro provides a portable way to declare a function template argument of type
T
that is to be perfect-forwarded. The expansion of the macro will use syntax that is appropriate for the current compiler settings for this platform.
BSLS_COMPILERFEATURES_FORWARD(T, V)
This macro provides a portable way to perfect-forward a function template argument,
V
, of typeT
. The expansion of the macro will use syntax that is appropriate for the current compiler settings for this platform. Note that due to the vagaries of implementing this macro, client code using this macro should provide the following two inclusions (in addition to the requisite inclusion of this header):
#include <bslmf_util.h>
#include <bsls_util.h>
BSLS_COMPILERFEATURES_GUARANTEED_COPY_ELISION
This macro is defined if the compiler always elides all copies (or moves) when returning a prvalue expression from a function and using that expression to initialize a class object of the same type (ignoring cv qualifications). Specifically, given the function,
Thing funcReturningThing() { return Thing(ctor-args...); }
, the return value is always initialized with(ctor-args...)
; no copy is performed in the return statement. Additionally,Thing var(funcReturningThing())
always constructsvar
directly from the return expression offuncReturningThing()
; again, no copies are involved. The semantics of these optimizations are guaranteed in C++17 and later, but are optional in previous versions of C++.
BSLS_COMPILERFEATURES_INITIALIZER_LIST_LEAKS_ON_EXCEPTIONS
The
BSLS_COMPILERFEATURES_INITIALIZER_LIST_LEAKS_ON_EXCEPTIONS
macro is defined for implementations that leak temporary objects constructed trying to initialize astd::initializer_list
object in the event that one of the elements of the list throws from its constructor. This is known to affect gcc as recently as the 8.x series, and the Sun CC compiler in C++11 mode. This would often reveal itself as a spurious memory leak in exception-safety tests for initializer_list constructors, so rises to the level of a generally supported defect-detection macro.
BSLS_COMPILERFEATURES_PP_LINE_IS_ON_FIRST
The
BSLS_COMPILERFEATURES_PP_LINE_IS_ON_FIRST
macro is defined for implementations that implement WG14 N2322 (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2322.htm) "Recommended practice" on the substitution value for the__LINE__
(predefined) preprocessor macro when expanding a macro that uses__LINE__
in its body, and that macro invocation spans multiple source lines (logical or physical). When macro is defined__LINE__
is substituted with the line number of the first character of the macro name of the (multi-line) macro invocation. When this macro is not defined__LINE__
is replaced (as traditional on older C++ compilers) by the line number of the last character of the macro invocation that expands to a use of__LINE__
. See also {Example 2:__LINE__
Macro Multi-line Value Differences Demonstration}.
BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
This macro is defined if alias templates are supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_ALIGNAS
This macro is defined if
alignas
alignment specifier is supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_ATTRIBUTE_FALLTHROUGH
This macro is defined if the
[[fallthrough]]
attribute is supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_ATTRIBUTE_MAYBE_UNUSED
This macro is defined if the
[[maybe_unused]]
attribute is supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_ATTRIBUTE_NODISCARD
This macro is defined if the
[[nodiscard]]
attribute is supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_ATTRIBUTE_NORETURN
This macro is defined if the
[[noreturn]]
attribute is supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_CONCEPTS
This macro is defined if the concepts core language feature is supported by the current compiler settings for this platform, as defined by ISO C++20.
BSLS_COMPILERFEATURES_SUPPORT_CONSTEXPR
This macro is defined if
constexpr
is supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_CONSTEXPR_CPP14
This macro is defined if
constexpr
with C++14 semantics is supported by the current compiler settings for this platform. In particular, this allows multiple statements in aconstexpr
function; changing state of local variables within the function; and making non-const
member functionsconstexpr
.
BSLS_COMPILERFEATURES_SUPPORT_CONSTEXPR_CPP17
This macro is defined if
constexpr
with C++17 semantics is supported by the current compiler settings for this platform. In particular, this allows lambda functions to be defined in aconstexpr
function.
BSLS_COMPILERFEATURES_SUPPORT_COROUTINE
This macro is defined if coroutines with C++20 (or later) semantics are supported by the current compiler settings, including the existence of the <coroutine> standard header that provides the basic library facilities necessary to make use of coroutines.
BSLS_COMPILERFEATURES_SUPPORT_CTAD
This macro is defined if template argument deduction introduced in the C++17 Standard are supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_DECLTYPE
This macro is defined if
decltype
is supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_DEFAULT_TEMPLATE_ARGS
This macro is defined if default template arguments for function templates are supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS
This macro is defined if defaulted functions are supported by the current compiler settings for this platform (i.e., via the
= default
syntax).
BSLS_COMPILERFEATURES_SUPPORT_DELETED_FUNCTIONS
This macro is defined if deleted functions are supported by the current compiler settings for this platform (i.e., via the
= delete
syntax).
BSLS_COMPILERFEATURES_SUPPORT_ENUM_CLASS
This macro is defined if
enum class
is supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_EXTERN_TEMPLATE
This macro is defined if
extern template
is supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_FINAL
This macro is defined if
final
is supported for classes and member functions by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS
This macro is defined if generalized initializers are supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_HAS_INCLUDE
This macro is defined if
__has_include
is supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_HEXFLOAT_LITERALS
This macro is defined if hexadecimal format literals for floating point types are supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_INCLUDE_NEXT
This macro is defined if include_next is supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_INLINE_NAMESPACE
This macro is defined if
inline
namespaces introduced in the C++11 Standard are supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES
This macro is defined if
inline
variables introduced in the C++17 Standard are supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT
This macro is defined if the
noexcept
keyword is supported by the current compiler settings for this platform, both for designating a function as not throwing and for testing if an expression may throw. The definition of this macro does not depend on whether the current compiler configuration has disabled support for exceptions.
BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT_IN_FNC_TYPE
This macro is defined if the
noexcept
keyword is supported by the current compiler settings for this platform such that ifnoexcept
is used to designate a function as not throwing, that use ofnoexcept
is explicitly considered part of the type of the function (a feature introduced in C++17). The definition of this macro does not depend on whether the current compiler configuration has disabled support for exceptions.
BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT_TYPES
Deprecated, use
BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT_IN_FNC_TYPE
instead.
BSLS_COMPILERFEATURES_SUPPORT_NULLPTR
This macro is defined if
nullptr
is supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_OPERATOR_EXPLICIT
This macro is defined if the
explicit
keyword applied to conversion operators is supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_OVERRIDE
This macro is defined if the
override
keyword is supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_RAW_STRINGS
This macro is defined if the compiler supports C++-11-style R"tag(string)tag" strings.
BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
This macro is defined if member functions with trailing reference qualifiers (e.g.,
void myfunc(int) &&
) are supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES
This macro is defined if rvalue references are supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_STATIC_ASSERT
This macro is defined if static_assert is supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
This macro is defined if
<=>
operator is supported by the current compiler settings for this platform. Including full library support as of C++20.
BSLS_COMPILERFEATURES_SUPPORT_THROW_SPECIFICATIONS
This macro is defined if dynamic exception specifications are supported by the current compiler settings for this platform. Dynamic exception specifications were deprecated in C++11, and actively removed from the language in C++17. The definition of this macro does not depend on whether the current compiler configuration has disabled support for exceptions.
BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER
This macro is defined if the standard library for the current compiler settings for this platform supports some form of the standard
<type_traits>
header. Note that many standard library implementations provided partial support for a long time, and those libraries will be identified as providing the<type_traits>
header.
BSLS_COMPILERFEATURES_SUPPORT_UNICODE_CHAR_TYPES
This macro is defined if the compiler supports the
char16_t
andchar32_t
types and the related u and U prefixes for character- and string-literal values.
BSLS_COMPILERFEATURES_SUPPORT_USER_DEFINED_LITERALS
This macro is defined if user-defined literals are supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_UTF8_CHAR_TYPE
This macro is defined if the compiler supports the
char8_t
type.
BSLS_COMPILERFEATURES_SUPPORT_VARIADIC_TEMPLATES
This macro is defined if variadic template parameters are supported by the current compiler settings for this platform.
BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
This macro is defined if variable templates introduced in the C++14 Standard are supported by the current compiler settings for this platform.
The following code snippets illustrate use of this component.
Suppose that we wish to "preinstantiate" bsl::basic_string
for a given character type, say, char
, on platforms that support extern template
. To accomplish this, we would do the following in the .h
and .cpp
files of the bslstl_string component:
Note that this isn't an example of use, it is a demonstration of compiler preprocessor behavior and the BSLS_COMPILERFEATURES_PP_LINE_IS_ON_FIRST
macro.
Sometimes we write code that uses line numbers for logging or other purposes. Although most of the time the precise values of those line numbers (in program output, such as assertions, or logs) is unimportant (the output is read by humans who are good at finding the line that actually emitted the text), sometimes programs read other programs' output. In such cases the precise values for the line numbers may matter. This example demonstrates the two ways our currently supported C++ compilers generate line numbers in multi-line macro expansion contexts (from the __LINE__
macro), and how the presence (or absence) of the macro BSLS_COMPILERFEATURES_PP_LINE_IS_ON_FIRST
indicates which method the current compiler uses. First, we define a macro that uses __LINE__
in its replacement text:
Note that this macro has the function-like syntax so we can easily span its invocation to multiple lines.
Next, we record the current line number in a constant, and also record the line number from our macro, but we span the macro invocation multiple lines to invoke the unspecified behavior.
The two lines must follow each other due to working with line numbering:
We deliberately extended the macro invocation to more than 2 physical source code lines so that we can demonstrate the two distinct behaviors: using the line number of the first character or the last. Extending the number of lines beyond the macro invocation (by placing the semicolon on its own line) has no effect on the line number substitution inside the macro. The dummy argument is required for C++03 compatibility.
If we follow the definition of A_LINE
without any intervening empty lines the line number of the first character of the macro invocation will be A_LINE + 1
, while the last falls on line A_LINE + 4
.
Now we demonstrate the two different behaviors and how the presence of BSLS_COMPILERFEATURES_PP_LINE_IS_ON_FIRST
indicates which one will occur:
Finally note that WG14 N2322 defines this behavior as unspecified, therefore it is in the realm of possibilities, although not likely (in C++ compilers) that further, more complicated or even indeterminate behaviors may arise.
This macro is defined if the compiler leaks temporary objects constructed trying to initialize a std::initializer_list
object in the event that one of the elements of the list throws from its constructor.
Note that https://en.cppreference.com/w/cpp/compiler_support is a useful reference for initial versions to test for support for various features.
This macro is defined if the compiler substitutes the __LINE__
macro in macro expansions with the line number of the first character of the macro invocation, which is the recommended practice for the C preprocessor (see WG14 N2322 at http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2322.htm). Note that all BDE supported compilers that do not define this macro use the line number of the last character of the macro invocation instead.
This macro is defined if the compiler supports syntax to introduce a typedef
-name using alias-declaration syntax, declaring a name for a family of types.
This macro is defined if the compiler supports the alignas
alignment specifier.
This feature is not yet supported in Visual Studio, IBM xlC, Oracle CC.
This macro is defined if the compiler supports [[noreturn]]
C++11 attribute syntax. MSVC supports the attribute with alternative syntax __declspec(noreturn), earlier versions of GCC and Clang support the alternative syntax __attribute__((noreturn))
, and xlC supports the alternative syntax _Noreturn
. This macro does not support alternative syntaxes.
This macro is defined if the compiler supports [[nodiscard]]
C++17 attribute syntax.
This macro is defined if the compiler supports [[fallthrough]]
C++17 attribute syntax.
This macro is defined if the compiler supports [[maybe_unused]]
C++17 attribute syntax.
This macro is defined if the concepts core language feature is fully supported, as defined by ISO C++20.
This macro is defined if the standard __cpp_concepts
feature-test macro has at least 202002L
value.
Note that clang 16.0 still has a bug that prevents it declaring C++20 concepts support. (At the time of writing (2023.Jun.01) clang trunk
does not yet declare C++20 concepts to be available, _cpp_concepts
is 201907LL).
This macro is defined in the compiler supports the constexpr
reserved keyword.
This macro is defined in the compiler supports the constexpr
reserved keyword with C++14 semantics.
This macro is defined if the compiler supports the constexpr
reserved keyword with C++17 semantics.
This macro is defined if the compiler supports at least the C++20 coroutine core language features and also provides the <coroutine>
standard header providing the basic library facilities necessary to make use of coroutines.
This macro is defined if the compiler supports the decltype
reserved word.
This macro is defined if the compiler supports syntax to introduce defaulted functions.
This macro is defined if the compiler supports syntax to introduce defaulted functions.
This macro is defined if the compiler supports syntax to introduce deleted functions.
This macro is defined if the compiler supports allowing suppression of implicit instantiation of templates by prefixing an explicit instantiation directive with the extern
keyword.
This macro is defined if the compiler supports both finalizing a class using the final
keyword after the class name as well as preventing further derived classes from overriding a virtual
function by using final
after its signature.
This macro is defined if the compiler supports generalized initializers.
This macro is defined if the compiler supports __has_include
semantics as defined in the C++17 Standard (see also P006R1). Note that this preprocessor feature is often available in earlier language dialects.
This macro is defined if the compiler supports #include_next.
This macro is defined if the compiler supports inline
namespaces introduced in the C++11 Standard.
This macro is defined if the compiler supports inline
variables introduced in the C++17 Standard.
This macro is defined if the compiler supports the noexcept
reserved keyword.
This macro is defined if the compiler supports the nullptr
reserved word.
This macro is defined if the compiler supports use of the explicit
keyword to indicate that a conversion operator only available for explicit conversions.
This macro is defined if the compiler supports use of the override
keyword to indicate that a member function is meant to override a virtual
function (and cause a failure if that is not the case).
This macro is defined if the compiler supports the use of C++11-style R"tag(string)tag" strings.
This macro is defined if member functions with trailing reference qualifiers (e.g., void myfunc(int) &
) and rvalue reference qualifiers (e.g., void myFunc(int) &&
) are supported. Note that this macro implies that BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES
is also defined.
This macro is defined if the compiler supports rvalue references and move semantics compatible with the final C++11 specification. (Semantics have changed since early draft proposals.)
This macro is defined if the compiler supports the static_assert reserved word.
This macro is defined if the compiler supports <=>
operator.
This macro is defined if the compiler supports the ability to express a template that accepts an arbitrary number of parameters in a type-safe manner.
This macro is defined if the compiler supports variable templates introduced in the C++14 Standard.
Microsoft Visual C++ in Microsoft Visual Studio has many different associated versions:
_MSVC_VER
(such as 19.32 and 1932)_MSVC_FULL_VER
(such as 193231329)The following table shows the mapping between the different version numbers. The source for the table was https://dev.to/yumetodo/list-of-mscver-and-mscfullver-8nd and the _MSC_VER
entry on https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros at 2020-12-13 20:00-05:00 (EST/New York).
(*) Visual Studio may receive interim updates that do not contribute into the Visual Studio "human friendly" version, but are visible in other version numbers.
#define BSLS_COMPILERFEATURES_CPLUSPLUS 199711L |
#define BSLS_COMPILERFEATURES_FORWARD | ( | T, | |
V | |||
) | ::BloombergLP::bslmf::Util::forward(V) |
#define BSLS_COMPILERFEATURES_FORWARD_REF | ( | T | ) | const T& |
#define BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES 1 |
#define BSLS_COMPILERFEATURES_SIMULATE_FORWARD_WORKAROUND 1 |
#define BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES 1 |
#define BSLS_COMPILERFEATURES_SUPPORT_THROW_SPECIFICATIONS 1 |