[Bug c++/52618] New: Explicit template specialization ignores access rights

2012-03-19 Thread blobbyvolley at mailmetrash dot com
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 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; // this declaration should be required
};

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

template void f(T) {
  typedef typename get_type::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)


[Bug c++/52618] Explicit template specialization ignores access rights

2012-03-20 Thread blobbyvolley at mailmetrash dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52618

--- Comment #2 from blobbyvolley at mailmetrash dot com 2012-03-20 11:53:29 UTC 
---
If it can be of any help, I noticed that for partial specializations everything
works as intended (the compiler reports an error).

class B {
  typedef double type; // this is a private member
};

template struct get_type;

template struct get_type { // partial specialization
  typedef typename B::type type; // error here
};

typedef typename get_type::type sometype;