NO_EXCEPTIONS, NO_RTTI dev presets

This commit is contained in:
BlackMATov
2023-01-10 18:28:38 +07:00
parent 57a031ae7a
commit d44cf16090
14 changed files with 106 additions and 29 deletions

View File

@@ -85,6 +85,20 @@
"BUILD_WITH_SANITIZERS": true
}
},
{
"name": "macos-arm64-san-no-exceptions",
"inherits": "macos-arm64-san",
"cacheVariables": {
"BUILD_WITH_NO_EXCEPTIONS": true
}
},
{
"name": "macos-arm64-san-no-rtti",
"inherits": "macos-arm64-san",
"cacheVariables": {
"BUILD_WITH_NO_RTTI": true
}
},
{
"name": "macos-x64",
"inherits": "macos-base",
@@ -100,6 +114,20 @@
"BUILD_WITH_SANITIZERS": true
}
},
{
"name": "macos-x64-san-no-exceptions",
"inherits": "macos-x64-san",
"cacheVariables": {
"BUILD_WITH_NO_EXCEPTIONS": true
}
},
{
"name": "macos-x64-san-no-rtti",
"inherits": "macos-x64-san",
"cacheVariables": {
"BUILD_WITH_NO_RTTI": true
}
},
{
"name": "windows-base",
"hidden": true,
@@ -218,20 +246,40 @@
"configurePreset": "linux-gcc-12"
},
{
"name": "macos-arm64-debug",
"name": "macos-arm64-debug-san",
"configuration": "Debug",
"configurePreset": "macos-arm64-san"
},
{
"name": "macos-arm64-debug-san-no-exceptions",
"configuration": "Debug",
"configurePreset": "macos-arm64-san-no-exceptions"
},
{
"name": "macos-arm64-debug-san-no-rtti",
"configuration": "Debug",
"configurePreset": "macos-arm64-san-no-rtti"
},
{
"name": "macos-arm64-release",
"configuration": "Release",
"configurePreset": "macos-arm64"
},
{
"name": "macos-x64-debug",
"name": "macos-x64-debug-san",
"configuration": "Debug",
"configurePreset": "macos-x64-san"
},
{
"name": "macos-x64-debug-san-no-exceptions",
"configuration": "Debug",
"configurePreset": "macos-x64-san-no-exceptions"
},
{
"name": "macos-x64-debug-san-no-rtti",
"configuration": "Debug",
"configurePreset": "macos-x64-san-no-rtti"
},
{
"name": "macos-x64-release",
"configuration": "Release",

View File

@@ -1,11 +1,15 @@
option(BUILD_WITH_COVERAGE "Build with coverage" OFF)
option(BUILD_WITH_SANITIZERS "Build with sanitizers" OFF)
option(BUILD_WITH_NO_EXCEPTIONS "Build with no exceptions" OFF)
option(BUILD_WITH_NO_RTTI "Build with no RTTI" OFF)
enable_testing()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake")
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(DisableExceptions)
include(DisableRTTI)
include(EnableASan)
include(EnableGCov)
include(EnableUBSan)

View File

@@ -0,0 +1,5 @@
add_library(${PROJECT_NAME}.disable_exceptions INTERFACE)
add_library(${PROJECT_NAME}::disable_exceptions ALIAS ${PROJECT_NAME}.disable_exceptions)
target_compile_options(${PROJECT_NAME}.disable_exceptions INTERFACE
-fno-exceptions)

View File

@@ -0,0 +1,5 @@
add_library(${PROJECT_NAME}.disable_rtti INTERFACE)
add_library(${PROJECT_NAME}::disable_rtti ALIAS ${PROJECT_NAME}.disable_rtti)
target_compile_options(${PROJECT_NAME}.disable_rtti INTERFACE
-fno-rtti)

View File

@@ -31,3 +31,16 @@ if(BUILD_WITH_SANITIZERS)
meta.hpp::enable_asan
meta.hpp::enable_ubsan)
endif()
if(BUILD_WITH_NO_EXCEPTIONS)
target_link_libraries(${PROJECT_NAME}.setup_targets INTERFACE
meta.hpp::disable_exceptions)
target_compile_definitions(${PROJECT_NAME}.setup_targets INTERFACE
DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS)
endif()
if(BUILD_WITH_NO_RTTI)
target_link_libraries(${PROJECT_NAME}.setup_targets INTERFACE
meta.hpp::disable_rtti)
endif()

