The invalid code below gives an "undefined reference" linker error on GCC 4.0.1 
at -O0, but not at -
O1; GCC 3.3.4 gives an error at both optimizations.  This may not be a bug, if 
the version 4 optimizer is 
being cleverer than the version 3 optimizer; but the failure to reject the 
invalid code might be 
considered a regression.


//By Stuart A. Malone, tweaked by Flash Sheridan

#include <stdio.h>
#include <stdint.h>

class Foo {
public:
     static const uint16_t kErrorCmd = 42;
};

static uint32_t TestCmd(const uint16_t & cmd)
{
     return (cmd == 42) ? 17 : 0;
}

int main()
{
     printf("%u", TestCmd(Foo::kErrorCmd) );
}

-----------

Here's the correct rejection:

368> /opt/gcc401chk/bin/g++ 
../cpp/noerror/Llamagrahpics_static_constant_by_ref.cpp
/tmp/cc3Hoo7z.o(.text+0x47): In function `main':
: undefined reference to `Foo::kErrorCmd'
collect2: ld returned 1 exit status


Here's the full session for the failure to reject:
369> /opt/gcc401chk/bin/g++ -O1 -v 
../cpp/noerror/Llamagrahpics_static_constant_by_ref.cpp
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure --enable-checking --prefix=/opt/gcc401chk 
--enable-languages=c,c+
+
Thread model: posix
gcc version 4.0.1
 /opt/gcc401chk/libexec/gcc/i686-pc-linux-gnu/4.0.1/cc1plus -quiet -v 
-D_GNU_SOURCE ../cpp/
noerror/Llamagrahpics_static_constant_by_ref.cpp -quiet -dumpbase 
Llamagrahpics_static_constant_by_ref.cpp -mtune=pentiumpro -auxbase 
Llamagrahpics_static_constant_by_ref -O1 -version -o /tmp/ccBQBEWy.s
ignoring nonexistent directory 
"/opt/gcc401chk/lib/gcc/i686-pc-linux-gnu/4.0.1/../../../../i686-pc-
linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/gcc401chk/lib/gcc/i686-pc-linux-gnu/4.0.1/../../../../include/c++/4.0.1
 
/opt/gcc401chk/lib/gcc/i686-pc-linux-gnu/4.0.1/../../../../include/c++/4.0.1/i686-pc-linux-gnu
 
/opt/gcc401chk/lib/gcc/i686-pc-linux-gnu/4.0.1/../../../../include/c++/4.0.1/backward
 /usr/local/include
 /opt/gcc401chk/include
 /opt/gcc401chk/lib/gcc/i686-pc-linux-gnu/4.0.1/include
 /usr/include
End of search list.
GNU C++ version 4.0.1 (i686-pc-linux-gnu)
        compiled by GNU C version 3.3.4 (pre 3.3.5 20040809).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
 as -V -Qy -o /tmp/ccgiUdjh.o /tmp/ccBQBEWy.s
GNU assembler version 2.15.91.0.2 (i586-suse-linux) using BFD version 
2.15.91.0.2 20040727 (SuSE 
Linux)
 /opt/gcc401chk/libexec/gcc/i686-pc-linux-gnu/4.0.1/collect2 --eh-frame-hdr -m 
elf_i386 -
dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o 
/opt/gcc401chk/lib/gcc/i686-pc-
linux-gnu/4.0.1/crtbegin.o -L/opt/gcc401chk/lib/gcc/i686-pc-linux-gnu/4.0.1 
-L/opt/gcc401chk/
lib/gcc/i686-pc-linux-gnu/4.0.1/../../.. /tmp/ccgiUdjh.o -lstdc++ -lm -lgcc_s 
-lgcc -lc -lgcc_s -lgcc 
/opt/gcc401chk/lib/gcc/i686-pc-linux-gnu/4.0.1/crtend.o /usr/lib/crtn.o
 [EMAIL PROTECTED] scripts 21:09:40
370>

-- 
           Summary: No error at -O1 for static const class member passed by
                    reference
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         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
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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

Reply via email to