r324433 - [NFC] Change odd cast-through-unknown behavior to an Optional
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 12 08:36:04 PST 2018
FWIW, you can write "*M" rather than M.getValue() if you reckon that's
neater.
And you could roll the declaration/initialization of M into the 'if'
condition - but I can understand why you might prefer not to, given it's a
many-line statement, etc.
On Tue, Feb 6, 2018 at 4:39 PM Erich Keane via cfe-commits <
cfe-commits at lists.llvm.org> wrote:
> 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;
> }
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180212/ad755cb7/attachment.html>
More information about the cfe-commits
mailing list