tkem / fsmlite

Lightweight finite state machine framework for C++11
MIT License
161 stars 25 forks source link

Warning/Error when compiling with -Wextra (fix included) #22

Closed kuuse closed 4 years ago

kuuse commented 4 years ago

Hi,

Great lib, works out of the box. Almost. Test program with #include "fsm.h"

g++ -g -Wall -Wextra -Werror -std=c++17 prog.cc -o prog

fsm.h:242:47: error: unused parameter ‘event’ [-Werror=unused-parameter]

Fix to silent compiler warning:

--- fsm.h   2020-06-05 11:15:19.387923805 +0200
+++ fsm-patched.h   2020-06-05 11:30:52.649638975 +0200
@@ -240,7 +240,7 @@
          */
         template<class Event>
         state_type no_transition(const Event& event) {
-            return m_state;
+            (void)event; return m_state;
         }

Best Regards, Johan

kuuse commented 4 years ago

An alternative solution:

        template<class Event>
        state_type no_transition(const Event& event __attribute__((unused))) {
            return m_state;
        }

BR, Johan

tkem commented 4 years ago

Good point. Cleanest and portable solution IMHO is not specifying parameter names for unused parameters. See https://github.com/tkem/fsmlite/tree/fix/22 for WIP.

kuuse commented 4 years ago

Agree. Tested your solution and it works. Thanks for a quick fix! Closing this issue now.

tkem commented 4 years ago

Re-opening this until merge into master branch and released.