Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress unused value warnings #46

Merged
merged 2 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ target_include_directories(${PROJECT_NAME} INTERFACE ".")

if (DBG_MACRO_ENABLE_TESTS)
add_executable(${PROJECT_NAME}-example tests/example.cpp)
target_compile_options(${PROJECT_NAME}-example PRIVATE -Wall -Wextra -pedantic -DDBG_MACRO_NO_WARNING)
target_compile_options(${PROJECT_NAME}-example PRIVATE -Wall -pedantic -DDBG_MACRO_NO_WARNING)
target_link_libraries(${PROJECT_NAME}-example ${PROJECT_NAME})

add_executable(${PROJECT_NAME}-tests tests/tests.cpp)
target_compile_options(${PROJECT_NAME}-tests PRIVATE -Wall -Wextra -pedantic -DDBG_MACRO_NO_WARNING)
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