public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114763] New: Wduplicated-branches just check last else if-else case?
@ 2024-04-18  7:47 hanwei62 at huawei dot com
  2024-04-18  8:16 ` [Bug c/114763] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: hanwei62 at huawei dot com @ 2024-04-18  7:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114763

            Bug ID: 114763
           Summary: Wduplicated-branches just check last else if-else
                    case?
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hanwei62 at huawei dot com
  Target Milestone: ---

This code:

void foo(int x) {
    if (x) {
        x -= 2;
    } else if (x > 50) {
        x -= 2;
    } else
        x += 2;
}

# gcc -c test.c -Wduplicated-branches

not warning, even if-else if branches is same.

void foo(int x) {
    if (x) {
        x -= 2;
    } else if (x > 50) {
        x -= 2;
    } else if (x < 20) {
        x += 2;
    } else {
        x += 2;
    }
}

warning.

Same like https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85094

What I find that Wduplicated-branches just check the last `else if-else`
branches.

https://godbolt.org/z/WP8v5P4Yf

It's misleading.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-04-18  8:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-18  7:47 [Bug c/114763] New: Wduplicated-branches just check last else if-else case? hanwei62 at huawei dot com
2024-04-18  8:16 ` [Bug c/114763] " pinskia at gcc dot gnu.org
2024-04-18  8:17 ` pinskia at gcc dot gnu.org
2024-04-18  8:31 ` hanwei62 at huawei dot com
2024-04-18  8:32 ` hanwei62 at huawei dot com
2024-04-18  8:45 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).