BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsls_compilerfeatures

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)
 

Detailed Description

Outline

Purpose

Provide macros to identify compiler support for C++11 features.

Macros

See also
bsls_libraryfeatures, bsls_platform

Description

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.

Special Formatting Rules and Allowances

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. Only comments and the 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.
  2. Feature macro definitions that are commented out (to indicate that for a given compiler + standard library combination the support does not exist) must not have the replacement text (the number 1) be present so as not to confuse a human reader not using syntax highlighting.
  3. Due to the depth of necessary conditional branches (#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

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

#if BSLS_COMPILERFEATURES_SUPPORT_CTAD && /
BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES
#define U_TAKE_MY_FINAL_FORM 1
#endif

works identical to the following, longer one.

#if defined(BSLS_COMPILERFEATURES_SUPPORT_CTAD) && /
defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
#define U_TAKE_MY_FINAL_FORM 1
#endif

Note that the line continuation backslash has been replaced with / to silence "multiline comment" warnings.

Macro Summary

The following are the macros provided by this component. Note that they are not defined for all platform/compiler combinations.

Usage

The following code snippets illustrate use of this component.

Example 1: Using BSLS_COMPILERFEATURES_SUPPORT_EXTERN_TEMPLATE

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:

// bslstl_string.h
// ...
#ifdef BSLS_COMPILERFEATURES_SUPPORT_EXTERN_TEMPLATE
extern template class bsl::basic_string<char>;
#endif
// ...
// bslstl_string.cpp
// ...
#ifdef BSLS_COMPILERFEATURES_SUPPORT_EXTERN_TEMPLATE
template class bsl::basic_string<char>;
#endif
// ...
Definition bslstl_string.h:1043
Definition bslstl_string.h:1281

Example 2: <strong>LINE</strong> Macro Multi-line Value Differences Demonstration

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:

#define THATS_MY_LINE(dummy) __LINE__

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:

const long A_LINE = __LINE__;
const long LINE_FROM_MACRO = THATS_MY_LINE
(
"dummy"
)
. ;

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:

#ifdef BSLS_COMPILERFEATURES_PP_LINE_IS_ON_FIRST
assert(A_LINE + 1 == LINE_FROM_MACRO);
#else
assert(A_LINE + 4 == LINE_FROM_MACRO);
#endif

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.

Bugs in Compilers

BSLS_COMPILERFEATURES_INITIALIZER_LIST_LEAKS_ON_EXCEPTIONS

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.

Feature Support in Compilers

Note that https://en.cppreference.com/w/cpp/compiler_support is a useful reference for initial versions to test for support for various features.

BSLS_COMPILERFEATURES_PP_LINE_IS_ON_FIRST

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.

BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES

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.

BSLS_COMPILERFEATURES_SUPPORT_ALIGNAS

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.

BSLS_COMPILERFEATURES_SUPPORT_ATTRIBUTE_NORETURN

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.

BSLS_COMPILERFEATURES_SUPPORT_ATTRIBUTE_NODISCARD

This macro is defined if the compiler supports [[nodiscard]] C++17 attribute syntax.

BSLS_COMPILERFEATURES_SUPPORT_ATTRIBUTE_FALLTHROUGH

This macro is defined if the compiler supports [[fallthrough]] C++17 attribute syntax.

BSLS_COMPILERFEATURES_SUPPORT_ATTRIBUTE_MAYBE_UNUSED

This macro is defined if the compiler supports [[maybe_unused]] C++17 attribute syntax.

BSLS_COMPILERFEATURES_SUPPORT_CONCEPTS

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).

BSLS_COMPILERFEATURES_SUPPORT_CONSTEXPR

This macro is defined in the compiler supports the constexpr reserved keyword.

BSLS_COMPILERFEATURES_SUPPORT_CONSTEXPR_CPP14

This macro is defined in the compiler supports the constexpr reserved keyword with C++14 semantics.

BSLS_COMPILERFEATURES_SUPPORT_CONSTEXPR_CPP17

This macro is defined if the compiler supports the constexpr reserved keyword with C++17 semantics.

BSLS_COMPILERFEATURES_SUPPORT_COROUTINE

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.

BSLS_COMPILERFEATURES_SUPPORT_DECLTYPE

