This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/71402] -Wunused-variable warnings ignore initialization side effects


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;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]