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++/54583] New: Spurious warning: value computed is not used with variable-size array


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54583

             Bug #: 54583
           Summary: Spurious warning: value computed is not used with
                    variable-size array
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: stuff0002@pobox.com


When declaring a two-dimensional array with variable-length second dimension,
there is a warning "value computed is not used". For example:

$ cat warn1.cpp
void fred(){
  int n=10;
  double (*x)[n];
}
$ g++ -c warn1.cpp -Wall
warn1.cpp: In function âvoid fred()â:
warn1.cpp:3:16: warning: value computed is not used [-Wunused-value]
warn1.cpp:3:12: warning: unused variable âxâ [-Wunused-variable]

The second warning ("unused variable") is to be expected of course, and is not
the subject of this bug report. I don't believe the fact that x isn't used is
relevant to the first warning, so code that uses x is omitted in the above
example in the interests of constructing a minimal example. But to check, here
is a longer example that uses x:

$ cat warn2.cpp
#include <stdio.h>
#include <stdlib.h>

#define M 10
void fred(){
  int a,b,n;
  n=10;
  double (*x)[n];
  x=(double(*)[n])malloc(M*n*sizeof(double));
  for(a=0;a<M;a++)for(b=0;b<n;b++)x[a][b]=3;
  for(a=0;a<M;a++)for(b=0;b<n;b++)printf("%g\n",x[a][b]);
}
$ g++ -c warn2.cpp -Wall
warn2.cpp: In function âvoid fred()â:
warn2.cpp:8:16: warning: value computed is not used [-Wunused-value]


g++ --version
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
...


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