View File

@@ -122,6 +122,6 @@ TEST_CASE("meta/meta_base/fixed_function") {
s = std::make_unique<int>(10)
](){};
fixed_function ff = std::move(f);
CHECK_NOTHROW(ff());
ff();
}
}

View File

@@ -330,9 +330,11 @@ TEST_CASE("meta/meta_features/diamond") {
CHECK(meta::resolve_type(cd) == meta::resolve_type<C>());
CHECK(meta::resolve_type(dd) == meta::resolve_type<D>());
#if !defined(META_HPP_NO_RTTI)
CHECK(meta::resolve_polymorphic_type(ad) == meta::resolve_type<D>());
CHECK(meta::resolve_polymorphic_type(bd) == meta::resolve_type<D>());
CHECK(meta::resolve_polymorphic_type(cd) == meta::resolve_type<D>());
CHECK(meta::resolve_polymorphic_type(dd) == meta::resolve_type<D>());
#endif
}
}

View File

@@ -136,20 +136,20 @@ TEST_CASE("meta/meta_states/member") {
}
{
CHECK_NOTHROW(vm.set(v, 10)); CHECK(vm.get(v) == 10);
CHECK_NOTHROW(vm.set(&v, 100)); CHECK(vm.get(v) == 100);
vm.set(v, 10); CHECK(vm.get(v) == 10);
vm.set(&v, 100); CHECK(vm.get(v) == 100);
CHECK_THROWS(vm.set(std::as_const(v), 11)); CHECK(vm.get(v) == 100);
CHECK_THROWS(vm.set(&std::as_const(v), 11)); CHECK(vm.get(v) == 100);
CHECK_NOTHROW(vm.set(std::move(v), 12)); CHECK(vm.get(v) == 12);
vm.set(std::move(v), 12); CHECK(vm.get(v) == 12);
CHECK_THROWS(vm.set(std::move(std::as_const(v)), 13)); CHECK(vm.get(v) == 12);
CHECK_NOTHROW(vm(v, 13)); CHECK(vm(v) == 13);
CHECK_NOTHROW(vm(&v, 130)); CHECK(vm(v) == 130);
vm(v, 13); CHECK(vm(v) == 13);
vm(&v, 130); CHECK(vm(v) == 130);
CHECK_THROWS(vm(std::as_const(v), 14)); CHECK(vm(v) == 130);
CHECK_THROWS(vm(std::as_const(v), 14)); CHECK(vm(v) == 130);
CHECK_NOTHROW(vm(std::move(v), 15)); CHECK(vm(v) == 15);
vm(std::move(v), 15); CHECK(vm(v) == 15);
CHECK_THROWS(vm(std::move(std::as_const(v)), 16)); CHECK(vm(v) == 15);
CHECK_THROWS(vm.set(v2, 17));

View File

@@ -84,8 +84,8 @@ TEST_CASE("meta/meta_states/variable") {
CHECK_FALSE(vm.is_settable_with<const float&>());
CHECK_FALSE(vm.is_settable_with(1.0));
CHECK_NOTHROW(vm.set(10)); CHECK(vm.get() == 10);
CHECK_NOTHROW(vm(11)); CHECK(vm() == 11);
vm.set(10); CHECK(vm.get() == 10);
vm(11); CHECK(vm() == 11);
}
SUBCASE("const int") {
@@ -132,8 +132,8 @@ TEST_CASE("meta/meta_states/variable") {
CHECK_FALSE(vm.is_settable_with<const float&>());
CHECK_FALSE(vm.is_settable_with(1.0));
CHECK_NOTHROW(vm.set(20)); CHECK(vm.get() == 20);
CHECK_NOTHROW(vm(21)); CHECK(vm() == 21);
vm.set(20); CHECK(vm.get() == 20);
vm(21); CHECK(vm() == 21);
}
SUBCASE("const ref int") {
@@ -169,7 +169,7 @@ TEST_CASE("meta/meta_states/variable") {
{
auto nv = std::make_unique<int>(11);
CHECK_NOTHROW(vm.set(std::move(nv)));
vm.set(std::move(nv));
CHECK(*clazz_1::unique_int_variable == 11);
}
@@ -190,7 +190,7 @@ TEST_CASE("meta/meta_states/variable") {
{
auto nv = std::make_unique<int>(13);
CHECK_NOTHROW(vm.set(std::move(nv)));
vm.set(std::move(nv));
CHECK(*clazz_1::unique_int_variable == 13);
}

View File

@@ -16,7 +16,7 @@ namespace
switch ( i ) {
case 0: return x;
case 1: return y;
default: throw std::out_of_range("ivec2::at");
default: std::abort();
}
}

View File

@@ -143,10 +143,10 @@ TEST_CASE("meta/meta_utilities/arg5/cast") {
static_assert(std::is_invocable_v<void(A* const), decltype(LV())>);
static_assert(std::is_invocable_v<void(const A* const), decltype(LV())>);
CHECK_NOTHROW([](A*){}(LV()));
CHECK_NOTHROW([](const A*){}(LV()));
CHECK_NOTHROW([](A* const){}(LV()));
CHECK_NOTHROW([](const A* const){}(LV()));
[](A*){}(LV());
[](const A*){}(LV());
[](A* const){}(LV());
[](const A* const){}(LV());
CHECK(uarg(LV()).cast<A*>() == static_cast<A*>(src));
CHECK(uarg(LV()).cast<const A*>() == static_cast<const A*>(src));

View File

@@ -75,7 +75,7 @@ namespace
if ( std::is_invocable_v<decltype(function_ptr), decltype(FromValue)> ) {\
CHECK(uarg{FromValue}.can_cast_to<ToType>());\
CHECK(uarg_base{type_list<decltype(FromValue)>{}}.can_cast_to<ToType>());\
CHECK_NOTHROW(std::ignore = uarg{FromValue}.cast<ToType>());\
std::ignore = uarg{FromValue}.cast<ToType>();\
\
CHECK(f_state.is_invocable_with<decltype(FromValue)>());\
CHECK(f_state.invoke(FromValue) == 1);\

View File

@@ -35,7 +35,7 @@ namespace
if ( std::is_invocable_v<decltype(method_ptr), decltype(Inst)> ) {\
CHECK(uinst{Inst}.can_cast_to<clazz Qualifiers>());\
CHECK(uinst_base{type_list<decltype(Inst)>{}}.can_cast_to<clazz Qualifiers>());\
CHECK_NOTHROW(std::ignore = uinst{Inst}.cast<clazz Qualifiers>());\
std::ignore = uinst{Inst}.cast<clazz Qualifiers>();\
\
CHECK(m_state.is_invocable_with<decltype(Inst)>());\
CHECK(m_state.invoke(Inst) == 1);\

View File

@@ -379,7 +379,7 @@ TEST_CASE("meta/meta_utilities/value") {
SUBCASE("ostream") {
std::stringstream str_stream;
CHECK_NOTHROW(str_stream << meta::uvalue{21} << " " << meta::uvalue{42});
str_stream << meta::uvalue{21} << " " << meta::uvalue{42};
CHECK_THROWS((str_stream << meta::uvalue{ivec2{1,2}}));
REQUIRE(str_stream.str() == "21 42");
}
@@ -391,9 +391,9 @@ TEST_CASE("meta/meta_utilities/value") {
CHECK_THROWS(str_stream >> v);
v = meta::uvalue{0};
CHECK_NOTHROW(str_stream >> v);
str_stream >> v;
CHECK(v == 21);
CHECK_NOTHROW(str_stream >> v);
str_stream >> v;
CHECK(v == 42);
}
@@ -436,10 +436,10 @@ TEST_CASE("meta/meta_utilities/value") {
{
int i{42};
void* p1 = &i;
const void* p2 = &i;
void* const& p3 = &i;
const void* const& p4 = &i;
[[maybe_unused]] void* p1 = &i;
[[maybe_unused]] const void* p2 = &i;
[[maybe_unused]] void* const& p3 = &i;
[[maybe_unused]] const void* const& p4 = &i;
CHECK_THROWS(std::ignore = *meta::uvalue(p1));
CHECK_THROWS(std::ignore = *meta::uvalue(p2));