refactor: Enable -Wswitch in exhaustive switch

Also, apply the comment according to the dev notes.

Also, modify the dev notes to give a lambda-wrapped example.

Can be reviewed via --ignore-all-space

Co-authored-by: Lőrinc <pap.lorinc@gmail.com>
This commit is contained in:
MarcoFalke
2026-02-26 21:13:21 +01:00
parent 5608b8ce9e
commit fa2670bd4b
19 changed files with 112 additions and 125 deletions

View File

@@ -583,29 +583,29 @@ RPCHelpMan::RPCHelpMan(std::string name, std::string description, std::vector<RP
// Default value type should match argument type only when defined
if (arg.m_fallback.index() == 2) {
const RPCArg::Type type = arg.m_type;
switch (std::get<RPCArg::Default>(arg.m_fallback).getType()) {
case UniValue::VOBJ:
CHECK_NONFATAL(type == RPCArg::Type::OBJ);
break;
case UniValue::VARR:
CHECK_NONFATAL(type == RPCArg::Type::ARR);
break;
case UniValue::VSTR:
CHECK_NONFATAL(type == RPCArg::Type::STR || type == RPCArg::Type::STR_HEX || type == RPCArg::Type::AMOUNT);
break;
case UniValue::VNUM:
CHECK_NONFATAL(type == RPCArg::Type::NUM || type == RPCArg::Type::AMOUNT || type == RPCArg::Type::RANGE);
break;
case UniValue::VBOOL:
CHECK_NONFATAL(type == RPCArg::Type::BOOL);
break;
case UniValue::VNULL:
// Null values are accepted in all arguments
break;
default:
[&]() {
switch (std::get<RPCArg::Default>(arg.m_fallback).getType()) {
case UniValue::VOBJ:
CHECK_NONFATAL(type == RPCArg::Type::OBJ);
return;
case UniValue::VARR:
CHECK_NONFATAL(type == RPCArg::Type::ARR);
return;
case UniValue::VSTR:
CHECK_NONFATAL(type == RPCArg::Type::STR || type == RPCArg::Type::STR_HEX || type == RPCArg::Type::AMOUNT);
return;
case UniValue::VNUM:
CHECK_NONFATAL(type == RPCArg::Type::NUM || type == RPCArg::Type::AMOUNT || type == RPCArg::Type::RANGE);
return;
case UniValue::VBOOL:
CHECK_NONFATAL(type == RPCArg::Type::BOOL);
return;
case UniValue::VNULL:
// Null values are accepted in all arguments
return;
} // no default case, so the compiler can warn about missing cases
NONFATAL_UNREACHABLE();
break;
}
}();
}
}
}