[PATCH] Fixes and features for Consumed analysis

Reid Kleckner rnk at google.com
Wed Aug 21 09:19:07 PDT 2013


On Wed, Aug 21, 2013 at 6:54 AM, Aaron Ballman <aaron at aaronballman.com>wrote:

> On Tue, Aug 20, 2013 at 7:16 PM, Christian Wailes
> <chriswailes at google.com> wrote:
> >> > +
> >> > +  if (!FunDecl->hasAttr<CallableWhenUnconsumedAttr>()) return;
> >> > +
> >> > +  if (PState.IsVar) {
> >> > +    const VarDecl *Var = PState.getVar();
> >> > +
> >> > +    switch (StateMap->getState(Var)) {
> >> > +    case CS_Consumed:
> >> > +      Analyzer.WarningsHandler.warnUseWhileConsumed(
> >> > +        FunDecl->getNameAsString(), Var->getNameAsString(),
> >> > +        Call->getExprLoc());
> >> > +      break;
> >> > +
> >> > +    case CS_Unknown:
> >> > +      Analyzer.WarningsHandler.warnUseInUnknownState(
> >> > +        FunDecl->getNameAsString(), Var->getNameAsString(),
> >> > +        Call->getExprLoc());
> >> > +      break;
> >> > +
> >> > +    default:
> >> > +      break;
> >>
> >> Should the default be unreachable?
> >>
> >
> > No, there are other cases besides Consumed and Unknown.  I just don't
> want
> > to do anything for those cases.
>
> I worry that this will cause extra warnings in some of the build bots
> because the other enumerants are not covered in the switch statement.
> The same is true elsewhere.


It is a bit of a clang coding convention to use fully-covered switches with
no default.  That way, when someone adds an enum value, the compiler will
warn on all of the switches missing cases.

We shouldn't get warnings for a partially covered switch with a default
(like this one), although we will for fully covered switches with a default.

There are only two enums vs one default, so I'd cover the switch to
leverage the warning.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130821/9c609166/attachment.html>


More information about the cfe-commits mailing list