Bug 87371 - Spurious -Wreturn-type warning with "pathological" for
Summary: Spurious -Wreturn-type warning with "pathological" for
Status: RESOLVED DUPLICATE of bug 67629
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 8.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-20 18:10 UTC by Matthew Woehlke
Modified: 2018-09-20 21:24 UTC (History)
1 user (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 Matthew Woehlke 2018-09-20 18:10:29 UTC
Consider the following code:

    int foo()
    {
        for (int y = 0; !y;)
            for (/*decl*/; !y; ++y)
                return 1;
    }

This generates a -Wreturn-type warning, despite that the inner loop body will *always* execute. Moreover, with optimization enabled, the compiler does (as expected) successfully remove the loops entirely.

(This is a simplified version of a pre-C++17 `with` statement. The purpose of this code, which is usually a macro, is to look like the opening statement of a block, where `/*decl*/` — omitted in this example — is in scope only until the end of the block. FWIW, the C++17 form, `if (/*decl*/; true)` does not exhibit the problem.)


Live example: https://godbolt.org/g/5xM6C3. Possibly related to #67629 and/or #85914.
Comment 1 Manuel López-Ibáñez 2018-09-20 21:24:45 UTC
The warning happens in the front-end, so there is no concept of always-executed. You don't need a loop. This also warns.

int foo()
{
    int y=0;
    if (!y)
        return 1;
}

*** This bug has been marked as a duplicate of bug 67629 ***