]> granicus.if.org Git - clang/commitdiff
[NFC] Change odd cast-through-unknown behavior to an Optional
authorErich Keane <erich.keane@intel.com>
Wed, 7 Feb 2018 00:37:19 +0000 (00:37 +0000)
committerErich Keane <erich.keane@intel.com>
Wed, 7 Feb 2018 00:37:19 +0000 (00:37 +0000)
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

lib/Driver/Driver.cpp

index 9ae5a60fa69fab1447cd81b72d0c93475bc81ffc..bbfdaefaf3fe6657e74d8e21d1ecce983172da5e 100644 (file)
@@ -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;
 }