docopt / docopt.cpp

C++11 port of docopt
Boost Software License 1.0
1.04k stars 146 forks source link

Move return so that switch has default case #157

Open eaaltonen opened 2 years ago

eaaltonen commented 2 years ago

Commit

When a project using docopt.cpp is built with -Werror=switch-default option, there's an error

error: switch missing default case [-Werror=switch-default]

which this fixes.

Signed-off-by: Eero Aaltonen eero.aaltonen@vaisala.com

jaredgrubb commented 2 years ago

This style is intentional.

There is another warning (-Wswitch) that warns if you forget to handle any enum case, but it gets disabled if you add a default (because that's signaling that you intend to cover "everything else not yet mentioned"). However, that's not the case here, as we want to be sure that we always explicitly handle every possible case.

I personally prefer Wswitch-enum which warns even if you have a default, but that warning tends to get very noisy on legacy code-bases so is less used (I don't know this for sure, but just anecdotally).

I personally prefer the style as it is (as it's compatible with both Wswitch and Wswitch-enum). I'll leave this open to hear other opinions though!

eaaltonen commented 5 months ago

I changed the commit so that the warning/error is silenced using a gcc pragma instead. Would you find that acceptable?

eaaltonen commented 5 months ago

@jaredgrubb Care to take a look? By suppressing the warning the library could be used also by code that compiles with switch-default.