[PATCH] PR28901 -Wunused-variable ignores unused const initialised variables

Steve Ellcey sellcey@imgtec.com
Tue Sep 15 17:04:00 GMT 2015


On Mon, 2015-09-14 at 09:50 +0200, Bernd Schmidt wrote:
> On 09/13/2015 08:24 PM, Mark Wielaard wrote:
> > commit 97505bd0e4ac15d86c2a302cfebc5f1a4fc2c2e8
> > Author: Mark Wielaard<mjw@redhat.com>
> > Date:   Fri Sep 11 23:54:15 2015 +0200
> >
> >      PR28901 -Wunused-variable ignores unused const initialised variables in C
> 
> This is ok.
> 
> 
> Bernd

I am not sure I like this change.  It broke the GLIBC build for me on
MIPS.  Basically GLIBC has a header file with initialized static
constant globals (sysdeps/ieee754/dbl-64/atnat2.h contains tqpi1 and
qpi1) and that header file is included in multiple .c files like
sysdeps/ieee754/dbl-64/e_atan2.c that use some, but not all, of those
static constant variables.  But between the various .c files all of the
globals are used somewhere, just not in every individual .c file.  This
seems like a perfectly reasonable use of static globals and header files
that should not be identified as a warning.

This warning causes the GLIBC build to fail because GLIBC is compiled
with -Wall -Werror.

Steve Ellcey
sellcey@imgtec.com


% cat a.h
static const int a = 3;
static const int b = 5;
static const int c = 4;

% cat a.c
#include "a.h"

int foo() { return a + b;}

% gcc -O2 -Werror -Wall -c a.c
In file included from a.c:1:0:
a.h:3:18: error: 'c' defined but not used
[-Werror=unused-const-variable]
 static const int c = 4;
                  ^
cc1: all warnings being treated as errors



More information about the Gcc-patches mailing list