This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52065] Declaring template friend function of template class breaks template type inference.
- From: "keean at fry-it dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 31 Jan 2012 12:49:18 +0000
- Subject: [Bug c++/52065] Declaring template friend function of template class breaks template type inference.
- Auto-submitted: auto-generated
- References: <bug-52065-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52065
Keean Schupke <keean@fry-it.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |keean@fry-it.com
Summary|template function of |Declaring template friend
|template class s;e |function of template class
| |breaks template type
| |inference.
--- Comment #1 from Keean Schupke <keean@fry-it.com> 2012-01-31 12:49:18 UTC ---
/* g++ (Gentoo 4.6.2 p1.2, pie-0.5.0) 4.6.2
*
* Linux Orac 3.0.0-gentoo #1 SMP Wed Oct 26 10:56:22 BST 2011 x86_64 Intel(R)
Xeon(R) CPU X5570 @ 2.93GHz GenuineIntel GNU/Linux
*
* $ /var/tmp/portage/sys-devel/gcc-4.6.2/work/gcc-4.6.2/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.2
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.2
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.2/man
--infodir=/usr/share/gcc-data/x86_64-pc linux-gnu/4.6.2/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
--disable-fixed-point --without-ppl --without-cloog --enable-lto --enable-nls
--without-included-gettext --with-system-zlib --disable-werror
--enable-secureplt --enable-multilib --enable-libmudflap --disable-libssp
--enable-libgomp
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.6.2/python
--enable-checking=release --enable-java-awt=gtk --disable-libquadmath
--enable-languages=c,c++,java --enable-shared --enable-threads=posix
--enable-__cxa_atexit --enable-clocale=gnu --enable-targets=all
--with-bugurl=http://bugs.gentoo.org/ --with-pkgversion=Gentoo 4.6.2 p1.3,
pie-0.5.0
*
* g++ "thisfile.cpp"
*
* /tmp/.private/keean/ccl1iwQk.o: In function `main':
* t.cpp:(.text+0x26): undefined reference to `void f<char>(A<char const*>,
char)'
* collect2: ld returned 1 exit status
*
* We have a function template which we want to allow access to the private
* data of an object. The function template works fine just using the public
* interface of the object, but adding the friend declaration seems to break
* the type inference when the template function is called.
* I can get this to compile by changing the friend definition to:
*
* template <typename TT, typename T2> friend void f(A<TT>, T2);
*
* However this does not mean the same thing as nothing is constraining
* TT == T so this would in fact allow private access to instances of 'f'
* of _all_ types of A<*> not just the ones where the type first type parameter
* is the same type as the type parameter of the template object.
*/
template <typename T> struct A;
template <typename T, typename T2> void f(A<T> a, T2 b) {
a.t = b;
}
template <typename T> struct A {
A(T a) {t = a;}
template <typename T2> friend void f(A<T>, T2);
//template <typename TT, typename T2> friend void f(A<TT>, T2);
private:
T t;
};
int main() {
A<int> a(1);
f(a, 2.1);
}