The code below compiles fine with gcc 3.3.1 and 3.4.0 (and does the right thing); it produces a compile time error in 4.0.2. Lookup of the << operator in the definition of serializable::impl<X>::value fails when it is instatiated via the bar or baz templates but succeeds when instantiated via the foo template. (Use of the bar or baz templates will succeed if instantation has alread occured.)
Curiously, the bug seems very specific -- a number of very similar pieces of code in 4.0.2's <tr1/type_traits> header compile correctly. // -------------------- extern "C" int printf( char const*, ... ); namespace std2 { class ostream { void* ptr; }; class string; ostream& operator<<( ostream&, string const& ); } namespace serializable { struct two { std2::ostream a, b; }; template <class U, class V> two operator<<(U&, V const&); template <class T> struct impl { static T const& make(); static std2::ostream& stream(); static const bool value = sizeof( stream() << make() ) == sizeof(std2::ostream); }; } template <bool V> struct foo { foo() { printf("%d\n", V); } }; template <typename T> struct baz : foo< T::value > {}; template <typename T> struct bar : baz< serializable::impl<T> > {}; struct X {}; int main() { bar< X >(); // -- Fails baz< serializable::impl<X> >(); // -- Fails foo< serializable::impl<X>::value >(); // -- Succeeds baz< serializable::impl<X> >(); // -- Succeeds bar< X >(); // -- Succeeds } // Expected output: 0 0 0 0 0 -- Summary: Bug in name lookup in template -- 4.0 regression against 3.4 Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: richard at ex-parrot dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25153