This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/15254] New: friend function does not have access to private method in templeted classes


When declaring a friend function to a templetized class, function does not have 
access to private methods: 
 
test.h 
================== 
template<class T> class foo; 
 
template<typename T1, typename T2> foo<T2>* convert(const foo<T1>& arg); 
 
 
template<class T> class foo 
{ 
    template<typename T1, typename T2> friend foo<T2>* convert(const foo<T1>& 
arg); 
 
public: 
    foo(int i); 
    ~foo(); 
 
private: 
    // don't copy or assign it 
    foo(const foo<T>& rhs); 
    foo<T>& operator=(const foo<T>& rhs); 
 
    // empty default constructor for the convert friend. 
    foo(); 
}; 
 
 
template<class T> 
foo<T>::foo(int i) 
{ 
    // do nothing 
} 
 
 
template<class T> 
foo<T>::~foo() 
{ 
    // do nothing 
} 
 
 
template<typename T1, typename T2> foo<T2>* convert(const foo<T1>& arg) 
{ 
    // do nothing 
    return 0; 
} 
 
 
 
 
 
 
 
test.cpp 
======================== 
#include "test.h" 
 
 
int main(int argc, char** argv) 
{ 
    foo<int>* foo_int; 
 
    foo_int = convert<char, int>( foo<char>( 10 ) ); 
} 
 
 
 
 
output: 
============== 
g++ -v -o test test.cpp 
Reading specs from /usr/lib/gcc/i686-pc-linux-gnu/3.4.0/specs 
Configured with: /var/tmp/portage/gcc-3.4.0/work/gcc-3.4.0/configure 
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.4 
--includedir=/usr/lib/gcc/i686-pc-linux-gnu/3.4.0/include 
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.4 
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/3.4/man 
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/3.4/info --enable-shared 
--host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --with-system-zlib 
--enable-languages=c,c++ --enable-threads=posix --enable-long-long 
--disable-checking --enable-cstdio=stdio --enable-clocale=generic 
--enable-__cxa_atexit --enable-version-specific-runtime-libs 
--with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/3.4.0/include/g++-v3 
--with-local-prefix=/usr/local --disable-werror --enable-shared --enable-nls 
--without-included-gettext --disable-multilib --with-arch=athlon-xp 
--with-cpu=athlon-xp 
Thread model: posix 
gcc version 3.4.0  (Gentoo Linux 3.4.0, pie-8.5.3) 
 /usr/libexec/gcc/i686-pc-linux-gnu/3.4.0/cc1plus -quiet -v -D_GNU_SOURCE 
test.cpp -quiet -dumpbase test.cpp -march=athlon-xp -auxbase test -version 
-o /tmp/cc3DFYJV.s 
ignoring nonexistent directory "/usr/local/include" 
ignoring nonexistent directory 
"/usr/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../i686-pc-linux-gnu/include" 
#include "..." search starts here: 
#include <...> search starts here: 
 /usr/lib/gcc/i686-pc-linux-gnu/3.4.0/include/g++-v3 
 /usr/lib/gcc/i686-pc-linux-gnu/3.4.0/include/g++-v3/i686-pc-linux-gnu 
 /usr/lib/gcc/i686-pc-linux-gnu/3.4.0/include/g++-v3/backward 
 /usr/lib/gcc/i686-pc-linux-gnu/3.4.0/include 
 /usr/include 
End of search list. 
GNU C++ version 3.4.0  (Gentoo Linux 3.4.0, pie-8.5.3) (i686-pc-linux-gnu) 
	compiled by GNU C version 3.4.0  (Gentoo Linux 3.4.0, pie-8.5.3). 
GGC heuristics: --param ggc-min-expand=73 --param ggc-min-heapsize=80638 
test.h: In function `int main(int, char**)': 
test.h:16: error: `foo<T>::foo(const foo<T>&) [with T = char]' is private 
test.cpp:8: error: within this context

-- 
           Summary: friend function does not have access to private method
                    in templeted classes
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hyliviu-gcc at yahoo dot com
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i686-linux-gnu
GCC target triplet: i686-linux-gnu


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]