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

             Bug #: 52618
           Summary: Explicit template specialization ignores access rights
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: blobbyvol...@mailmetrash.com


Created attachment 26918
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26918
Example code

Compilation of the following code should fail but it is accepted instead.
Explicit specialization of get_type for class B is able to access a private
member of B even without a friend declaration.

//// example.cpp 

template<class T> struct get_type {
  typedef typename T::type type;
};

struct A {
  typedef int type;
};

class B {
  typedef double type; // this is a private member
  //friend class get_type<B>; // this declaration should be required
};

template<> struct get_type<B> {
  typedef typename B::type type; // should not access B::type without friend
declaration
};

template<class T> void f(T) {
  typedef typename get_type<T>::type sometype;
}

int main(int, char*[]) {
  A a;
  B b;
  f(a);
  f(b);
}

//// end example.cpp

I also tried compiling under LLVM (the simple online demo) and it correctly
gives me an error.

compiled with: g++ -c example.cpp

Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.6.1-9ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin
--enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686
--with-tune=generic --enable-checking=release --build=i686-linux-gnu
--host=i686-linux-gnu --target=i686-linux-gnu
gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)

Reply via email to