Skip to content

Commit

Permalink
Suppress -Wunused-value warnings, closes #36
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Jul 2, 2019
1 parent 5e3f7a4 commit 9c80847
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ if (DBG_MACRO_ENABLE_TESTS)
target_compile_options(${PROJECT_NAME}-tests PRIVATE -Wall -pedantic -DDBG_MACRO_NO_WARNING)
target_link_libraries(${PROJECT_NAME}-tests ${PROJECT_NAME})

add_executable(${PROJECT_NAME}-tests-macro_disabled tests/tests.cpp)
target_compile_options(${PROJECT_NAME}-tests-macro_disabled PRIVATE -Wall -pedantic -DDBG_MACRO_NO_WARNING -DDBG_MACRO_DISABLE)
target_link_libraries(${PROJECT_NAME}-tests-macro_disabled ${PROJECT_NAME})

enable_testing()
add_test(${PROJECT_NAME} ${PROJECT_NAME}-tests)
add_test(${PROJECT_NAME}-macro_disabled ${PROJECT_NAME}-tests-macro_disabled)
endif()
8 changes: 7 additions & 1 deletion dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ class DebugOutput {
static constexpr const char* const ANSI_RESET = "\x1b[0m";
};

// Identity function to suppress "-Wunused-value" warnings in DBG_MACRO_DISABLE mode
template <typename T>
T&& identity(T&& t){
return std::forward<T>(t);
}

} // namespace dbg_macro

#ifndef DBG_MACRO_DISABLE
Expand All @@ -420,7 +426,7 @@ class DebugOutput {
dbg_macro::DebugOutput(__FILE__, __LINE__, __func__, #__VA_ARGS__) \
.print(dbg_macro::type_name<decltype(__VA_ARGS__)>(), (__VA_ARGS__))
#else
#define dbg(...) __VA_ARGS__
#define dbg(...) dbg_macro::identity(__VA_ARGS__)
#endif // DBG_MACRO_DISABLE

#endif // DBG_MACRO_DBG_H

0 comments on commit 9c80847

Please sign in to comment.