This macro is defined if the compiler supports the decltype reserved word.

BSLS_COMPILERFEATURES_SUPPORT_DEFAULT_TEMPLATE_ARGS

This macro is defined if the compiler supports syntax to introduce defaulted functions.

BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS

This macro is defined if the compiler supports syntax to introduce defaulted functions.

BSLS_COMPILERFEATURES_SUPPORT_DELETED_FUNCTIONS

This macro is defined if the compiler supports syntax to introduce deleted functions.

BSLS_COMPILERFEATURES_SUPPORT_EXTERN_TEMPLATE

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.

BSLS_COMPILERFEATURES_SUPPORT_FINAL

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.

BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS

This macro is defined if the compiler supports generalized initializers.

BSLS_COMPILERFEATURES_SUPPORT_HAS_INCLUDE

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.

BSLS_COMPILERFEATURES_SUPPORT_INCLUDE_NEXT

This macro is defined if the compiler supports #include_next.

BSLS_COMPILERFEATURES_SUPPORT_INLINE_NAMESPACE

This macro is defined if the compiler supports inline namespaces introduced in the C++11 Standard.

BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES

This macro is defined if the compiler supports inline variables introduced in the C++17 Standard.

BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT

This macro is defined if the compiler supports the noexcept reserved keyword.

BSLS_COMPILERFEATURES_SUPPORT_NULLPTR

This macro is defined if the compiler supports the nullptr reserved word.

BSLS_COMPILERFEATURES_SUPPORT_OPERATOR_EXPLICIT

This macro is defined if the compiler supports use of the explicit keyword to indicate that a conversion operator only available for explicit conversions.

BSLS_COMPILERFEATURES_SUPPORT_OVERRIDE

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).

BSLS_COMPILERFEATURES_SUPPORT_RAW_STRINGS

This macro is defined if the compiler supports the use of 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) &) 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.

BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES

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.)

BSLS_COMPILERFEATURES_SUPPORT_STATIC_ASSERT

This macro is defined if the compiler supports the static_assert reserved word.

BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON

This macro is defined if the compiler supports <=> operator.

BSLS_COMPILERFEATURES_SUPPORT_VARIADIC_TEMPLATES

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.

BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES

This macro is defined if the compiler supports variable templates introduced in the C++14 Standard.

Microsoft Visual Studio versions mapping

