Bug 105195 - spurious warning label defined but not used with if constexpr
Summary: spurious warning label defined but not used with if constexpr
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2022-04-07 13:19 UTC by Barry Revzin
Modified: 2022-11-29 15:17 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-04-07 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Barry Revzin 2022-04-07 13:19:32 UTC
Similar to other "if constexpr" related warnings, gcc warns on this example:

void g();
void h();

template <bool B>
void f() {
    if constexpr (B) {
        goto label;
    }

    g();

label:
    h();
}

int main() {
    f<false>();
}

<source>:12:1: warning: label 'label' defined but not used [-Wunused-label]
   12 | label:
      | ^~~~~

But the label is used, just not in this particular instantiation.
Comment 1 Marek Polacek 2022-04-07 13:29:25 UTC
Confirmed.
Comment 2 Andrew Pinski 2022-11-10 23:50:01 UTC
MSVC warns too:
<source>(12): warning C4102: 'label': unreferenced label
<source>(17): note: see reference to function template instantiation 'void f<false>(void)' being compiled

clang does not though.
I think GCC should not warn either.