Thread View: gnu.gcc.bug
1 messages
1 total messages
Started by Stephen J Bevan
Tue, 28 Jul 1992 11:57
Some comments on new -W options in gcc 2.2
Author: Stephen J Bevan
Date: Tue, 28 Jul 1992 11:57
Date: Tue, 28 Jul 1992 11:57
121 lines
6698 bytes
6698 bytes
This is not a bug report per se, rather an observation about some of
the new warning options that have appeared with GCC 2.2.
`-Waggregate-return'
Warn if any functions that return structures or unions are defined
or called. (In languages where you can return an array, this also
elicits a warning.)
I initially thought it was an attempt catch the case of returning a
pointer to a stack allocated object which dissapears with the stack
frame on exit. However, instead it seems to warn about perfectly
valid structure returns (i.e. the values are copied off the stack
frame). I'm therefore confused, what error(s) is this trying to
catch?
`-Wredundant-decls'
Warn if anything is declared more than once in the same scope,
even in cases where multiple declaration is valid and changes
nothing.
I think the utility of this could be greatly increased if it only
complained about multiple _declarations_ rather than complaining about
a declaration followed by a definition. i.e. code like the following
seems quite normal practice and it to have the compiler warn about it
seems rather pointless :-
/* foo.h */
extern int foo(int x);
/* foo.c */
#include "foo.h"
int foo(int x) { ... }
On the other hand multiple declarations such as having two "extern int
foo(int x);" declarations in the code is worth knowing about.
However, under the current scheme these are lost in the warnings about
the situation described previously.
There is also the interesting interation between the above and :-
`-Wmissing-prototypes'
Warn if a global function is defined without a previous prototype
declaration. This warning is issued even if the definition itself
provides a prototype. The aim is to detect global functions that
fail to be declared in header files.
It seems if both are enabled, no matter what is done warnings will be
generated. For example, given the following program :-
extern int foo(int x);
int foo(int x) {return 10;}
int main() {
int v;
v = foo(1);
return 0;
}
Warnings are produced about duplicate definitions of "foo", and a
missing prototype for "main" :-
panda% gcc-new -v -pipe -Wall -Wcast-align -Wconversion -Waggregate-return -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline -Wstrict-prototypes -Wshadow -Wcast-qual -Wpointer-arith -Wwrite-strings -ansi -pedantic foo.c
Reading specs from /usr/local/gcc/gcc-lib/sparc-sun-sunos4/2.2.2/specs
gcc version 2.2.2
/usr/local/gcc/gcc-lib/sparc-sun-sunos4/2.2.2/cpp -lang-c -v -undef -D__GNUC__=2 -trigraphs -$ -D__STRICT_ANSI__ -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -Wall -Wcast-align -Wconversion -Waggregate-return -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline -Wstrict-prototypes -Wshadow -Wcast-qual -Wpointer-arith -Wwrite-strings -pedantic foo.c |
/usr/local/gcc/gcc-lib/sparc-sun-sunos4/2.2.2/cc1 -quiet -dumpbase foo.c -Wall -Wcast-align -Wconversion -Waggregate-return -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline -Wstrict-prototypes -Wshadow -Wcast-qual -Wpointer-arith -Wwrite-strings -pedantic -ansi -version -o - |
as - -o foo.o
GNU CPP version 2.2.2 (sparc)
GNU C version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
foo.c:3: warning: redundant redeclaration of `foo' in same scope
foo.c:1: warning: previous declaration of `foo'
foo.c:5: warning: function declaration isn't a prototype
/usr/local/gcc/gcc-lib/sparc-sun-sunos4/2.2.2/ld -e start -dc -dp /lib/crt0.o -L/usr/local/gcc/gcc-lib/sparc-sun-sunos4/2.2.2 -L/usr/local/gcc foo.o -lgcc -lc -lgcc
After adding a prototype for "main" :-
extern int foo(int x);
int foo(int x) {return 10;}
int main(void);
int main() {
int v;
v = foo(1);
return 0;
}
A warning is then issued about duplicate prototypes for "main" :-
panda% gcc-new -v -pipe -Wall -Wcast-align -Wconversion -Waggregate-return -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline -Wstrict-prototypes -Wshadow -Wcast-qual -Wpointer-arith -Wwrite-strings -ansi -pedantic foo.c
Reading specs from /usr/local/gcc/gcc-lib/sparc-sun-sunos4/2.2.2/specs
gcc version 2.2.2
/usr/local/gcc/gcc-lib/sparc-sun-sunos4/2.2.2/cpp -lang-c -v -undef -D__GNUC__=2 -trigraphs -$ -D__STRICT_ANSI__ -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -Wall -Wcast-align -Wconversion -Waggregate-return -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline -Wstrict-prototypes -Wshadow -Wcast-qual -Wpointer-arith -Wwrite-strings -pedantic foo.c |
/usr/local/gcc/gcc-lib/sparc-sun-sunos4/2.2.2/cc1 -quiet -dumpbase foo.c -Wall -Wcast-align -Wconversion -Waggregate-return -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline -Wstrict-prototypes -Wshadow -Wcast-qual -Wpointer-arith -Wwrite-strings -pedantic -ansi -version -o - |
as - -o foo.o
GNU CPP version 2.2.2 (sparc)
GNU C version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
foo.c:3: warning: redundant redeclaration of `foo' in same scope
foo.c:1: warning: previous declaration of `foo'
foo.c:7: warning: redundant redeclaration of `main' in same scope
foo.c:5: warning: previous declaration of `main'
/usr/local/gcc/gcc-lib/sparc-sun-sunos4/2.2.2/ld -e start -dc -dp /lib/crt0.o -L/usr/local/gcc/gcc-lib/sparc-sun-sunos4/2.2.2 -L/usr/local/gcc foo.o -lgcc -lc -lgcc
I realise that these are optional warnings which I can choose not to
enable if I don't want to, however, in their present state, they seem
of little utility. So, whilst I'm all in favour of extra checks being
done by the compiler, is there any chance of them being a little more
intelligent?
Finally, has any thought been given to removing all the different
environment variables and replacing them with a single one, say "GCC".
This would contain all the options (in command line syntax for) that
the user wants enabled as default. Besides reducing environment
variable name space polution, it would also allow the long list of
warnings I like enabled as default to be defined once and for all
rather than having to repeat them in each Makefile.
bevan
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads