HomePhabricator

[build] enforce exhaustive switch statements in BUILD_WERROR config

Description

[build] enforce exhaustive switch statements in BUILD_WERROR config

Summary:
D6079 introduced a function that switches over an enum class parameter
and returns a std::string, which raises a warning from the compiler that
"control reaches end of non-void function". since this should never
happen, an assert(false) after the switch silences that warning.

to really bulletproof it though, defaultless switch statements over an enum
value that do not have a specific case for each should raise an error and not a warning

edit: also promoted -Wreturn-type to an error, h/t @deadalnix

ref: https://abseil.io/tips/147

Test Plan:
add another value to PSBTRole enum class in src/psbt.h without changing the
definition of std::string PSBTRoleName(PSBTRole role);

cmake .. -GNinja -WENABLE_WERROR:BOOL=True
ninja

notice that this raises an error:

../src/psbt.cpp:282:13: error: enumeration value 'TESTER' not handled in switch [-Werror,-Wswitch]
switch (role) {

without the WENABLE_WERROR flag set, it'll only emit a warning.

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Subscribers: deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D6107

Details

Provenance
majcostaAuthored on May 17 2020, 01:34
abc-botPushed on May 17 2020, 16:30
Reviewer
Restricted Project
Differential Revision
D6107: [build] enforce exhaustive switch statements in BUILD_WERROR config
Parents
rSTAGING921ff8d34b06: [Automated] Update timing.json
Branches
Unknown
Tags
Unknown
References
tag: phabricator/base/20191