Skip to content

Commit dd81b53

Browse files
committed
Unit tests: Update <mstd_type_traits> stub
The stub version of <mstd_type_traits> is mostly identical to the production file of the same name, except the former lags behind and doesn't contain the recent "is_constant_evaluated" feature. It's safe to update the stub file, because "is_constant_evaluated" only checks generic GCC and Clang versions that also apply to compilers on PCs. This enables MbedCRC.h to include <mstd_type_traits> without distinguishing between Mbed applications and unit tests.
1 parent eb6d1aa commit dd81b53

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

UNITTESTS/target_h/platform/cxxsupport/mstd_type_traits

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,14 @@
2020
/* <mstd_type_traits>
2121
*
2222
* - includes toolchain's <type_traits>
23-
* - For ARM C 5, standard C++11/14 features:
24-
* - std::integral_constant, std::true_type, std::false_type
25-
* - primary type categories (std::is_void, std::is_integral etc)
26-
* - composite type categories (std::is_reference etc)
27-
* - type properties (std::is_const, std::is_constructible etc), except std::is_final
28-
* - type property queries (std::alignment_of, std::rank, std::extent)
29-
* - type relations (std::is_same, std::is_base_of, std::is_convertible)
30-
* - const-volatile modifications (std::remove_cv, std::add_const etc)
31-
* - reference modifications (std::remove_reference, std::add_lvalue_reference etc)
32-
* - sign modifications (std::make_signed, std::make_unsigned)
33-
* - array modifications (std::remove_extent, std::remove_all_extents)
34-
* - pointer modifications (std::remove_pointer, std::add_pointer)
35-
* - other modifications:
36-
* - std::aligned_storage
37-
* - std::decay
38-
* - std::enable_if
39-
* - std::conditional
40-
* - std::common_type
41-
* - std::underlying_type
42-
* - std::result_of
4323
* - For all toolchains, C++17/20 backports:
4424
* - mstd::type_identity
4525
* - mstd::bool_constant
4626
* - mstd::void_t
4727
* - mstd::is_invocable, mbed::is_invocable_r, etc
4828
* - mstd::invoke_result
4929
* - logical operator traits (mstd::conjunction, mstd::disjunction, mstd::negation)
30+
* - mstd::is_constant_evaluated
5031
*/
5132

5233
#include <mstd_cstddef>
@@ -55,7 +36,6 @@
5536
// The template stuff in here is too confusing for astyle
5637
// *INDENT-OFF*
5738

58-
5939
namespace mstd {
6040

6141
/* C++20 type identity */
@@ -92,6 +72,10 @@ template <typename F, typename... Args>
9272
struct invoke_result;
9373
#endif
9474

75+
} // namespace mstd
76+
77+
namespace mstd {
78+
9579
using std::is_same;
9680
using std::conditional;
9781
using std::conditional_t;
@@ -462,8 +446,30 @@ struct is_nothrow_invocable_r : impl::is_invocable_r<R, invoke_result<F, Args...
462446

463447
#endif // __cpp_lib_is_invocable
464448

449+
/* C++20 is_constant_evaluated */
450+
constexpr bool is_constant_evaluated() noexcept
451+
{
452+
#ifdef __clang__
453+
#if __has_builtin(__builtin_is_constant_evaluated)
454+
#define MSTD_HAS_IS_CONSTANT_EVALUATED 1
455+
return __builtin_is_constant_evaluated();
456+
#else
457+
return false;
458+
#endif
459+
#elif __GNUC__ >= 9
460+
#define MSTD_HAS_IS_CONSTANT_EVALUATED 1
461+
return __builtin_is_constant_evaluated();
462+
#else
463+
return false;
464+
#endif
465+
}
465466

466-
} // namespace mstd
467+
#if MSTD_HAS_IS_CONSTANT_EVALUATED
468+
#define MSTD_CONSTEXPR_IF_HAS_IS_CONSTANT_EVALUATED constexpr
469+
#else
470+
#define MSTD_CONSTEXPR_IF_HAS_IS_CONSTANT_EVALUATED
471+
#endif
467472

473+
} // namespace mstd
468474

469475
#endif /* MSTD_TYPE_TRAITS_ */

0 commit comments

Comments
 (0)