Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CETL's polymorphic RTTI #110

Merged
merged 11 commits into from Apr 1, 2024
2 changes: 1 addition & 1 deletion cetlvast/cmake/compiler_flag_sets/default.cmake
Expand Up @@ -67,7 +67,7 @@ endif()

if (CETLVAST_DISABLE_CPP_EXCEPTIONS)
message(STATUS "CETLVAST_DISABLE_CPP_EXCEPTIONS is true. Adding -fno-exceptions to compiler flags.")
list(APPEND C_FLAG_SET
list(APPEND CXX_FLAG_SET
"-fno-exceptions")
endif()

Expand Down
44 changes: 44 additions & 0 deletions cetlvast/suites/compile/test_any_footprint_get_const.cpp
@@ -0,0 +1,44 @@
/// @file
/// Compile test that ensures it's impossible get "bigger" value than `Footprint` of const `any`.
///
/// @copyright
/// Copyright (C) OpenCyphal Development Team <opencyphal.org>
/// Copyright Amazon.com Inc. or its affiliates.
/// SPDX-License-Identifier: MIT
///

#include "cetl/any.hpp"

#include <cstdint>

namespace cetl
{
template <>
constexpr type_id type_id_value<uint8_t>{};

template <>
constexpr type_id type_id_value<uint16_t>{};

} // namespace cetl

int main()
{
using any = cetl::any<sizeof(uint8_t)>;

const any test{static_cast<uint8_t>(0)};

#ifndef CETLVAST_COMPILETEST_PRECHECK

// Verify at `cetl::detail::base_storage::get_ptr const`
// ```
// static_assert(sizeof(ValueType) <= Footprint,
// "Cannot contain the requested type since the footprint is too small");
// ```
return cetl::any_cast<uint16_t>(test);

#else

return cetl::any_cast<uint8_t>(test);

#endif
}
44 changes: 44 additions & 0 deletions cetlvast/suites/compile/test_any_footprint_get_non_const.cpp
@@ -0,0 +1,44 @@
/// @file
/// Compile test that ensures it's impossible set "bigger" value than `Footprint` of `any`.
///
/// @copyright
/// Copyright (C) OpenCyphal Development Team <opencyphal.org>
/// Copyright Amazon.com Inc. or its affiliates.
/// SPDX-License-Identifier: MIT
///

#include "cetl/any.hpp"

#include <cstdint>

namespace cetl
{
template <>
constexpr type_id type_id_value<uint8_t>{};

template <>
constexpr type_id type_id_value<uint16_t>{};

} // namespace cetl

int main()
{
using any = cetl::any<sizeof(uint8_t)>;

any test{static_cast<uint8_t>(0)};

#ifndef CETLVAST_COMPILETEST_PRECHECK

// Verify at `cetl::detail::base_storage::get_ptr`
// ```
// static_assert(sizeof(ValueType) <= Footprint,
// "Cannot contain the requested type since the footprint is too small");
// ```
return cetl::any_cast<uint16_t&>(test);

#else

return cetl::any_cast<uint8_t&>(test);

#endif
}
45 changes: 45 additions & 0 deletions cetlvast/suites/compile/test_any_footprint_set.cpp
@@ -0,0 +1,45 @@
/// @file
/// Compile test that ensures it's impossible set "bigger" value than `Footprint` of `any`.
///
/// @copyright
/// Copyright (C) OpenCyphal Development Team <opencyphal.org>
/// Copyright Amazon.com Inc. or its affiliates.
/// SPDX-License-Identifier: MIT
///

#include "cetl/any.hpp"

#include <cstdint>

namespace cetl
{
template <>
constexpr type_id type_id_value<uint8_t>{};

template <>
constexpr type_id type_id_value<uint16_t>{};

} // namespace cetl

int main()
{
using any = cetl::any<sizeof(uint8_t)>;

any test{};

#ifndef CETLVAST_COMPILETEST_PRECHECK

// Verify at `cetl::detail::base_storage::make_handlers`
// ```
// static_assert(sizeof(Tp) <= Footprint, "Enlarge the footprint");
// ```
test = static_cast<uint16_t>(1);

#else

test = static_cast<uint8_t>(1);

#endif

return 0;
}