[Bug c++/104142] [9/10/11 Regression] Spurious warning unused-variable on const static variable and defaulted constructor

2022-05-12 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142

--- Comment #8 from CVS Commits  ---
The releases/gcc-11 branch has been updated by Jason Merrill
:

https://gcc.gnu.org/g:5296b77556da4682d5a1e2318c0643affaa00563

commit r11-9981-g5296b77556da4682d5a1e2318c0643affaa00563
Author: Jason Merrill 
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.

[Bug c++/104142] [9/10/11 Regression] Spurious warning unused-variable on const static variable and defaulted constructor

2022-05-03 Thread mh+gcc at glandium dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142

--- Comment #7 from Mike Hommey  ---
(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

[Bug c++/104142] [9/10/11 Regression] Spurious warning unused-variable on const static variable and defaulted constructor

2022-05-03 Thread mh+gcc at glandium dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104142

Mike Hommey  changed:

   What|Removed |Added

 CC||mh+gcc at glandium dot org

--- Comment #6 from Mike Hommey  ---
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[] = {};
```

```
: In function 'void __static_initialization_and_destruction_0(int,
int)':
:5:11: error: statement has no effect [-Werror=unused-value]
5 | const Foo foo[] = {};
  |   ^~~
```