The following mistyped illegal code compiles. The resulted executable crashes because of the accepted illegal pointers.
// --------------------------------------------------------------------------- struct Base {}; struct Derived : protected Base { operator const Base* () const { return *this; // --- Illegal type, should be written without * } }; int main() { Derived der; const Base *bp = static_cast<const Base*>(der); (void) bp; // --- Avoid warning return 0; } // ------------------------------------------------------------------------ Compiled with the command: g++ -Wall -ansi -pedantic source.cpp Detailed configuration info is: Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --host=i386-redhat-linux Thread model: posix gcc version 3.4.1 20040714 (Red Hat 3.4.1-7) GNU C++ version 3.4.1 20040714 (Red Hat 3.4.1-7) (i386-redhat-linux) compiled by GNU C version 3.4.1 20040714 (Red Hat 3.4.1-7). GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64160 as -V -Qy -o /tmp/cco9w5Jv.o /tmp/ccCvMY8N.s -- Summary: illegal code compiles and segfaults in runtime Product: gcc Version: 3.4.1 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: istvan dot zolyomi at gmail dot com CC: gcc-bugs at gcc dot gnu dot org,scamel at elte dot hu GCC build triplet: gcc version 3.4.1 20040714 (Red Hat 3.4.1-7) GCC host triplet: Linux GCC target triplet: i386 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18855