Compiling the C Torture file "weak-6.c" (below) gives an error at O0 and O1, as 
seemed to be expected 
by the author.  At O2, there's no error or warning.

214> gcc -O2 -c ../c/noerror/GPL/3.3.2/nowarn/bulk/gcc.dg/weak/weak-6.c
<no error>

215> gcc -O1 -c ../c/noerror/GPL/3.3.2/nowarn/bulk/gcc.dg/weak/weak-6.c
../c/noerror/GPL/3.3.2/nowarn/bulk/gcc.dg/weak/weak-6.c:4: error: weak 
declaration of `foo' must 
precede definition


weak-6.c:
/* { dg-do compile } */

extern void * foo (void);
void * foo (void) { return (void *)foo; } /* { dg-error "precede" } */

#pragma weak foo

Also occurs with arm-softfloat-linux-gnu-g++ 3.4.1.
With Apple gcc version 3.3, I don't get the error at any optimization level.

____________________________________

Here's the save-temps output:


225> gcc -v -save-temps -O2 -c 
../c/noerror/GPL/3.3.2/nowarn/bulk/gcc.dg/weak/weak-6.c
Reading specs from /usr/lib/gcc-lib/i586-suse-linux/3.3.4/specs
Configured with: ../configure --enable-threads=posix --prefix=/usr 
--with-local-prefix=/usr/local --
infodir=/usr/share/info --mandir=/usr/share/man 
--enable-languages=c,c++,f77,objc,java,ada --
disable-checking --libdir=/usr/lib --enable-libgcj 
--with-gxx-include-dir=/usr/include/g++ --with-
slibdir=/lib --with-system-zlib --enable-shared --enable-__cxa_atexit 
i586-suse-linux
Thread model: posix
gcc version 3.3.4 (pre 3.3.5 20040809)
 /usr/lib/gcc-lib/i586-suse-linux/3.3.4/cc1 -E -quiet -v -D__GNUC__=3 
-D__GNUC_MINOR__=3 
-D__GNUC_PATCHLEVEL__=4 ../c/noerror/GPL/3.3.2/nowarn/bulk/gcc.dg/weak/weak-6.c 
-O2 weak
-6.i
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc-lib/i586-suse-linux/3.3.4/include
 /usr/i586-suse-linux/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/i586-suse-linux/3.3.4/cc1 -fpreprocessed weak-6.i -quiet 
-dumpbase weak-6.c 
-auxbase weak-6 -O2 -version -o weak-6.s
GNU C version 3.3.4 (pre 3.3.5 20040809) (i586-suse-linux)
        compiled by GNU C version 3.3.4 (pre 3.3.5 20040809).
GGC heuristics: --param ggc-min-expand=81 --param ggc-min-heapsize=96968
 /usr/lib/gcc-lib/i586-suse-linux/3.3.4/../../../../i586-suse-linux/bin/as -V 
-Qy -o weak-6.o weak
-6.s
GNU assembler version 2.15.91.0.2 (i586-suse-linux) using BFD version 
2.15.91.0.2 20040727 (SuSE 
Linux)

-- 
           Summary: "weak declaration must precede definition" error missing
                    at >= O2
           Product: gcc
           Version: 3.3.4
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: flash at pobox dot com
                CC: gcc-bugs at gcc dot gnu dot org


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

Reply via email to