LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 5190 - missing warnings on switch(boolean_expr)
Summary: missing warnings on switch(boolean_expr)
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: Frontend (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Zhanyong Wan
URL:
Keywords:
Depends on: 5206
Blocks:
  Show dependency tree
 
Reported: 2009-10-14 15:28 PDT by Zhanyong Wan
Modified: 2010-03-12 00:57 PST (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments
proposed fix (2.33 KB, patch)
2009-10-17 14:03 PDT, Zhanyong Wan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zhanyong Wan 2009-10-14 15:28:44 PDT
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;
}
Comment 1 Zhanyong Wan 2009-10-14 15:32:16 PDT
This was forked from http://llvm.org/PR4407 filed by nlewycky@google.com.
Comment 2 Zhanyong Wan 2009-10-15 18:47:49 PDT
This bug depends on PR5206.
Comment 3 Zhanyong Wan 2009-10-16 14:22:18 PDT
A patch was sent to cfe-commits for review.
Comment 4 Chris Lattner 2009-10-17 01:45:36 PDT
according to Edward, the patch didn't apply cleanly to mainline, please update and resend when you get a chance, thanks!
Comment 5 Zhanyong Wan 2009-10-17 14:01:28 PDT
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.
Comment 6 Zhanyong Wan 2009-10-17 14:03:43 PDT
Created attachment 3668 [details]
proposed fix

Attached the patch file (the same as sent to cfe-commits) to the bug.
Comment 7 Edward O'Callaghan 2009-10-17 14:34:15 PDT
No idea why it was not applying, so I did it by hand.

Committed in revision 84346.

Many thanks,
Edward.