public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104142] New: [9/10/11/12] Spurios warning unused-variable
@ 2022-01-20 8:42 phdiv at fastmail dot fm
2022-01-20 8:48 ` [Bug c++/104142] " rguenth at gcc dot gnu.org
` (12 more replies)
0 siblings, 13 replies; 14+ messages in thread
From: phdiv at fastmail dot fm @ 2022-01-20 8:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142
Bug ID: 104142
Summary: [9/10/11/12] Spurios warning unused-variable
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: phdiv at fastmail dot fm
Target Milestone: ---
Created attachment 52238
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52238&action=edit
Reproducer.
> cat c.cpp
struct A { };
static const A a;
struct B { B()=default; };
static const B b;
> g++ -Wunused-variable -Wunused-const-variable -c c.cpp
c.cpp:5:16: warning: 'b' defined but not used [-Wunused-variable]
5 | static const B b;
| ^
c.cpp:2:16: warning: 'a' defined but not used [-Wunused-const-variable=]
2 | static const A a;
| ^
I would expect the warning unused-const-variable to be issued for both a and b.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/104142] Spurios warning unused-variable
2022-01-20 8:42 [Bug c++/104142] New: [9/10/11/12] Spurios warning unused-variable phdiv at fastmail dot fm
@ 2022-01-20 8:48 ` rguenth at gcc dot gnu.org
2022-01-21 8:32 ` [Bug c++/104142] [9/10/11/12 Regression] Spurios warning unused-variable on const static variable and defaulted constructor pinskia at gcc dot gnu.org
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-20 8:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[9/10/11/12] Spurios |Spurios warning
|warning unused-variable |unused-variable
Keywords| |diagnostic
Last reconfirmed| |2022-01-20
Status|UNCONFIRMED |NEW
Known to fail| |10.3.0, 11.2.0, 12.0, 9.4.0
Ever confirmed|0 |1
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
'b' is likely not marked readonly as it is initialized.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/104142] [9/10/11/12 Regression] Spurios warning unused-variable on const static variable and defaulted constructor
2022-01-20 8:42 [Bug c++/104142] New: [9/10/11/12] Spurios warning unused-variable phdiv at fastmail dot fm
2022-01-20 8:48 ` [Bug c++/104142] " rguenth at gcc dot gnu.org
@ 2022-01-21 8:32 ` pinskia at gcc dot gnu.org
2022-01-28 11:32 ` jakub at gcc dot gnu.org
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-21 8:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |9.5
Summary|Spurios warning |[9/10/11/12 Regression]
|unused-variable on const |Spurios warning
|static variable and |unused-variable on const
|defaulted constructor |static variable and
| |defaulted constructor
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There was no -Wunused-variable warning for b before GCC 8.
-Wunused-const-variable didn't warn about b either in GCC 8 (and before).
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/104142] [9/10/11/12 Regression] Spurios warning unused-variable on const static variable and defaulted constructor
2022-01-20 8:42 [Bug c++/104142] New: [9/10/11/12] Spurios warning unused-variable phdiv at fastmail dot fm
2022-01-20 8:48 ` [Bug c++/104142] " rguenth at gcc dot gnu.org
2022-01-21 8:32 ` [Bug c++/104142] [9/10/11/12 Regression] Spurios warning unused-variable on const static variable and defaulted constructor pinskia at gcc dot gnu.org
@ 2022-01-28 11:32 ` jakub at gcc dot gnu.org
2022-01-28 11:43 ` jakub at gcc dot gnu.org
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-01-28 11:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
It isn't clear what exactly is the regression.
We warn on b with -Wunused-variable since
r9-412-gb46b715d5b838d9869f89d3594ebf7d0b7cb374c
A and B aren't the same, one has explicit defaulted ctor, the other has
implicit ctor.
-Wunused-const-variable warns about a and not b since its introduction in
r6-3283-g0f876f22887f239cedca64ff170b71e5f1daaf54
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/104142] [9/10/11/12 Regression] Spurios warning unused-variable on const static variable and defaulted constructor
2022-01-20 8:42 [Bug c++/104142] New: [9/10/11/12] Spurios warning unused-variable phdiv at fastmail dot fm
` (2 preceding siblings ...)
2022-01-28 11:32 ` jakub at gcc dot gnu.org
@ 2022-01-28 11:43 ` jakub at gcc dot gnu.org
2022-04-11 18:52 ` jason at gcc dot gnu.org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-01-28 11:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org,
| |ppalka at gcc dot gnu.org
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
If we want the same warning, we'd need to probably special case const vars with
defaulted default ctors and empty classes, if it isn't empty class, both of
these are rejected already:
pr104142.C:2:16: error: uninitialized ‘const a’ [-fpermissive]
2 | static const A a;
| ^
pr104142.C:1:8: note: ‘const struct A’ has no user-provided default constructor
1 | struct A { int a; };
| ^
pr104142.C:1:16: note: and the implicitly-defined constructor does not
initialize ‘int A::a’
1 | struct A { int a; };
| ^
pr104142.C:5:16: error: uninitialized ‘const b’ [-fpermissive]
5 | static const B b;
| ^
pr104142.C:4:8: note: ‘const struct B’ has no user-provided default constructor
4 | struct B { B()=default; int b; };
| ^
pr104142.C:4:12: note: constructor is not user-provided because it is
explicitly defaulted in the class body
4 | struct B { B()=default; int b; };
| ^
pr104142.C:4:29: note: and the implicitly-defined constructor does not
initialize ‘int B::b’
4 | struct B { B()=default; int b; };
| ^
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/104142] [9/10/11/12 Regression] Spurios warning unused-variable on const static variable and defaulted constructor
2022-01-20 8:42 [Bug c++/104142] New: [9/10/11/12] Spurios warning unused-variable phdiv at fastmail dot fm
` (3 preceding siblings ...)
2022-01-28 11:43 ` jakub at gcc dot gnu.org
@ 2022-04-11 18:52 ` jason at gcc dot gnu.org
2022-04-12 3:58 ` cvs-commit at gcc dot gnu.org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu.org @ 2022-04-11 18:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/104142] [9/10/11/12 Regression] Spurios warning unused-variable on const static variable and defaulted constructor
2022-01-20 8:42 [Bug c++/104142] New: [9/10/11/12] Spurios warning unused-variable phdiv at fastmail dot fm
` (4 preceding siblings ...)
2022-04-11 18:52 ` jason at gcc dot gnu.org
@ 2022-04-12 3:58 ` cvs-commit at gcc dot gnu.org
2022-05-04 2:36 ` [Bug c++/104142] [9/10/11 Regression] Spurious " mh+gcc at glandium dot org
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-04-12 3:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
https://gcc.gnu.org/g:0899b22d9329c1e8fc12d6f0deee0f87dcc0163a
commit r12-8099-g0899b22d9329c1e8fc12d6f0deee0f87dcc0163a
Author: Jason Merrill <jason@redhat.com>
Date: Mon Apr 11 14:50:14 2022 -0400
c++: rodata and defaulted ctor [PR104142]
Trivial initialization shouldn't bump a variable out of .rodata; if the
result of build_aggr_init is an empty STATEMENT_LIST, throw it away.
PR c++/104142
gcc/cp/ChangeLog:
* decl.cc (check_initializer): Check TREE_SIDE_EFFECTS.
gcc/testsuite/ChangeLog:
* g++.dg/opt/const7.C: New test.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/104142] [9/10/11 Regression] Spurious warning unused-variable on const static variable and defaulted constructor
2022-01-20 8:42 [Bug c++/104142] New: [9/10/11/12] Spurios warning unused-variable phdiv at fastmail dot fm
` (5 preceding siblings ...)
2022-04-12 3:58 ` cvs-commit at gcc dot gnu.org
@ 2022-05-04 2:36 ` mh+gcc at glandium dot org
2022-05-04 3:26 ` mh+gcc at glandium dot org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: mh+gcc at glandium dot org @ 2022-05-04 2:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142
Mike Hommey <mh+gcc at glandium dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mh+gcc at glandium dot org
--- Comment #6 from Mike Hommey <mh+gcc at glandium dot org> ---
There's a different warning that interestingly only happens on 11.2 and 11.3
(not 11.1 or earlier versions), that is fixed by the patch in this bug:
```
struct Foo {
explicit constexpr Foo(char) {}
};
const Foo foo[] = {};
```
```
<source>: In function 'void __static_initialization_and_destruction_0(int,
int)':
<source>:5:11: error: statement has no effect [-Werror=unused-value]
5 | const Foo foo[] = {};
| ^~~
```
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/104142] [9/10/11 Regression] Spurious warning unused-variable on const static variable and defaulted constructor
2022-01-20 8:42 [Bug c++/104142] New: [9/10/11/12] Spurios warning unused-variable phdiv at fastmail dot fm
` (6 preceding siblings ...)
2022-05-04 2:36 ` [Bug c++/104142] [9/10/11 Regression] Spurious " mh+gcc at glandium dot org
@ 2022-05-04 3:26 ` mh+gcc at glandium dot org
2022-05-12 20:13 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: mh+gcc at glandium dot org @ 2022-05-04 3:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142
--- Comment #7 from Mike Hommey <mh+gcc at glandium dot org> ---
(In reply to Mike Hommey from comment #6)
> There's a different warning that interestingly only happens on 11.2 and 11.3
> (not 11.1 or earlier versions), that is fixed by the patch in this bug:
Forgot to mention: that warning was a regression from bug 101029
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/104142] [9/10/11 Regression] Spurious warning unused-variable on const static variable and defaulted constructor
2022-01-20 8:42 [Bug c++/104142] New: [9/10/11/12] Spurios warning unused-variable phdiv at fastmail dot fm
` (7 preceding siblings ...)
2022-05-04 3:26 ` mh+gcc at glandium dot org
@ 2022-05-12 20:13 ` cvs-commit at gcc dot gnu.org
2022-05-12 21:25 ` [Bug c++/104142] [9/10 " cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-12 20:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:5296b77556da4682d5a1e2318c0643affaa00563
commit r11-9981-g5296b77556da4682d5a1e2318c0643affaa00563
Author: Jason Merrill <jason@redhat.com>
Date: Mon Apr 11 14:50:14 2022 -0400
c++: rodata and defaulted ctor [PR104142]
Trivial initialization shouldn't bump a variable out of .rodata; if the
result of build_aggr_init is an empty STATEMENT_LIST, throw it away.
PR c++/104142
gcc/cp/ChangeLog:
* decl.c (check_initializer): Check TREE_SIDE_EFFECTS.
gcc/testsuite/ChangeLog:
* g++.dg/opt/const7.C: New test.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/104142] [9/10 Regression] Spurious warning unused-variable on const static variable and defaulted constructor
2022-01-20 8:42 [Bug c++/104142] New: [9/10/11/12] Spurios warning unused-variable phdiv at fastmail dot fm
` (8 preceding siblings ...)
2022-05-12 20:13 ` cvs-commit at gcc dot gnu.org
@ 2022-05-12 21:25 ` cvs-commit at gcc dot gnu.org
2022-05-27 9:47 ` [Bug c++/104142] [10 " rguenth at gcc dot gnu.org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-12 21:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142
--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:cfa3a04be981f63af41f9a960df06e84c2634c5f
commit r10-10729-gcfa3a04be981f63af41f9a960df06e84c2634c5f
Author: Jason Merrill <jason@redhat.com>
Date: Mon Apr 11 14:50:14 2022 -0400
c++: rodata and defaulted ctor [PR104142]
Trivial initialization shouldn't bump a variable out of .rodata; if the
result of build_aggr_init is an empty STATEMENT_LIST, throw it away.
PR c++/104142
gcc/cp/ChangeLog:
* decl.c (check_initializer): Check TREE_SIDE_EFFECTS.
gcc/testsuite/ChangeLog:
* g++.dg/opt/const7.C: New test.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/104142] [10 Regression] Spurious warning unused-variable on const static variable and defaulted constructor
2022-01-20 8:42 [Bug c++/104142] New: [9/10/11/12] Spurios warning unused-variable phdiv at fastmail dot fm
` (9 preceding siblings ...)
2022-05-12 21:25 ` [Bug c++/104142] [9/10 " cvs-commit at gcc dot gnu.org
@ 2022-05-27 9:47 ` rguenth at gcc dot gnu.org
2022-06-28 10:47 ` jakub at gcc dot gnu.org
2023-07-07 9:55 ` rguenth at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-27 9:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|9.5 |10.4
--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9 branch is being closed
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/104142] [10 Regression] Spurious warning unused-variable on const static variable and defaulted constructor
2022-01-20 8:42 [Bug c++/104142] New: [9/10/11/12] Spurios warning unused-variable phdiv at fastmail dot fm
` (10 preceding siblings ...)
2022-05-27 9:47 ` [Bug c++/104142] [10 " rguenth at gcc dot gnu.org
@ 2022-06-28 10:47 ` jakub at gcc dot gnu.org
2023-07-07 9:55 ` rguenth at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|10.4 |10.5
--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/104142] [10 Regression] Spurious warning unused-variable on const static variable and defaulted constructor
2022-01-20 8:42 [Bug c++/104142] New: [9/10/11/12] Spurios warning unused-variable phdiv at fastmail dot fm
` (11 preceding siblings ...)
2022-06-28 10:47 ` jakub at gcc dot gnu.org
@ 2023-07-07 9:55 ` rguenth at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 9:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Target Milestone|10.5 |10.4
Known to work| |10.4.0
Status|ASSIGNED |RESOLVED
--- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed in 10.4 already.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2023-07-07 9:55 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-20 8:42 [Bug c++/104142] New: [9/10/11/12] Spurios warning unused-variable phdiv at fastmail dot fm
2022-01-20 8:48 ` [Bug c++/104142] " rguenth at gcc dot gnu.org
2022-01-21 8:32 ` [Bug c++/104142] [9/10/11/12 Regression] Spurios warning unused-variable on const static variable and defaulted constructor pinskia at gcc dot gnu.org
2022-01-28 11:32 ` jakub at gcc dot gnu.org
2022-01-28 11:43 ` jakub at gcc dot gnu.org
2022-04-11 18:52 ` jason at gcc dot gnu.org
2022-04-12 3:58 ` cvs-commit at gcc dot gnu.org
2022-05-04 2:36 ` [Bug c++/104142] [9/10/11 Regression] Spurious " mh+gcc at glandium dot org
2022-05-04 3:26 ` mh+gcc at glandium dot org
2022-05-12 20:13 ` cvs-commit at gcc dot gnu.org
2022-05-12 21:25 ` [Bug c++/104142] [9/10 " cvs-commit at gcc dot gnu.org
2022-05-27 9:47 ` [Bug c++/104142] [10 " rguenth at gcc dot gnu.org
2022-06-28 10:47 ` jakub at gcc dot gnu.org
2023-07-07 9:55 ` rguenth 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).