oversearch commented on a change in pull request #11668:
URL: https://github.com/apache/pulsar/pull/11668#discussion_r689693314
##########
File path: pulsar-client-cpp/lib/Commands.cc
##########
@@ -644,6 +644,7 @@ std::string Commands::messageType(BaseCommand_Type type) {
return "END_TXN_ON_SUBSCRIPTION_RESPONSE";
break;
};
+ BOOST_THROW_EXCEPTION(std::logic_error("Invalid BaseCommand enumeration
value"));
Review comment:
Yep, you're quite correct, and I believe that this change keeps that
invariant intact. Note that what I *didn't* do was to add a `default:` case,
which would indeed be undesirable since it would cover all future cases
automatically.
This "throw" line should essentially *never* be hit in any normal
circumstance. If any items are added or removed from the enum or any cases
removed from this switch, the compiler will emit an error and maintainers must
deal with it. The only possible way to get here is to `reinterpret_cast` some
arbitrary value to this enum type, which would cause the switch to drop out and
hit this throw statement. Before, this would have been scary undefined
behavior, but now we'll get an exception. Turning on `-Wall` makes this
situation a warning that we have to deal with, which is a good thing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]