Skip to content

Commit 6ac3501

Browse files
authored
🐛 (patch) Add exceptions an no-rtti ABI flags (#43)
* 🐛 (patch) Add exceptions an no-rtti ABI flags libhal projects use the no-rtti ABI flag to disable RTTI for all objects except for exceptions. Currently strong_ptr enables this ABI by not specifying that its disabled preventing its usage in programs with RTTI disabled. * Fix incorrect rc<T> destruction
1 parent a4f1dab commit 6ac3501

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ target_sources(strong_ptr PUBLIC
3434
FILES modules/strong_ptr.cppm
3535
)
3636

37+
target_compile_options(strong_ptr PRIVATE
38+
-g
39+
-Werror
40+
-Wno-unused-command-line-argument
41+
-Wall
42+
-Wextra
43+
-Wshadow
44+
-fexceptions
45+
-fno-rtti)
46+
3747
install(
3848
TARGETS strong_ptr
3949
EXPORT strong_ptr_targets
@@ -78,10 +88,13 @@ else()
7888
target_compile_options(strong_ptr_unit_test PUBLIC
7989
-g
8090
-Werror
91+
-Wno-unused-command-line-argument
8192
-Wall
8293
-Wextra
8394
-Wshadow
8495
-pedantic
96+
-fexceptions
97+
-fno-rtti
8598
)
8699

87100
# Enable ASAN only on non-Windows platforms (Windows doesn't support it)

modules/strong_ptr.cppm

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,7 @@ struct rc
284284
if (p_object != nullptr) {
285285
// Cast back into the original rc<T> type and ...
286286
auto const* obj = static_cast<rc<T> const*>(p_object);
287-
// Destruct T.
288-
obj->m_object.~T();
289-
// Destructor ref_info if its not trivially destructible. In general, this
290-
// should never be the case, but if we do modify ref_info to have a
291-
// non-trivial destructor, this will automatically manage that.
292-
if constexpr (not std::is_trivially_destructible_v<ref_info>) {
293-
obj->m_info.~ref_info();
294-
}
287+
obj->~rc<T>();
295288
}
296289
// Return size for future deallocation
297290
return sizeof(rc<T>);

test_package/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ target_sources(${PROJECT_NAME} PUBLIC
3535
)
3636
target_include_directories(${PROJECT_NAME} PUBLIC .)
3737
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_23)
38+
target_compile_options(${PROJECT_NAME} PRIVATE -fexceptions -fno-rtti)
3839
target_link_libraries(${PROJECT_NAME} PRIVATE strong_ptr)
3940

4041
# Always run this custom target by making it depend on ALL

0 commit comments

Comments
 (0)