public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113582] New: incorrect warning about unused label
@ 2024-01-24 13:48 nmmm at nmmm dot nu
2024-01-24 14:31 ` [Bug c++/113582] " nmmm at nmmm dot nu
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: nmmm at nmmm dot nu @ 2024-01-24 13:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113582
Bug ID: 113582
Summary: incorrect warning about unused label
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: nmmm at nmmm dot nu
Target Milestone: ---
This code:
template<bool B>
void do_something(){
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-label"
start:
if constexpr(B)
goto start;
#pragma GCC diagnostic pop
}
int main(){
do_something<0>();
}
Generates a warning:
warning: label ‘start’ defined but not used [-Wunused-label]
pragma GCC diagnostic did not work as well.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/113582] incorrect warning about unused label
2024-01-24 13:48 [Bug c++/113582] New: incorrect warning about unused label nmmm at nmmm dot nu
@ 2024-01-24 14:31 ` nmmm at nmmm dot nu
2024-01-24 21:13 ` mpolacek at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: nmmm at nmmm dot nu @ 2024-01-24 14:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113582
--- Comment #1 from Nikolay Mihaylov <nmmm at nmmm dot nu> ---
If you move the pragma outside the templated function, no warning is shown:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-label"
template<bool B>
void do_something(){
start:
if constexpr(B)
goto start;
}
#pragma GCC diagnostic pop
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/113582] incorrect warning about unused label
2024-01-24 13:48 [Bug c++/113582] New: incorrect warning about unused label nmmm at nmmm dot nu
2024-01-24 14:31 ` [Bug c++/113582] " nmmm at nmmm dot nu
@ 2024-01-24 21:13 ` mpolacek at gcc dot gnu.org
2024-01-24 21:19 ` [Bug c++/113582] incorrect warning about unused label with `pragma GCC diagnostic` around the " pinskia at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-01-24 21:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113582
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-01-24
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
CC| |mpolacek at gcc dot gnu.org
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/113582] incorrect warning about unused label with `pragma GCC diagnostic` around the unused label
2024-01-24 13:48 [Bug c++/113582] New: incorrect warning about unused label nmmm at nmmm dot nu
2024-01-24 14:31 ` [Bug c++/113582] " nmmm at nmmm dot nu
2024-01-24 21:13 ` mpolacek at gcc dot gnu.org
@ 2024-01-24 21:19 ` pinskia at gcc dot gnu.org
2024-01-24 22:59 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-24 21:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113582
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|incorrect warning about |incorrect warning about
|unused label with `pragma |unused label with `pragma
|GCC diagnostic` inside a |GCC diagnostic` around the
|template |unused label
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I originally thought this was due to a template but nope, it is to due with
where the warning happens. Which is at the end of the function.
That is this does not work:
```
void do_something(){
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-label"
start:;
#pragma GCC diagnostic pop
}
```
But this causes the warning not to happen:
```
void do_something(){
start:;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-label"
}
#pragma GCC diagnostic pop
```
Note another way to remove the warning is just to mark the lable as unused with
an attribute like:
```
[[gnu::unused]]start:
```
Which is slightly shorter than using the pragma too.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/113582] incorrect warning about unused label with `pragma GCC diagnostic` around the unused label
2024-01-24 13:48 [Bug c++/113582] New: incorrect warning about unused label nmmm at nmmm dot nu
` (2 preceding siblings ...)
2024-01-24 21:19 ` [Bug c++/113582] incorrect warning about unused label with `pragma GCC diagnostic` around the " pinskia at gcc dot gnu.org
@ 2024-01-24 22:59 ` mpolacek at gcc dot gnu.org
2024-01-24 23:01 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-01-24 22:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113582
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Hack/fix:
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 3748ccd49ff..224d47f2f90 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -13093,7 +13093,11 @@ cp_parser_label_for_labeled_statement (cp_parser*
parser, tree attributes)
/* Anything else must be an ordinary label. */
label = finish_label_stmt (cp_parser_identifier (parser));
if (label && TREE_CODE (label) == LABEL_DECL)
- FALLTHROUGH_LABEL_P (label) = fallthrough_p;
+ {
+ FALLTHROUGH_LABEL_P (label) = fallthrough_p;
+ if (!warning_enabled_at (input_location, OPT_Wunused_label))
+ suppress_warning (label, OPT_Wunused_label);
+ }
break;
}
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 74013533b0f..b6686d8543f 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -18796,11 +18796,13 @@ tsubst_stmt (tree t, tree args, tsubst_flags_t
complain, tree in_decl)
case LABEL_EXPR:
{
tree decl = LABEL_EXPR_LABEL (t);
- tree label;
-
- label = finish_label_stmt (DECL_NAME (decl));
+ tree label = finish_label_stmt (DECL_NAME (decl));
if (TREE_CODE (label) == LABEL_DECL)
- FALLTHROUGH_LABEL_P (label) = FALLTHROUGH_LABEL_P (decl);
+ {
+ FALLTHROUGH_LABEL_P (label) = FALLTHROUGH_LABEL_P (decl);
+ if (warning_suppressed_p (decl, OPT_Wunused_label))
+ TREE_USED (label) = true;
+ }
if (DECL_ATTRIBUTES (decl) != NULL_TREE)
cplus_decl_attributes (&label, DECL_ATTRIBUTES (decl), 0);
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/113582] incorrect warning about unused label with `pragma GCC diagnostic` around the unused label
2024-01-24 13:48 [Bug c++/113582] New: incorrect warning about unused label nmmm at nmmm dot nu
` (3 preceding siblings ...)
2024-01-24 22:59 ` mpolacek at gcc dot gnu.org
@ 2024-01-24 23:01 ` mpolacek at gcc dot gnu.org
2024-01-30 16:12 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-01-24 23:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113582
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The reason I'm not doing simply
TREE_USED (label) = TREE_USED (decl);
in the pt.cc/LABEL_EXPR hunk is that I think we still want the warning in the
second function, what with the goto being a discarded statement.
// PR c++/113582
template<bool B> void
do_something ()
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-label"
start:
if constexpr(B)
goto start;
#pragma GCC diagnostic pop
}
template<bool B> void
do_something2 ()
{
start: // { dg-warning "defined but not used" }
if constexpr(B)
goto start;
}
void
g ()
{
do_something<0>();
do_something2<0>();
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/113582] incorrect warning about unused label with `pragma GCC diagnostic` around the unused label
2024-01-24 13:48 [Bug c++/113582] New: incorrect warning about unused label nmmm at nmmm dot nu
` (4 preceding siblings ...)
2024-01-24 23:01 ` mpolacek at gcc dot gnu.org
@ 2024-01-30 16:12 ` mpolacek at gcc dot gnu.org
2024-05-08 16:22 ` cvs-commit at gcc dot gnu.org
2024-05-08 16:24 ` mpolacek at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-01-30 16:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113582
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Patch approved for GCC 15:
https://gcc.gnu.org/pipermail/gcc-patches/2024-January/643999.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/113582] incorrect warning about unused label with `pragma GCC diagnostic` around the unused label
2024-01-24 13:48 [Bug c++/113582] New: incorrect warning about unused label nmmm at nmmm dot nu
` (5 preceding siblings ...)
2024-01-30 16:12 ` mpolacek at gcc dot gnu.org
@ 2024-05-08 16:22 ` cvs-commit at gcc dot gnu.org
2024-05-08 16:24 ` mpolacek at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-08 16:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113582
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:d9318caed3bbff8136d13e00dcfc020a59d10f78
commit r15-329-gd9318caed3bbff8136d13e00dcfc020a59d10f78
Author: Marek Polacek <polacek@redhat.com>
Date: Wed Jan 24 18:06:48 2024 -0500
c++: #pragma doesn't disable -Wunused-label [PR113582]
The PR complains that
void do_something(){
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-label"
start:;
#pragma GCC diagnostic pop
} #1
doesn't work. That's because we warn_for_unused_label only while we're
in finish_function, meaning we're at #1 where we're outside the #pragma
region. We can use suppress_warning + warning_suppressed_p to fix this.
Note that I'm not using TREE_USED. Propagating it in
tsubst_stmt/LABEL_EXPR
from decl to label would mean that we don't warn in do_something2, but
I think we want the warning there: we're in a template and the goto is
a discarded statement.
PR c++/113582
gcc/c-family/ChangeLog:
* c-warn.cc (warn_for_unused_label): Don't warn if -Wunused-label
has
been suppressed for the label.
gcc/cp/ChangeLog:
* parser.cc (cp_parser_label_for_labeled_statement):
suppress_warning
if it's not enabled at input_location.
* pt.cc (tsubst_stmt): Call copy_warning.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wunused-label-4.C: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/113582] incorrect warning about unused label with `pragma GCC diagnostic` around the unused label
2024-01-24 13:48 [Bug c++/113582] New: incorrect warning about unused label nmmm at nmmm dot nu
` (6 preceding siblings ...)
2024-05-08 16:22 ` cvs-commit at gcc dot gnu.org
@ 2024-05-08 16:24 ` mpolacek at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-05-08 16:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113582
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed in GCC 15.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-05-08 16:24 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-24 13:48 [Bug c++/113582] New: incorrect warning about unused label nmmm at nmmm dot nu
2024-01-24 14:31 ` [Bug c++/113582] " nmmm at nmmm dot nu
2024-01-24 21:13 ` mpolacek at gcc dot gnu.org
2024-01-24 21:19 ` [Bug c++/113582] incorrect warning about unused label with `pragma GCC diagnostic` around the " pinskia at gcc dot gnu.org
2024-01-24 22:59 ` mpolacek at gcc dot gnu.org
2024-01-24 23:01 ` mpolacek at gcc dot gnu.org
2024-01-30 16:12 ` mpolacek at gcc dot gnu.org
2024-05-08 16:22 ` cvs-commit at gcc dot gnu.org
2024-05-08 16:24 ` mpolacek 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).