The following code complies with GCC 4.3.0-2 and presumably older versions
(also tested with 3.4), but fails under GCC 4.4.0:

  template<typename T>
  class C {
    template <typename U> class D {};

    friend class C::D<int>;
  };

The message it outputs is:
  $ /s/gcc-4.4.0/bin/g++ test.cc
  test.cc:5: error: ‘typename C<T>::D’ names ‘template<class T> template<class
U> class C<T>::D’, which is not a type

Here is compiler information (though it also failed under what IIRC is a Mingw
build of 4.5 experimental so I doubt this matters):

  $ /s/gcc-4.4.0/bin/g++ -v
  Reading specs from /../lib/gcc/i686-pc-linux-gnu/4.4.0/specs
  Target: i686-pc-linux-gnu
  Configured with: ../gcc-4.4.0/configure --prefix=/s/gcc-4.4.0/i386_rhel5
--enable-shared --enable-threads --with-pic --enable-languages=c,c++,fortran
--with-gmp=/s/gmp-4.3.0/ --with-mpfr=/s/mpfr-2.4.1/
--with-mpfr-include=/s/mpfr-2.4.1/include --with-mpfr-lib=/s/mpfr-2.4.1/lib
  Thread model: posix
  gcc version 4.4.0 (GCC) 


Things that allow the example to compile:

1. Remove the qualification (change 'C::D<int>' to just 'D<int>')
2. Make D not a template
3. Make C not a template


I can't say definitively that this is a bug and not just a change within an
ambiguity of the C++ standard (or even fixing a bug that used to permit illegal
code), but older versions of GCC, Intel CC 11, and Comeau's "try it out" online
thing all accept that snippet. However, it does have an easy fix, so even
though I encountered this issue in production code, it's not a big deal.


-- 
           Summary: Error when using a qualified name to declare a nested
                    template instantiation as a friend of the containing
                    template
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: evaned at gmail dot com


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

Reply via email to