home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / gnu / gcc / bug / 2001 < prev    next >
Encoding:
Text File  |  1992-07-28  |  6.4 KB  |  135 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!computer-science.manchester.ac.UK!bevan
  3. From: bevan@computer-science.manchester.ac.UK (Stephen J Bevan)
  4. Subject: Some comments on new -W options in gcc 2.2
  5. Message-ID: <9207281157.AA08983@panda.cs.man.ac.uk>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Tue, 28 Jul 1992 11:57:06 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 122
  12.  
  13. This is not a bug report per se, rather an observation about some of
  14. the new warning options that have appeared with GCC 2.2.
  15.  
  16. `-Waggregate-return'
  17.      Warn if any functions that return structures or unions are defined
  18.      or called.  (In languages where you can return an array, this also
  19.      elicits a warning.)
  20.  
  21. I initially thought it was an attempt catch the case of returning a
  22. pointer to a stack allocated object which dissapears with the stack
  23. frame on exit.  However, instead it seems to warn about perfectly
  24. valid structure returns (i.e.  the values are copied off the stack
  25. frame).  I'm therefore confused, what error(s) is this trying to
  26. catch?
  27.  
  28.  
  29. `-Wredundant-decls'
  30.      Warn if anything is declared more than once in the same scope,
  31.      even in cases where multiple declaration is valid and changes
  32.      nothing.
  33.  
  34. I think the utility of this could be greatly increased if it only
  35. complained about multiple _declarations_ rather than complaining about
  36. a declaration followed by a definition. i.e. code like the following
  37. seems quite normal practice and it to have the compiler warn about it
  38. seems rather pointless :-
  39.  
  40.    /* foo.h */
  41.    extern int foo(int x);
  42.  
  43.    /* foo.c */
  44.    #include "foo.h"
  45.    int foo(int x) { ... }
  46.  
  47. On the other hand multiple declarations such as having two "extern int
  48. foo(int x);" declarations in the code is worth knowing about.
  49. However, under the current scheme these are lost in the warnings about
  50. the situation described previously.
  51.  
  52. There is also the interesting interation between the above and :-
  53.  
  54. `-Wmissing-prototypes'
  55.      Warn if a global function is defined without a previous prototype
  56.      declaration.  This warning is issued even if the definition itself
  57.      provides a prototype.  The aim is to detect global functions that
  58.      fail to be declared in header files.
  59.  
  60. It seems if both are enabled, no matter what is done warnings will be
  61. generated.  For example, given the following program :-
  62.  
  63. extern int foo(int x);
  64.  
  65. int foo(int x) {return 10;}
  66.  
  67. int main() {
  68.   int v;
  69.   v = foo(1);
  70.   return 0;
  71. }
  72.  
  73. Warnings are produced about duplicate definitions of "foo", and a
  74. missing prototype for "main" :-
  75.  
  76. 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
  77. Reading specs from /usr/local/gcc/gcc-lib/sparc-sun-sunos4/2.2.2/specs
  78. gcc version 2.2.2
  79.  /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 |
  80.  /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 - |
  81.  as - -o foo.o
  82. GNU CPP version 2.2.2 (sparc)
  83. GNU C version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
  84. foo.c:3: warning: redundant redeclaration of `foo' in same scope
  85. foo.c:1: warning: previous declaration of `foo'
  86. foo.c:5: warning: function declaration isn't a prototype
  87.  /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
  88.  
  89. After adding a prototype for "main" :-
  90.  
  91. extern int foo(int x);
  92.  
  93. int foo(int x) {return 10;}
  94.  
  95. int main(void);
  96.  
  97. int main() {
  98.   int v;
  99.   v = foo(1);
  100.   return 0;
  101. }
  102.  
  103. A warning is then issued about duplicate prototypes for "main" :-
  104.  
  105. 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
  106. Reading specs from /usr/local/gcc/gcc-lib/sparc-sun-sunos4/2.2.2/specs
  107. gcc version 2.2.2
  108.  /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 |
  109.  /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 - |
  110.  as - -o foo.o
  111. GNU CPP version 2.2.2 (sparc)
  112. GNU C version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
  113. foo.c:3: warning: redundant redeclaration of `foo' in same scope
  114. foo.c:1: warning: previous declaration of `foo'
  115. foo.c:7: warning: redundant redeclaration of `main' in same scope
  116. foo.c:5: warning: previous declaration of `main'
  117.  /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
  118.  
  119. I realise that these are optional warnings which I can choose not to
  120. enable if I don't want to, however, in their present state, they seem
  121. of little utility.  So, whilst I'm all in favour of extra checks being
  122. done by the compiler, is there any chance of them being a little more
  123. intelligent?
  124.  
  125. Finally, has any thought been given to removing all the different
  126. environment variables and replacing them with a single one, say "GCC".
  127. This would contain all the options (in command line syntax for) that
  128. the user wants enabled as default.  Besides reducing environment
  129. variable name space polution, it would also allow the long list of
  130. warnings I like enabled as default to be defined once and for all
  131. rather than having to repeat them in each Makefile.
  132.  
  133. bevan
  134.  
  135.