Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview

Artifact ID: 01537d87a6fc3da7195c0e62988a3deabacc5ba4
Page Name:BehaviourMacros
Date: 2017-08-08 16:43:16
Original User: luismachuca
Parent: ceffde9a986a2a9f9ba3ef8acbe92b45d96d3e60
Content

Basic Macros

When this library is included in a piece of software, the following macros are defined:

  • CXXOMFORT_DATE - it expands to an unsigned integer representing the release date of the current version in the format YYYYMM.
  • CXXOMFORT_CXX_STD - resolves to a numeric value indicating the Standard version supported by the compiler, for example 2011 for C++11-compliant compilers.
  • CXXOMFORT_CXX_EMULATION - resolves to a numeric value that corresponds the Standard version that the compiler is emulating, if it is operating in an "emulation" mode such as GCC's c++0x.
  • CXXOMFORT_COMPILER_ID - this expands to a numerical code identifying the compiler, if it has been identified.
  • CXXOMFORT_COMPILER_VERSION - this expands to a numerical code identifying the compiler version, using the format 100*major+minor where possible.

The following macros exist and deliver information but are to be deprecated in a future version:

  • CXXOMFORT_VERSION - it expands to an unsigned integer representing the library version with the formula 100*major+minor.

Configuration Macros

The behaviour of this library can be queried or configured via a set of macros.

The following macros can be used to change the behaviour of this library:

  • CXXOMFORT_NOTICES - if defined and nonzero, the library will emit some diagnostics indicating what features are being used, etc. These diagnostics do not affect the code being compiled and are only informative. The higher the value of the macro, the more diagnostics does the library emit.
  • CXXOMFORT_NO_TR1 - if defined, the library will not #include some of the headers required for TR1 features. Note that this configuration is not supported, after all part of the purpose of this library is to make those features usable.

Diagnostics emitted by CXXOMFORT_NOTICES

== 1

Emits basic library identification messages.
Emits standard vs emulation notice.
Emits a message when an "Extra" feature is included.
== 2Emits compiler identification messages related to patches.
Emits notification when additions to TR1 library headers (<functional>, <tuple>, etc...) are included.
== 3Emits notifications of all features being included.Emits patching diagnostics.

"Standard Mode" and "Emulation Mode"

This library attempts to detect when the compiler supports the C++98/03, C++11 or C++14 Standard and is using its features, in which case it sets the value of the macro CXXOMFORT_CXX_STD to the given year (1998, 2011 or 2014) for use.

Identification of C++11 Mode relies in the Standard-specified method of announcing compliance - that is, by defining the identifier __cplusplus to an adequate value.

In some environments, the library can also detect if the compiler is operating in a C++11 or C++14 "emulation" mode, usually called "C++0x", "c++1y" or the like, where only a subset of features is implemented and/or they are done only partially. If such emulation mode is detected, the macro CXXOMFORT_CXX_EMULATION takes the value of the given year of the standard emulated.

Identification of Emulation Mode is a compiler-dependent and project-dependent feature, so this method is not exact. For a compiler to be recognized as operating in C++11 mode, for example, the following need to hapen:

  • The compiler advertises C++11 emulation mode by defining a particular macro (for example GNUXX_EXPERIMENTAL_CXX0X in GCC).

Values of the control macros under different settings:

* = no official support
[ 1 ] Compiler ID and version values
[ 2 ] _CXXOMFORT_CXX_STD
[ 3 ] _CXXOMFORT_CXX_EMULATION
+--------------------------------+----------+-------+-------+
| Setting                        | Compiler | _CXX_ | _CXX_ | 
|                                |    [ 1 ] | [1]   | [2]   |
+--------------------------------+----------+-------+-------+
| GCC 4.4 (*)                    |  101 404 |  1997 |     0 |
| GCC 4.4 with --std=c++0x (*)   |  101 404 |  1997 |  2011 |
| GCC 4.5 (*)                    |  101 405 |  2003 |     0 |
| GCC 4.5 with --std=c++0x (*)   |  101 405 |  2003 |  2011 |
| GCC 4.6                        |  101 406 |  2003 |     0 |
| GCC 4.6 with --std=c++0x       |  101 406 |  2003 |  2011 |
| GCC 4.7                        |  101 407 |  2003 |     0 |
| GCC 4.7 with --std=c++0x       |  101 407 |  2011 |  2011 |
| GCC 4.8                        |          |       |       |
| GCC 4.8 with --std=c++11       |          |       |       |
| Clang 3.0                      |  102 300 |  2003 |     0 |
| MSVC 2008 SP1                  |  103 150 |  1997 |     0 |
| MSVC 2010                      |  103 160 |  1997 |  2011 |
| MSVC 2012                      |          |       |       |
+--------------------------------+----------+-------+-------+

The library also sets a number of macros to determine what features are found as supported by the compiler in either Standard or Emulation mode:

Macro

Nonzero if...
CXXO_COMPILER_SUPPORT_attribute[[attribute]] is supported
CXXO_COMPILER_SUPPORT_autoC++11 type-deducing semantics for 'auto' is supported
CXXO_COMPILER_SUPPORT_constexpr'constexpr' is supported
CXXO_COMPILER_SUPPORT_decltype'decltype' is supported
CXXO_COMPILER_SUPPORT_default_deleteC++11 "=default" and "=delete" for members is supported
CXXO_COMPILER_SUPPORT_foreachC++11 'for(i: range)' syntax is supported
CXXO_COMPILER_SUPPORT_local_typesC++11 locally defined types as arguments for templates is supported
CXXO_COMPILER_SUPPORT_noexceptC++11 'noexcept' is supported
CXXO_COMPILER_SUPPORT_rvrefC++11 rvalue-references (T&&) is supported
CXXO_COMPILER_SUPPORT_variadicC++11 variadic template arguments is supported

The library also provides the ability to write conditional code depending on the detected C++ version: