Clang should warn on switch(bool) since it's almost certainly wrong (developers seem okay with using if-statements instead). int test2(const char *foo) { int success = 0; switch (foo && foo[0]) { /* XXX */ case 0: success = 1; break; case 1: break; } return success; }
This was forked from http://llvm.org/PR4407 filed by nlewycky@google.com.
This bug depends on PR5206.
A patch was sent to cfe-commits for review.
according to Edward, the patch didn't apply cleanly to mainline, please update and resend when you get a chance, thanks!
I did an 'svn up' and didn't see any conflict, so I'm not where why the patch wouldn't work for the trunk. I just tried this in a clean svn checkout: patch -p 0 -i pr5190.patch and it worked fine. Could you try again? Thanks. BTW, this patch adds a new file test/SemaCXX/switch.cpp. Don't know if this has anything to do with what Edward saw.
Created attachment 3668 [details] proposed fix Attached the patch file (the same as sent to cfe-commits) to the bug.
No idea why it was not applying, so I did it by hand. Committed in revision 84346. Many thanks, Edward.