This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/71402] -Wunused-variable warnings ignore initialization side effects
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 04 Jun 2016 22:34:55 +0000
- Subject: [Bug c++/71402] -Wunused-variable warnings ignore initialization side effects
- Auto-submitted: auto-generated
- References: <bug-71402-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71402
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |msebor at gcc dot gnu.org
Resolution|WORKSFORME |FIXED
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
I just happened to be looking into this report and it's not clear to me whether
or not the warning should be expected in this case. The documentation suggests
it should be:
-Wunused-variable
Warn whenever a local or static variable is unused aside from its
declaration.
and I could find no tests that exercise this case, or the much simpler:
staticc int i;
static int j = i;
which is also not diagnosed by GCC (it is by Clang).
Since the dynamic initialization is retained, it might make sense not to
diagnose it. On the other hand, when the initialization has no observable
side-effects it would be nice to know that it's still done (in case the
variable can be removed, such as in the simple test above).
Either way, the warning doesn't seem to work as I would expect in many cases.
For example, the following produces no warnings with GCC (Clang diagnoses both
s and k, which makes more sense to me):
int f ();
static int i = f ();
static struct S { } s = S ();
static int j;
static int k = j;