[cfe-dev] -Wswitch warning patch

Michal korgulec at gmail.com
Sat Jan 30 09:23:44 PST 2010

Attaching (I hope) final version.

On Thu, Jan 28, 2010 at 7:01 PM, Douglas Gregor <dgregor at apple.com> wrote:
> On Jan 23, 2010, at 11:59 AM, Michal wrote:
> Thank you both for replies. Attaching a newer, but not yet finished version.
> +      // Iterate over Enum values and check which are missing in switch
> +      CaseValsTy::const_iterator CI = CaseVals.begin();
> +      for(EnumDecl::enumerator_iterator EI = ED->enumerator_begin(); EI !=
> ED->enumerator_end(); EI++) {
> +        if(CI == CaseVals.end() || EI->getInitVal().slt(CI->first))
> Why use "slt" here? The values aren't guaranteed to be signed.
> I misunderstood slt code. I already asked here how to compare ASPInts but
> I am not sure whether it is appropriate to use your answer here. Are you ok
> with
> adding another function that copies and extends an ASPInt, and calling it
> for
> each comparison?
> As for now I am using ordinary <,==, etc, which obviously breaks if enum has
> no
> negative values.
> Every enumeration has an underlying integral type. You can ask that type
> whether it is signed or unsigned, and use ASTContext's getTypeSize() to
> determine its size (in bits). From that information, construct the APSInts
> and compare them with ==.

I've choosen to copy enum constants and promote them to the same type
as condition.
This decision is mainly because it is possible to have to enum
constants of different

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Wswitch.patch
Type: application/octet-stream
Size: 5308 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100130/d3ce79af/attachment.obj>

More information about the cfe-dev mailing list