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>
On 3/29/2016 11:44 AM, Max Ruttenberg via llvm-dev wrote:> > I've looked online and saw some post mentioning that this warning is named > "switch-bool" but clang doesn't seem to know that.You're probably using an old clang. There is an option "-Wno-switch-bool" that turns this warning off, but if your clang does not understand it, there may be no other way of disabling it. Alternatively, you could try -w, but that would turn off all warnings. If you can change the source, you could make it "switch ((int)(argc == 2))". -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Krzysztof, Thanks for the response. You're probably using an old clang. You're right about that. Sadly, I'm stuck with it. If you can change the source, you could make it "switch ((int)(argc == 2))". I think that will have to do. Thank you! -Max On Tue, Mar 29, 2016 at 12:53 PM, Krzysztof Parzyszek via llvm-dev < llvm-dev at lists.llvm.org> wrote:> On 3/29/2016 11:44 AM, Max Ruttenberg via llvm-dev wrote: > >> >> I've looked online and saw some post mentioning that this warning is named >> "switch-bool" but clang doesn't seem to know that. >> > > You're probably using an old clang. There is an option "-Wno-switch-bool" > that turns this warning off, but if your clang does not understand it, > there may be no other way of disabling it. Alternatively, you could try -w, > but that would turn off all warnings. > > If you can change the source, you could make it "switch ((int)(argc => 2))". > > -Krzysztof > > -- > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted > by The Linux Foundation > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160329/7a84dc9b/attachment.html>