Skip to content

Commit d9482c6

Browse files
authored
Merge pull request #237 from parbo/rtti-option
Add option for using rtti
2 parents d598a05 + c583945 commit d9482c6

File tree

8 files changed

+29
-2
lines changed

8 files changed

+29
-2
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ script:
7777
- export PATH="${HOME}/bin:${PATH}"
7878
- ln -sf /usr/bin/ccache ${HOME}/bin/"${CXX}"
7979
- which ${CXX}
80-
- cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DRC_ENABLE_TESTS=ON -DRC_ENABLE_EXAMPLES=ON -DRC_ENABLE_GTEST=ON -DRC_ENABLE_GMOCK=ON -DRC_ENABLE_BOOST=ON -DRC_ENABLE_BOOST_TEST=ON -G Ninja ..
80+
- cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DRC_ENABLE_TESTS=ON -DRC_ENABLE_EXAMPLES=ON -DRC_ENABLE_GTEST=ON -DRC_ENABLE_GMOCK=ON -DRC_ENABLE_BOOST=ON -DRC_ENABLE_BOOST_TEST=ON -DRC_ENABLE_RTTI=ON -G Ninja ..
8181
- ccache --show-stats > ccache_before # collect stats
8282
- ninja -j1 # Don't run out of memory, please
8383
- ccache --show-stats > ccache_after

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ set(CMAKE_CXX_STANDARD 11)
1010

1111
option(RC_ENABLE_TESTS "Build RapidCheck tests" OFF)
1212
option(RC_ENABLE_EXAMPLES "Build RapidCheck examples" OFF)
13+
option(RC_ENABLE_RTTI "Build RapidCheck with RTTI" ON)
1314

1415
if(MSVC)
1516
# /bigobj - some object files become very large so we need this
@@ -101,6 +102,10 @@ if(MINGW)
101102
target_compile_definitions(rapidcheck PRIVATE RC_SEED_SYSTEM_TIME)
102103
endif()
103104

105+
if(RC_ENABLE_RTTI)
106+
add_definitions(-DRC_USE_RTTI)
107+
endif()
108+
104109
add_subdirectory(ext)
105110

106111
if(RC_ENABLE_TESTS)

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ build_script:
2323
- md build
2424
- cd build
2525
- "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat\" %ARCH%"
26-
- cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DRC_ENABLE_TESTS=ON -DRC_ENABLE_EXAMPLES=ON -DRC_ENABLE_GTEST=ON -DRC_ENABLE_GMOCK=ON -DRC_ENABLE_BOOST=ON -DRC_ENABLE_BOOST_TEST=ON -G "NMake Makefiles" ..
26+
- cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DRC_ENABLE_TESTS=ON -DRC_ENABLE_EXAMPLES=ON -DRC_ENABLE_GTEST=ON -DRC_ENABLE_GMOCK=ON -DRC_ENABLE_BOOST=ON -DRC_ENABLE_BOOST_TEST=ON -DRC_ENABLE_RTTI=ON -G "NMake Makefiles" ..
2727
- nmake
2828

2929
test_script:

include/rapidcheck/detail/Any.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class Any::IAnyImpl {
1515
virtual void *get() = 0;
1616
virtual void showType(std::ostream &os) const = 0;
1717
virtual void showValue(std::ostream &os) const = 0;
18+
#ifdef RC_USE_RTTI
1819
virtual const std::type_info &typeInfo() const = 0;
20+
#endif // RC_USE_RTTI
1921
virtual ~IAnyImpl() = default;
2022
};
2123

@@ -32,7 +34,9 @@ class Any::AnyImpl : public Any::IAnyImpl {
3234

3335
void showValue(std::ostream &os) const override { show(m_value, os); }
3436

37+
#ifdef RC_USE_RTTI
3538
const std::type_info &typeInfo() const override { return typeid(T); }
39+
#endif // RC_USE_RTTI
3640

3741
private:
3842
T m_value;
@@ -49,14 +53,18 @@ Any Any::of(T &&value) {
4953
template <typename T>
5054
const T &Any::get() const {
5155
assert(m_impl);
56+
#ifdef RC_USE_RTTI
5257
assert(m_impl->typeInfo() == typeid(T));
58+
#endif // RC_USE_RTTI
5359
return *static_cast<T *>(m_impl->get());
5460
}
5561

5662
template <typename T>
5763
T &Any::get() {
5864
assert(m_impl);
65+
#ifdef RC_USE_RTTI
5966
assert(m_impl->typeInfo() == typeid(T));
67+
#endif // RC_USE_RTTI
6068
return *static_cast<T *>(m_impl->get());
6169
}
6270

include/rapidcheck/detail/ShowType.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ struct ShowMultipleTypes<Type, Types...> {
4444
template <typename T>
4545
struct ShowType {
4646
static void showType(std::ostream &os) {
47+
#ifdef RC_USE_RTTI
4748
os << detail::demangle(typeid(T).name());
49+
#else
50+
os << "[unknown type]";
51+
#endif // RC_USE_RTTI
4852
}
4953
};
5054

include/rapidcheck/state/Command.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ void Command<Model, Sut>::run(const Model &s0, Sut &sut) const {}
1717

1818
template <typename Model, typename Sut>
1919
void Command<Model, Sut>::show(std::ostream &os) const {
20+
#ifdef RC_USE_RTTI
2021
os << ::rc::detail::demangle(typeid(*this).name());
22+
#else
23+
os << "[unknown command]";
24+
#endif // RC_USE_RTTI
2125
}
2226

2327
template <typename Model, typename Sut>

test/detail/ShowTypeTests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using namespace rc;
88
using namespace rc::test;
99
using namespace rc::detail;
1010

11+
#ifdef RC_USE_RTTI
1112
TEST_CASE("typeToString") {
1213
SECTION("shows primitive types correctly") {
1314
REQUIRE(typeToString<void>() == "void");
@@ -166,3 +167,4 @@ TEST_CASE("typeToString") {
166167
"std::shared_ptr<const FFoo *>");
167168
}
168169
}
170+
#endif // RC_USE_RTTI

test/state/gen/ExecCommandsTests.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct GeneratesOnConstrution : public IntVecCmd {
5050
#endif // defined(__GNUC__) || defined(__clang__)
5151

5252
TEST_CASE("state::gen::execOneOf") {
53+
#ifdef RC_USE_RTTI
5354
prop("returns one of the commands",
5455
[](const GenParams &params, const IntVec &s0) {
5556
const auto cmd =
@@ -73,6 +74,7 @@ TEST_CASE("state::gen::execOneOf") {
7374
}
7475
RC_SUCCEED("All generated");
7576
});
77+
#endif
7678

7779
prop("uses state constructor if there is one, passing it the state",
7880
[](const GenParams &params, const IntVec &s0) {
@@ -96,6 +98,7 @@ TEST_CASE("state::gen::execOneOf") {
9698
#endif // defined(__GNUC__) || defined(__clang__)
9799

98100
TEST_CASE("state::gen::execOneOfWithArgs") {
101+
#ifdef RC_USE_RTTI
99102
prop("returns one of the commands",
100103
[](const GenParams &params, const IntVec &s0) {
101104
const auto cmd = state::gen::execOneOfWithArgs<A, B, C>()()(
@@ -119,6 +122,7 @@ TEST_CASE("state::gen::execOneOfWithArgs") {
119122
}
120123
RC_SUCCEED("All generated");
121124
});
125+
#endif
122126

123127
prop("uses args constructor if there is one, passing it the state",
124128
[](const GenParams &params, const std::string &str, int num) {

0 commit comments

Comments
 (0)