This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/16395] New: Problem with operator& and templates
- From: "chgros+bugzilla at stanford dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Jul 2004 22:53:45 -0000
- Subject: [Bug c++/16395] New: Problem with operator& and templates
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Under certain conditions (non-fully defined template it seems), operator&
overload is not used.
output of gcc -v:
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.4/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib
--enable-nls --without-included-gettext --enable-__cxa_atexit
--enable-clocale=gnu --enable-debug --enable-java-gc=boehm
--enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.4 (Debian 1:3.3.4-2)
Sample program:
template<typename T> class A
{
public:
A();
void foo()const{}
const A &operator&()const{return *this;}
};
template<typename T> const A<int> &test_amp(){return *new A<int>;}
void test()
{
A<void> a;
(&test_amp<int>()).foo();
}
int main(int argc, char**argv){}
template <typename X> A<X>::A(){}
Compiler output:
gccbug.cc: In function `void test()':
gccbug.cc:37: error: request for member `foo' in `+test_amp [with T = int]()',
which is of non-aggregate type `const A<int>*'
If the constructor for A is placed before test, or if the "A<void> a"
declaration is removed, or if "int" is replaced with "void" in test_amp, the
problem disappears.
--
Summary: Problem with operator& and templates
Product: gcc
Version: 3.3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: chgros+bugzilla at stanford dot edu
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16395