From: Erich Keane <erich.keane@intel.com> Date: Wed, 7 Feb 2018 00:37:19 +0000 (+0000) Subject: [NFC] Change odd cast-through-unknown behavior to an Optional X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c1b9c07504bdb033fb7b44a03d5b6f4b01deb642;p=clang [NFC] Change odd cast-through-unknown behavior to an Optional This bit of code in the driver uses '~0U' as a sentinel value. The result is an odd mishmash of casts just to work. This replaces it with an optional, which is a little less crazy looking. --ehis line, and those below, will be ignored-- M lib/Driver/Driver.cpp git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324433 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 9ae5a60fa6..bbfdaefaf3 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -148,15 +148,15 @@ void Driver::setDriverModeFromOption(StringRef Opt) { return; StringRef Value = Opt.drop_front(OptName.size()); - const unsigned M = llvm::StringSwitch<unsigned>(Value) - .Case("gcc", GCCMode) - .Case("g++", GXXMode) - .Case("cpp", CPPMode) - .Case("cl", CLMode) - .Default(~0U); - - if (M != ~0U) - Mode = static_cast<DriverMode>(M); + auto M = llvm::StringSwitch<llvm::Optional<DriverMode>>(Value) + .Case("gcc", GCCMode) + .Case("g++", GXXMode) + .Case("cpp", CPPMode) + .Case("cl", CLMode) + .Default(None); + + if (M) + Mode = M.getValue(); else Diag(diag::err_drv_unsupported_option_argument) << OptName << Value; }