r324433 - [NFC] Change odd cast-through-unknown behavior to an Optional
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 6 16:37:19 PST 2018
Author: erichkeane
Date: Tue Feb 6 16:37:19 2018
New Revision: 324433
URL: http://llvm.org/viewvc/llvm-project?rev=324433&view=rev
Log:
[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
Modified:
cfe/trunk/lib/Driver/Driver.cpp
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=324433&r1=324432&r2=324433&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Feb 6 16:37:19 2018
@@ -148,15 +148,15 @@ void Driver::setDriverModeFromOption(Str
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);
+ auto M = llvm::StringSwitch<llvm::Optional<DriverMode>>(Value)
+ .Case("gcc", GCCMode)
+ .Case("g++", GXXMode)
+ .Case("cpp", CPPMode)
+ .Case("cl", CLMode)
+ .Default(None);
- if (M != ~0U)
- Mode = static_cast<DriverMode>(M);
+ if (M)
+ Mode = M.getValue();
else
Diag(diag::err_drv_unsupported_option_argument) << OptName << Value;
}
More information about the cfe-commits
mailing list