Hi all. g++ 3.4.4 seems to accept calling a destructor ~T() on a char * pointer if you're inside a template in certain cases. Obviously not very serious in the grand scheme of things! Apologies if this has been fixed - I couldn't find it in the bug list, though.
--- START EXAMPLE --- class Foo {}; struct Bing { char *GetChar() { return new char; } }; template<typename T> struct Bar { void Wibble() { bing.GetChar()->~T(); // How can this be legal if T isn't char? } Bing bing; }; int main() { Bar<Foo> fooBar; fooBar.Wibble(); } --- END EXAMPLE --- You can see that the (char *) return from GetChar() has ~Foo() called on it, but g++ 3.4.4 happily accepts this. It doesn't actually enter the destructor for Foo - I guess it's calling the char destructor. If you split the call to GetChar into "char *p = bing.GetChar(); p->~T();", then the compiler spots that there's something wrong: gccbug.cpp: In member function `void Bar<T>::Wibble() [with T = Foo]': gccbug.cpp:21: instantiated from here gccbug.cpp:12: error: `*p' is not of type `Foo' Haven't tried it on g++ 3.4.5 or 4.0.x - I don't have time before Xmas (sorry). Command line is "g++ -o gccbug gccbug.cpp", g++ -v gives: Reading specs from /space/azuro2/i686-pc-linux-gnu/toolset/lib/gcc/i686-pc-linux-gnu/3.4.4/specs Configured with: ../gcc-3.4.4/configure --with-gnu-as --with-gnu-ld --prefix=/space/azuro2/i686-pc-linux-gn/toolset -v : (reconfigured) ../gcc-3.4.4/configure --with-gnu-as --with-gnu-ld --prefix=/space/azuro2/i686-pc-linux-gnu/toolset -v Thread model: posix gcc version 3.4.4 Hope this helps. Have a good Xmas y'all, regards Steev -- Summary: Wrong-type destructor call accepted in template with no error Product: gcc Version: 3.4.4 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: steev at azuro dot com GCC host triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25546