[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-20 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: @gendalph, this warning is meant to always warn if a {{default}} label is missing, even if all enumeration values are covered. If you don't want a warning on enumerations, use the previously mentioned clang-tidy check

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-20 Thread via cfe-commits
gendalph wrote: Using an enum class without default is a good opportunity to get a warning in all places of use in the switch construct when adding new elements to the enum https://github.com/llvm/llvm-project/pull/73077 ___ cfe-commits mailing list

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-20 Thread via cfe-commits
gendalph wrote: In real projects mix enum class with old int switch. Try to update defaults and have noise from enum class case. My be mix options -Wswitch -Wswitch-default can disable warning in enum class case without default if full covered? https://godbolt.org/z/xrdafn6WK

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-19 Thread dong jianqiang via cfe-commits
@@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-default %s + +int f1(int a) { + switch (a) {// expected-warning {{'switch' missing 'default' label}} +case 1: a++; break; +case 2: a += 2; break; + } + return a; +}

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-18 Thread Shafik Yaghmour via cfe-commits
@@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-default %s + +int f1(int a) { + switch (a) {// expected-warning {{'switch' missing 'default' label}} +case 1: a++; break; +case 2: a += 2; break; + } + return a; +}

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-18 Thread dong jianqiang via cfe-commits
dongjianqiang2 wrote: > ``` > enum class test > { > err1, > err2, > ok > }; > > int check_err (test v) > { > switch (v) > { > case test::err1: > return 1; > case test::err2: > return 2; > case test::ok: > break; > } > return 0; > } >

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-18 Thread via cfe-commits
gendalph wrote: ` enum class test { err1, err2, ok }; int check_err (test v) { switch (v) { case test::err1: return 1; case test::err2: return 2; case test::ok: break; } return 0; } ` https://github.com/llvm/llvm-project/pull/73077

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-06 Thread via cfe-commits
https://github.com/hstk30-hw closed https://github.com/llvm/llvm-project/pull/73077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-06 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman approved this pull request. LGTM! https://github.com/llvm/llvm-project/pull/73077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-05 Thread dong jianqiang via cfe-commits
https://github.com/dongjianqiang2 updated https://github.com/llvm/llvm-project/pull/73077 >From a09d149f050918f6161e5880b4f7e352fc5e52c2 Mon Sep 17 00:00:00 2001 From: dong jianqiang Date: Wed, 22 Nov 2023 11:06:00 +0800 Subject: [PATCH] [clang][Sema] Add -Wswitch-default warning option Adds

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-05 Thread dong jianqiang via cfe-commits
https://github.com/dongjianqiang2 updated https://github.com/llvm/llvm-project/pull/73077 >From af54d1f1870ba43e18cb3677d171e916f8c887b2 Mon Sep 17 00:00:00 2001 From: dong jianqiang Date: Wed, 22 Nov 2023 11:06:00 +0800 Subject: [PATCH] [clang][Sema] Add -Wswitch-default warning option Adds

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-05 Thread dong jianqiang via cfe-commits
@@ -10044,6 +10044,8 @@ def warn_missing_case : Warning<"%plural{" "3:enumeration values %1, %2, and %3 not handled in switch|" ":%0 enumeration values not handled in switch: %1, %2, %3...}0">, InGroup; +def warn_switch_default : Warning<"switch missing default case">,

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-05 Thread dong jianqiang via cfe-commits
https://github.com/dongjianqiang2 updated https://github.com/llvm/llvm-project/pull/73077 >From 94069d442fd703051bef0244e8c663c1390cadbb Mon Sep 17 00:00:00 2001 From: dong jianqiang Date: Wed, 22 Nov 2023 11:06:00 +0800 Subject: [PATCH] [clang][Sema] Add -Wswitch-default warning option Adds

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-05 Thread Aaron Ballman via cfe-commits
AaronBallman wrote: > I think there is value to adding this if only for the GCC compat story here. > I realize we don't like non-on-by-default warnings, but it IS something that > folks use reasonably often, and we've even acquiesced to making it an ignored > flag IIRC. Aaron is the real

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-05 Thread Aaron Ballman via cfe-commits
@@ -10044,6 +10044,8 @@ def warn_missing_case : Warning<"%plural{" "3:enumeration values %1, %2, and %3 not handled in switch|" ":%0 enumeration values not handled in switch: %1, %2, %3...}0">, InGroup; +def warn_switch_default : Warning<"switch missing default case">,

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-04 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: > Aaron is the real decision maker here Specifically @AaronBallman, not me. https://github.com/llvm/llvm-project/pull/73077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-04 Thread Erich Keane via cfe-commits
erichkeane wrote: I think there is value to adding this if only for the GCC compat story here. I realize we don't like non-on-by-default warnings, but it IS something that folks use reasonably often, and we've even acquiesced to making it an ignored flag IIRC. Aaron is the real decision

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-03 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: In the end it probably boils down to how you view an enumeration type. Is it a type with the declared enumerators as inhabitants, or is it an integer type of some length with associated symbolic constants of that type? In other words, is an enumeration a "strong" type or a

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-03 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: > There is one clang-tidy check (bugprone-switch-missing-default-case) also for > this feature. This excludes enumeration types though, while GCC `-Wswitch-default` warns on them as well. (Even if all enumeration values are covered.) > whether switch statements should

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-12-03 Thread via cfe-commits
cor3ntin wrote: @AaronBallman @erichkeane @shafik WDYT? https://github.com/llvm/llvm-project/pull/73077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-11-25 Thread via cfe-commits
hstk30-hw wrote: > For example, Folks at google advise against using `default` when switching > over an enum https://abseil.io/tips/147. > Misra requires a default statement, but makes an exception for enums. (6.4.6 > in misra 2008) I see it's easy to implement in LLVM like clang tidy (not

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-11-24 Thread via cfe-commits
cor3ntin wrote: I'd like other to weight in on that but even though GCC has that flag (which clang recognizes and ignores), I'm, a bit reluctant to add a warning for it. We have a policy to avoid off-by-default warnings most of the time... but more importantly, whether switch statements should

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-11-21 Thread dong jianqiang via cfe-commits
dongjianqiang2 wrote: > There is one clang-tidy check (bugprone-switch-missing-default-case) also for > this feature. Thank you for your reply. It may be a more convenient and straightforward way if can be identified during compile time. On the other hand, it it more compatibile with GCC's

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-11-21 Thread Shivam Gupta via cfe-commits
xgupta wrote: There is one clang-tidy check (bugprone-switch-missing-default-case) also for this feature. https://github.com/llvm/llvm-project/pull/73077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-11-21 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-clang Author: dong jianqiang (dongjianqiang2) Changes Adds a warning, issued by the clang semantic analysis. The patch warns on switch which don't have the default branch. This is a counterpart of gcc's Wswitch-default. --- Full diff:

[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

2023-11-21 Thread dong jianqiang via cfe-commits
https://github.com/dongjianqiang2 created https://github.com/llvm/llvm-project/pull/73077 Adds a warning, issued by the clang semantic analysis. The patch warns on switch which don't have the default branch. This is a counterpart of gcc's Wswitch-default. >From