From 6ad5c1f5588634b650281027add606f53e7c4e91 Mon Sep 17 00:00:00 2001 From: wqking Date: Tue, 28 May 2019 18:54:04 +0800 Subject: [PATCH] Fixed warnings under /W4 in MSVC and -Wall -Wextra in GCC. Raised warning level in unittests to highest. --- include/eventpp/eventpolicies.h | 2 +- include/eventpp/eventqueue.h | 2 +- include/eventpp/internal/eventpolicies_i.h | 2 +- include/eventpp/utilities/eventutil.h | 12 ++-- tests/CMakeLists.txt | 6 ++ tests/benchmark/b3_b5_eventqueue.cpp | 67 +++++++++++---------- tests/unittest/tutorial_eventdispatcher.cpp | 2 +- 7 files changed, 51 insertions(+), 42 deletions(-) diff --git a/include/eventpp/eventpolicies.h b/include/eventpp/eventpolicies.h index 4d61d4a..889088b 100644 --- a/include/eventpp/eventpolicies.h +++ b/include/eventpp/eventpolicies.h @@ -89,7 +89,7 @@ struct SingleThreading value = desired; } - T load(std::memory_order order = std::memory_order_seq_cst) const noexcept + T load(std::memory_order /*order*/ = std::memory_order_seq_cst) const noexcept { return value; } diff --git a/include/eventpp/eventqueue.h b/include/eventpp/eventqueue.h index 9d259a6..e26ded1 100644 --- a/include/eventpp/eventqueue.h +++ b/include/eventpp/eventqueue.h @@ -485,7 +485,7 @@ class EventQueueBase < } template - bool doInvokeFuncWithQueuedEventHelper(F && func, const typename super::Event & e, Args ...args) const + bool doInvokeFuncWithQueuedEventHelper(F && func, const typename super::Event & /*e*/, Args ...args) const { return func(std::forward(args)...); } diff --git a/include/eventpp/internal/eventpolicies_i.h b/include/eventpp/internal/eventpolicies_i.h index e8f0bba..481b8df 100644 --- a/include/eventpp/internal/eventpolicies_i.h +++ b/include/eventpp/internal/eventpolicies_i.h @@ -160,7 +160,7 @@ struct ForEachMixins , Func> using Type = Root; template - static bool forEach(A && ...args) { + static bool forEach(A && .../*args*/) { return true; } }; diff --git a/include/eventpp/utilities/eventutil.h b/include/eventpp/utilities/eventutil.h index 2f0b549..45be4fb 100644 --- a/include/eventpp/utilities/eventutil.h +++ b/include/eventpp/utilities/eventutil.h @@ -85,7 +85,7 @@ bool hasListener( dispatcher.forEachIf( event, [&found, &listener]( - const typename DispatcherType::Handle & handle, + const typename DispatcherType::Handle & /*handle*/, const typename DispatcherType::Callback & item ) -> bool { if(item == listener) { @@ -111,8 +111,8 @@ bool hasAnyListener( dispatcher.forEachIf( event, [&found]( - const typename DispatcherType::Handle & handle, - const typename DispatcherType::Callback & item + const typename DispatcherType::Handle & /*handle*/, + const typename DispatcherType::Callback & /*item*/ ) -> bool { found = true; return false; @@ -131,7 +131,7 @@ bool hasListener( bool found = false; callbackList.forEachIf( [&found, &callback]( - const typename CallbackListType::Handle & handle, + const typename CallbackListType::Handle & /*handle*/, const typename CallbackListType::Callback & item ) -> bool { if(item == callback) { @@ -155,8 +155,8 @@ bool hasAnyListener( bool found = false; callbackList.forEachIf( [&found]( - const typename CallbackListType::Handle & handle, - const typename CallbackListType::Callback & item + const typename CallbackListType::Handle & /*handle*/, + const typename CallbackListType::Callback & /*item*/ ) -> bool { found = true; return false; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7fa547c..43c34c1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,6 +8,12 @@ set(THIRDPARTY_PATH ../../thirdparty) include_directories(../include) +if(MSVC) + add_definitions(/W4) +else() + add_definitions(-Wall -Wextra) +endif() + add_subdirectory(unittest) add_subdirectory(benchmark) diff --git a/tests/benchmark/b3_b5_eventqueue.cpp b/tests/benchmark/b3_b5_eventqueue.cpp index 3c0f856..12e15bf 100644 --- a/tests/benchmark/b3_b5_eventqueue.cpp +++ b/tests/benchmark/b3_b5_eventqueue.cpp @@ -154,47 +154,50 @@ void doMultiThreadingExecuteEventQueue( } //unnamed namespace +// To avoid warning "typedef locally defined but not used" in GCC, +// let's move the policies outside of the test case functions + +struct B3PoliciesMultiThreading { + using Threading = eventpp::MultipleThreading; +}; +struct B3PoliciesSingleThreading { + using Threading = eventpp::SingleThreading; +}; + TEST_CASE("b3, EventQueue, one thread") { - struct PoliciesMultiThreading { - using Threading = eventpp::MultipleThreading; - }; - struct PoliciesSingleThreading { - using Threading = eventpp::SingleThreading; - }; - - doExecuteEventQueue("Multi threading", 100, 1000 * 100, 100); - doExecuteEventQueue("Multi threading", 1000, 1000 * 100, 100); - doExecuteEventQueue("Multi threading", 1000, 1000 * 100, 1000); - - doExecuteEventQueue("Single threading", 100, 1000 * 100, 100); - doExecuteEventQueue("Single threading", 1000, 1000 * 100, 100); - doExecuteEventQueue("Single threading", 1000, 1000 * 100, 1000); + doExecuteEventQueue("Multi threading", 100, 1000 * 100, 100); + doExecuteEventQueue("Multi threading", 1000, 1000 * 100, 100); + doExecuteEventQueue("Multi threading", 1000, 1000 * 100, 1000); + + doExecuteEventQueue("Single threading", 100, 1000 * 100, 100); + doExecuteEventQueue("Single threading", 1000, 1000 * 100, 100); + doExecuteEventQueue("Single threading", 1000, 1000 * 100, 1000); } +struct B4PoliciesMultiThreading { + using Threading = eventpp::GeneralThreading; +}; + TEST_CASE("b4, EventQueue, multi threads, mutex") { - struct PoliciesMultiThreading { - using Threading = eventpp::GeneralThreading; - }; - - doMultiThreadingExecuteEventQueue("Mutex", 1, 1, 1000 * 1000 * 10, 100); - doMultiThreadingExecuteEventQueue("Mutex", 1, 3, 1000 * 1000 * 10, 100); - doMultiThreadingExecuteEventQueue("Mutex", 2, 2, 1000 * 1000 * 10, 100); - doMultiThreadingExecuteEventQueue("Mutex", 4, 4, 1000 * 1000 * 10, 100); - doMultiThreadingExecuteEventQueue("Mutex", 16, 16, 1000 * 1000 * 10, 100); + doMultiThreadingExecuteEventQueue("Mutex", 1, 1, 1000 * 1000 * 10, 100); + doMultiThreadingExecuteEventQueue("Mutex", 1, 3, 1000 * 1000 * 10, 100); + doMultiThreadingExecuteEventQueue("Mutex", 2, 2, 1000 * 1000 * 10, 100); + doMultiThreadingExecuteEventQueue("Mutex", 4, 4, 1000 * 1000 * 10, 100); + doMultiThreadingExecuteEventQueue("Mutex", 16, 16, 1000 * 1000 * 10, 100); } +struct B5PoliciesMultiThreading { + using Threading = eventpp::GeneralThreading; +}; + TEST_CASE("b5, EventQueue, multi threads, spinlock") { - struct PoliciesMultiThreading { - using Threading = eventpp::GeneralThreading; - }; - - doMultiThreadingExecuteEventQueue("Spinlock", 1, 1, 1000 * 1000 * 10, 100); - doMultiThreadingExecuteEventQueue("Spinlock", 1, 3, 1000 * 1000 * 10, 100); - doMultiThreadingExecuteEventQueue("Spinlock", 2, 2, 1000 * 1000 * 10, 100); - doMultiThreadingExecuteEventQueue("Spinlock", 4, 4, 1000 * 1000 * 10, 100); - doMultiThreadingExecuteEventQueue("Spinlock", 16, 16, 1000 * 1000 * 10, 100); + doMultiThreadingExecuteEventQueue("Spinlock", 1, 1, 1000 * 1000 * 10, 100); + doMultiThreadingExecuteEventQueue("Spinlock", 1, 3, 1000 * 1000 * 10, 100); + doMultiThreadingExecuteEventQueue("Spinlock", 2, 2, 1000 * 1000 * 10, 100); + doMultiThreadingExecuteEventQueue("Spinlock", 4, 4, 1000 * 1000 * 10, 100); + doMultiThreadingExecuteEventQueue("Spinlock", 16, 16, 1000 * 1000 * 10, 100); } diff --git a/tests/unittest/tutorial_eventdispatcher.cpp b/tests/unittest/tutorial_eventdispatcher.cpp index c8c47ee..9b08eb8 100644 --- a/tests/unittest/tutorial_eventdispatcher.cpp +++ b/tests/unittest/tutorial_eventdispatcher.cpp @@ -154,7 +154,7 @@ TEST_CASE("EventDispatcher tutorial 4, event canceling") std::cout << "Got event 3" << std::endl; e.canceled = true; }); - dispatcher.appendListener(3, [](const Tutor4MyEvent & e) { + dispatcher.appendListener(3, [](const Tutor4MyEvent & /*e*/) { std::cout << "Should not get this event 3" << std::endl; });