|
1 | 1 | /// @file |
2 | 2 | /// CETL common header. |
3 | 3 | /// |
| 4 | +/// @copyright |
| 5 | +/// Copyright (C) OpenCyphal Development Team <opencyphal.org> |
| 6 | +/// Copyright Amazon.com Inc. or its affiliates. |
| 7 | +/// SPDX-License-Identifier: MIT |
| 8 | +/// |
4 | 9 | /// @note |
5 | 10 | /// Keep this very spare. CETL's desire is to adapt to future C++ standards |
6 | 11 | /// and too many CETL-specific definitions makes it difficult for users to switch off of CETL in the |
7 | 12 | /// future. |
8 | 13 | /// |
9 | | -/// @copyright |
10 | | -/// Copyright (C) OpenCyphal Development Team <opencyphal.org> |
11 | | -/// Copyright Amazon.com Inc. or its affiliates. |
12 | | -/// SPDX-License-Identifier: MIT |
| 14 | +/// If `CETL_H_ERASE` is defined then all CETL types will exclude the `cetl/cetl.hpp` header which |
| 15 | +/// removes all common dependencies, other than C++ standard headers, from CETL. The types will not build due to |
| 16 | +/// missing macros but the user can re-define these based on subsequent compiler errors. This allows elision of |
| 17 | +/// cetl.hpp without modifying CETL source code. The CETL types are not guaranteed to work with cetl.hpp removed; you |
| 18 | +/// have been warned. |
| 19 | +/// |
| 20 | +/// @warning |
| 21 | +/// polyfill headers cannot be used if CETL_H_ERASE is defined. Presumably, if you really want to minimize your |
| 22 | +/// dependencies, you would not be using the polyfill headers. |
13 | 23 | /// |
14 | 24 |
|
15 | 25 | #ifndef CETL_H_INCLUDED |
16 | 26 | #define CETL_H_INCLUDED |
17 | 27 |
|
| 28 | +#ifdef CETL_H_ERASE |
| 29 | +# error "CETL_H_ERASE was defined. This header should never be included when the build is trying to erase it!" |
| 30 | +#endif |
| 31 | + |
| 32 | +/// @defgroup CETL_VERSION The semantic version number of the CETL library. |
| 33 | +/// These macros are an AUTOSAR-14 Rule A16-0-1 violation but we feel it necessary to provide them. |
| 34 | +/// @{ |
| 35 | + |
| 36 | +/// @def CETL_VERSION_PATCH |
| 37 | +/// CETL Patch version. |
| 38 | +/// Patch versions shall always be backwards compatible with the same major |
| 39 | +/// and minor version. A patch version number change will only occur if library source code is changed. |
| 40 | +/// Documentation or test suite changes will not require a change to `cetl/cetl.hpp` and will not bump |
| 41 | +/// the patch version. |
| 42 | +#define CETL_VERSION_PATCH 0 |
| 43 | + |
| 44 | +/// @def CETL_VERSION_MINOR |
| 45 | +/// CETL minor version. |
| 46 | +/// Minor versions shall only add to CETL or modify it in a backwards compatible way. |
| 47 | +#define CETL_VERSION_MINOR 0 |
| 48 | + |
| 49 | +/// @def CETL_VERSION_MAJOR |
| 50 | +/// CETL Major version. |
| 51 | +/// New major versions shall be rare. No overarching guarantees are made about compatibility |
| 52 | +/// between major versions. |
| 53 | +#define CETL_VERSION_MAJOR 0 |
| 54 | + |
| 55 | +/// @} |
| 56 | + |
18 | 57 | /// @def CETL_DEBUG_ASSERT |
19 | 58 | /// When `CETL_ENABLE_DEBUG_ASSERT` is defined and not 0 then this is redirected to |
20 | 59 | /// assert as included from `<cassert>`. Because assert does not support a failure message |
|
36 | 75 | # define CETL_DEBUG_ASSERT(c, m) ((void) m) |
37 | 76 | #endif // CETL_ENABLE_DEBUG_ASSERT |
38 | 77 |
|
39 | | -// For example: https://godbolt.org/z/Thsn8qf1a |
40 | | -// We define these in a common header since we might encounter odd values on some compilers that we'll have to |
41 | | -// provide special cases for. |
42 | | - |
43 | 78 | /// @defgroup CETL_CPP_STANDARD Guaranteed CETL c++ standard numbers |
44 | 79 | /// These macros are an AUTOSAR-14 Rule A16-0-1 violation but can be used to conditionally include headers which |
45 | | -/// is compliant with A16-0-1. |
| 80 | +/// is compliant with A16-0-1. The values were obtained by observation of compiler output using |
| 81 | +/// [godbolt](https://godbolt.org/z/Thsn8qf1a) and as predicted by |
| 82 | +/// [cppreference.com](https://en.cppreference.com/w/cpp/preprocessor/replace#Predefined_macros). |
| 83 | +/// |
| 84 | +/// @note |
| 85 | +/// Some CETL types don't use these values directly to reduce the number of explicit dependencies on cetl.hpp but by |
| 86 | +/// including `cetl/cetl.hpp` these types inherit the static assertions that the only valid values of `__cplusplus` |
| 87 | +/// found are one of the the list found in this group or a value greater than the target support `CETL_CPP_STANDARD_20` |
| 88 | +/// value. |
| 89 | +/// |
46 | 90 | /// @{ |
47 | 91 |
|
48 | 92 | /// @def CETL_CPP_STANDARD_14 |
|
76 | 120 | #define CETL_CPP_STANDARD_20 202002L |
77 | 121 |
|
78 | 122 | /// @} |
| 123 | + |
| 124 | +// Ensure base support. |
| 125 | +static_assert(__cplusplus >= CETL_CPP_STANDARD_14, |
| 126 | + "Unsupported language: ISO C14, C++14, or a newer version of either is required to use this type."); |
| 127 | + |
| 128 | +// Detect weird versions |
| 129 | +static_assert(__cplusplus == CETL_CPP_STANDARD_14 || __cplusplus == CETL_CPP_STANDARD_17 || |
| 130 | + __cplusplus >= CETL_CPP_STANDARD_20, |
| 131 | + "Unknown __cplusplus value found?"); |
| 132 | + |
79 | 133 | #endif // CETL_H_INCLUDED |
0 commit comments