Bug 107162 - -Wmisleading-indentation is blinded by comments
Summary: -Wmisleading-indentation is blinded by comments
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 12.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2022-10-05 18:37 UTC by Kees Cook
Modified: 2024-01-09 23:47 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kees Cook 2022-10-05 18:37:37 UTC
Hi,

Similar to this bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106528

-Wmissing-indentation is blinded by comments:

int square(int num) {
    if (num == 1)
        goto fail;

//    if (num == 0)
        goto fail;

    if (num > 20)
        return num * num;
    else
        return num + num;

fail:
    return -1;
}

The above case does not warn in GCC, but does in Clang:
https://godbolt.org/z/bMG5jM9Ga
Comment 1 Richard Biener 2022-10-06 10:47:23 UTC
I suppose the better diagnostic would point out that

    if (num > 20)
        return num * num;
    else
        return num + num;

is unreachable?