public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52618] New: Explicit template specialization ignores access rights
@ 2012-03-19 15:07 blobbyvolley at mailmetrash dot com
2012-03-19 15:23 ` [Bug c++/52618] " redi at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: blobbyvolley at mailmetrash dot com @ 2012-03-19 15:07 UTC (permalink / raw)
To: gcc-bugs
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: unassigned@gcc.gnu.org
ReportedBy: blobbyvolley@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)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/52618] Explicit template specialization ignores access rights
2012-03-19 15:07 [Bug c++/52618] New: Explicit template specialization ignores access rights blobbyvolley at mailmetrash dot com
@ 2012-03-19 15:23 ` redi at gcc dot gnu.org
2012-03-20 12:10 ` blobbyvolley at mailmetrash dot com
2021-07-27 0:50 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2012-03-19 15:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52618
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |accepts-invalid
Status|UNCONFIRMED |NEW
Last reconfirmed| |2012-03-19
Ever Confirmed|0 |1
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-19 15:06:31 UTC ---
Confirmed, this is one of many access-checking bugs in templates, see PR 47346
Reduced:
class B {
typedef double type; // this is a private member
};
template<class T> struct get_type;
template<> struct get_type<B> {
typedef typename B::type type;
};
typedef typename get_type<B>::type sometype;
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/52618] Explicit template specialization ignores access rights
2012-03-19 15:07 [Bug c++/52618] New: Explicit template specialization ignores access rights blobbyvolley at mailmetrash dot com
2012-03-19 15:23 ` [Bug c++/52618] " redi at gcc dot gnu.org
@ 2012-03-20 12:10 ` blobbyvolley at mailmetrash dot com
2021-07-27 0:50 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: blobbyvolley at mailmetrash dot com @ 2012-03-20 12:10 UTC (permalink / raw)
To: gcc-bugs
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<class T, class U> struct get_type;
template<class U> struct get_type<B, U> { // partial specialization
typedef typename B::type type; // error here
};
typedef typename get_type<B, int>::type sometype;
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/52618] Explicit template specialization ignores access rights
2012-03-19 15:07 [Bug c++/52618] New: Explicit template specialization ignores access rights blobbyvolley at mailmetrash dot com
2012-03-19 15:23 ` [Bug c++/52618] " redi at gcc dot gnu.org
2012-03-20 12:10 ` blobbyvolley at mailmetrash dot com
@ 2021-07-27 0:50 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-27 0:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52618
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEW |RESOLVED
Target Milestone|--- |4.8.0
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed in GCC 4.8+.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-07-27 0:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-19 15:07 [Bug c++/52618] New: Explicit template specialization ignores access rights blobbyvolley at mailmetrash dot com
2012-03-19 15:23 ` [Bug c++/52618] " redi at gcc dot gnu.org
2012-03-20 12:10 ` blobbyvolley at mailmetrash dot com
2021-07-27 0:50 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).