[llvm-dev] -Wswitch-bool?

Max Ruttenberg via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 29 09:44:27 PDT 2016


All,

If I have source file like this:

/**********************************/
#include <stdbool.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
  switch(argc == 2)
  {
  case true:
    puts("argc == 2");
    break;
  case false:
    puts("argc != 2");
    break;
  }
  return 0;
}
/**********************************/

When I compile this source file with -Wall -Werror flags I get an error:
"main.c:5:3: error: switch condition has boolean value [-Werror]"

And that's fine. I guess it even makes sense. After all, why on earth
wouldn't I just use an if-else statement? I appreciate all responses to
this email, but if you do respond PLEASE pretend I don't have much of a
choice. My question is, how do turn this specific warning off? I've looked
online and saw some post mentioning that this warning is named
"switch-bool" but clang doesn't seem to know that. It suggests
"switch-enum" but that doesn't help...


- Max
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160329/9b434dde/attachment.html>


More information about the llvm-dev mailing list