Microsoft Visual C++ in Microsoft Visual Studio has many different associated versions:

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 name & version | Toolset | _MSC_VER | _MSC_FULL_VER |
+===================+==========+=========+==========+===============+
| 2015 | 14.0 | 14.0 | 1900 | 190023026 |
| 2015 Update 1 | 14.0 | 14.0 | 1900 | 190023506 |
| 2015 Update 2 | 14.0 | 14.0 | 1900 | 190023918 |
| 2015 Update 3 | 14.0 | 14.0 | 1900 | 190024210 |
+-------------------+----------+---------+----------+---------------+
| 2017 | 15.0 | 14.10 | 1910 | 191025017 |
| 2017 Update 1 | 15.1 | 14.10 | 1910 | 191025017 |
| 2017 Update 2 | 15.2 | 14.10 | 1910 | 191025017 |
| 2017 Update 3 | 15.3.3 | 14.11 | 1911 | 191125507 |
| 2017 Update 4 | 15.4.4 | 14.11 | 1911 | 191125542 |
| Update 4(*) | 15.4.5 | 14.11 | 1911 | 191125547 |
| 2017 Update 5 | 15.5.2 | 14.12 | 1912 | 191225831 |
| Update 5(*) | 15.5.3 | 14.12 | 1912 | 191225834 |
| Update 5(*) | 15.5.4 | 14.12 | 1912 | 191225834 |
| Update 5(*) | 15.5.6 | 14.12 | 1912 | 191225835 |
| Update 5(*) | 15.5.7 | 14.12 | 1912 | 191225835 |
| 2017 Update 6 | 15.6.0 | 14.13 | 1913 | 191326128 |
| Update 6(*) | 15.6.1 | 14.13 | 1913 | 191326128 |
| Update 6(*) | 15.6.2 | 14.13 | 1913 | 191326128 |
| Update 6(*) | 15.6.3 | 14.13 | 1913 | 191326129 |
| Update 6(*) | 15.6.4 | 14.13 | 1913 | 191326129 |
| Update 6(*) | 15.6.6 | 14.13 | 1913 | 191326131 |
| Update 6(*) | 15.6.7 | 14.13 | 1913 | 191326132 |
| 2017 Update 7 | 15.7.1 | 14.14 | 1914 | 191426428 |
| Update 7(*) | 15.7.2 | 14.14 | 1914 | 191426429 |
| Update 7(*) | 15.7.3 | 14.14 | 1914 | 191426430 |
| Update 7(*) | 15.7.5 | 14.14 | 1914 | 191426433 |
| 2017 Update 8 | 15.8.0 | 14.15 | 1915 | ? |
| 2017 Update 9 | 15.9.0 | 14.16 | 1916 | ? |
| Update 9(*) | 15.9.1 | 14.16 | 1916 | 191627023 |
| Update 9(*) | 15.9.4 | 14.16 | 1916 | 191627025 |
| Update 9(*) | 15.9.5 | 14.16 | 1916 | 191627026 |
| Update 9(*) | 15.9.7 | 14.16 | 1916 | 191627027 |
| Update 9(*) | 15.9.11 | 14.16 | 1916 | 191627030 |
+-------------------+----------+---------+----------+---------------+
| 2019 | 16.0 | 14.20 | 1920 | 192027508 |
| 2019 Update 1 | 16.1.2 | 14.21 | 1921 | 192127702 |
| 2019 Update 2 | 16.2.3 | 14.21 | 1922 | 192227905 |
| 2019 Update 3 | 16.3.2 | 14.21 | 1923 | 192328105 |
| 2019 Update 4 | 16.4.0 | 14.24 | 1924 | 192428314 |
| 2019 Update 5 | 16.5.1 | 14.25 | 1925 | 192528611 |
| 2019 Update 6 | 16.6.2 | 14.26 | 1926 | 192628806 |
| 2019 Update 7 | 16.7 | 14.27 | 1927 | 192729112 |
| 2019 Update 8 | 16.8.1 | 14.28 | 1928 | 192829333 |
| Update 8(*) | 16.8.2 | 14.28 | 1928 | 192829334 |
| 2019 Update 9 | 16.9.2 | 14.28 | 1928 | 192829913 |
| 2019 Update 11 | 16.11.2 | 14.28 | 1929 | 192930133 |
+-------------------+----------+---------+----------+---------------+
| 2022 | 17.0.1 | 14.30 | 1930 | 193030705 |
| 2022(*) | 17.0.2 | 14.30 | 1930 | 193030706 |
| 2022(*) | 17.2.2 | 14.30 | 1932 | 193231329 |
| 2022(*) | 17.3.4 | 14.30 | 1933 | 193331630 |
+-------------------+----------+---------+----------+---------------+

(*) Visual Studio may receive interim updates that do not contribute into the Visual Studio "human friendly" version, but are visible in other version numbers.

####################################################################
########################################################################
## ##
## THIS HEADER FILE HAS SPECIAL FORMATTING RULES! ##
## ************************************************ ##
## ##
## Please follow the rules when updating it. For specific reasons and ##
## details please see {Special Formatting Rules and Allowances} above. ##
## ##
########################################################################
####################################################################

Macro Definition Documentation

◆ BSLS_COMPILERFEATURES_CPLUSPLUS

#define BSLS_COMPILERFEATURES_CPLUSPLUS   199711L

◆ BSLS_COMPILERFEATURES_FORWARD

#define BSLS_COMPILERFEATURES_FORWARD (   T,
 
)     ::BloombergLP::bslmf::Util::forward(V)

◆ BSLS_COMPILERFEATURES_FORWARD_REF

#define BSLS_COMPILERFEATURES_FORWARD_REF (   T)    const T&

◆ BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES

#define BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES   1

◆ BSLS_COMPILERFEATURES_SIMULATE_FORWARD_WORKAROUND

#define BSLS_COMPILERFEATURES_SIMULATE_FORWARD_WORKAROUND   1

◆ BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES

#define BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES   1

◆ BSLS_COMPILERFEATURES_SUPPORT_THROW_SPECIFICATIONS

#define BSLS_COMPILERFEATURES_SUPPORT_THROW_SPECIFICATIONS   1