<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Aug 5, 2014 at 7:37 PM, Benjamin Bannier <span dir="ltr"><<a href="mailto:bbannier@gmail.com" target="_blank">bbannier@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi Alexander,<br>
<div class=""><br>
> > While clang issues a warns about a possibly incomplete switch statement<br>
> > when switching over an enum variable and failing to cover all enum<br>
> > values (either explicitly or with a default case), no such warning is<br>
> > emitted if a plain integer variable is used as switch variable.<br>
> ><br>
><br>
> If we consider this diagnostic useful, then we should implement<br>
> -Wswitch-default in Clang (GCC has it, Clang doesn't).<br>
<br>
</div>This is intended to catch different problems than -Wswitch-default,</blockquote><div><br></div><div>This check warns on "switching on non-enum value without default case". GCC's -Wswitch-default warns "whenever a switch statement does not have a default case". The difference is "non-enum value", which would make a reasonable improvement over the GCC's behavior, as switching over enums is better handled with -Wswitch. Once there's a compiler diagnostic in GCC with a very close (but strictly wider) scope, it seems reasonable to implement it in Clang also as a compiler diagnostic.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> and<br>
a default case is even discouraged in some style guides since it masks<br>
unhandled values when using -Wswitch (explicitly in GCC or implicitly in<br>
clang).<br>
<br>
The problem this tries to catch is switching on ints w/o an existing<br>
default. If the switch labels are enum values both GCC and clang will<br>
check for full coverage if one uses -Wswitch; however since the switch<br>
condition won't be of that enum type no full coverage can be guaranteed.<br>
The same problem also exists were the switch labels plain ints, but then<br>
even -Wswitch won't help.<br>
<br>
It might be a good idea to add a compiler warning proper for that, but I<br>
have even less experience with that than with writing AST matchers for<br>
clang-tidy.</blockquote><div><br></div><div>This reason alone is not enough to decide in favor of a clang-tidy check in this case. Implementing this specific diagnostic in the compiler shouldn't be much harder. There are good examples which are quite close to what you need - -Wswitch and -Wcovered-switch-default.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
Btw, I am working on comments in <a href="http://reviews.llvm.org/D4784" target="_blank">http://reviews.llvm.org/D4784</a>.<br>
<br>
<br>
Cheers,<br>
<br>
Benjamin<br>
<div class=""><div class="h5"><br>
--<br>
"Good judgment comes from experience. Experience comes from bad judgment."</div></div></blockquote></div>
</div></div>