diff --git a/rd-cpp/CMakeLists.txt b/rd-cpp/CMakeLists.txt index 703d4e4bc..8c26b90d8 100644 --- a/rd-cpp/CMakeLists.txt +++ b/rd-cpp/CMakeLists.txt @@ -32,6 +32,14 @@ if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "7.0.0") message(FATAL_ERROR "Insufficient clang version") endif () + if (CMAKE_BUILD_TYPE MATCHES "Debug") + option(USE_ADDRESS_SANITIZER "Use address sanitizer to troubleshoot invalid allocations" ON) + else () + option(USE_ADDRESS_SANITIZER "Use address sanitizer to troubleshoot invalid allocations" OFF) + endif () + if (USE_ADDRESS_SANITIZER) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -g") + endif() endif () if (MINGW) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj") diff --git a/rd-cpp/src/rd_core_cpp/src/test/cases/ViewableSetTest.cpp b/rd-cpp/src/rd_core_cpp/src/test/cases/ViewableSetTest.cpp index 4753380d3..9bbc4d776 100644 --- a/rd-cpp/src/rd_core_cpp/src/test/cases/ViewableSetTest.cpp +++ b/rd-cpp/src/rd_core_cpp/src/test/cases/ViewableSetTest.cpp @@ -6,11 +6,10 @@ using namespace rd; TEST(viewable_set, advise) { - std::unique_ptr> set = std::make_unique>(); - std::vector logAdvise; std::vector logView1; std::vector logView2; + std::unique_ptr> set = std::make_unique>(); LifetimeDefinition::use([&](Lifetime lt) { set->advise(lt, [&](AddRemove kind, int const& v) { logAdvise.push_back(kind == AddRemove::ADD ? v : -v); }); set->view(lt, [&](Lifetime inner, int const& v) { @@ -66,8 +65,8 @@ TEST(viewable_set, view) std::unique_ptr> set = std::make_unique>(); std::vector log; - auto x = LifetimeDefinition::use([&](Lifetime lifetime) { - set->view(lifetime, [&](Lifetime lt, int const& value) { + auto x = LifetimeDefinition::use([&](const Lifetime& lifetime) { + set->view(lifetime, [&](const Lifetime& lt, int const& value) { log.push_back("View " + std::to_string(value)); lt->add_action([&]() { log.push_back("UnView " + std::to_string(value)); }); });