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++/23982] New: gcc tries to call global function instead of base template's method


The following code works with previous versions of gcc (tried "3.3.5
20050117" and "4.0.2 20050901"), but fails to compile with "4.1.0
20050919".  It works if Base and Derived aren't templates and it works
if I call this->func(t) (which is a simple workaround).


------8<-----------------
int func(const char*);

class Test {
	int i1, i2;
};

template <class T>
class Base {
public:
	void func(T &t) { };
};

template <class T>
class Derived : public Base<T> {
public:
	void call_func(T &t) {
#if 1
		func(t);
#else
		this->func(t);
#endif
	};
};

int main()
{
	Derived<Test> d;
	Test t;

	d.call_func(t);

	return 0;
}
------8<-----------------

$ g++ -Wall  scope.cc
scope.cc: In member function &#8216;void Derived<T>::call_func(T&) [with T = Test]&#8217;:
scope.cc:30:   instantiated from here
scope.cc:18: error: cannot convert &#8216;Test&#8217; to &#8216;const char*&#8217; for argument &#8216;1&#8217; to
&#8216;int func(const char*)&#8217;

$ g++ -v
Using built-in specs.
Target: i586-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man
--libdir=/usr/lib --libexecdir=/usr/lib
--enable-languages=c,c++,objc,f95,java,ada --enable-checking
--with-gxx-include-dir=/usr/include/c++/4.1.0 --disable-libssp
--enable-java-awt=gtk --disable-libjava-multilib --with-slibdir=/lib
--with-system-zlib --enable-shared --enable-__cxa_atexit
--without-system-libunwind --host=i586-suse-linux
Thread model: posix
gcc version 4.1.0 20050919 (experimental) (SUSE Linux)

PS: Sorry if this isn't a bug, I'm not that experienced in C++...

-- 
           Summary: gcc tries to call global function instead of base
                    template's method
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mmarek at suse dot cz
                CC: gcc-bugs at gcc dot gnu dot org


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


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