public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/23982] New: gcc tries to call global function instead of base template's method
@ 2005-09-20 16:38 mmarek at suse dot cz
  2005-09-20 16:43 ` [Bug c++/23982] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: mmarek at suse dot cz @ 2005-09-20 16:38 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/23982] gcc tries to call global function instead of base template's method
  2005-09-20 16:38 [Bug c++/23982] New: gcc tries to call global function instead of base template's method mmarek at suse dot cz
@ 2005-09-20 16:43 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-20 16:43 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-20 16:43 -------
Yes the behavior in 4.1.0 is the correct behavior as defined by the C++ standard and its Defect reports.

This is a dup of bug 5660 which was fixed for 4.1.0.

>PS: Sorry if this isn't a bug, I'm not that experienced in C++...
The namelookup rules for templates are harder than normal namelookup.

*** This bug has been marked as a duplicate of 5660 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-09-20 16:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-20 16:38 [Bug c++/23982] New: gcc tries to call global function instead of base template's method mmarek at suse dot cz
2005-09-20 16:43 ` [Bug c++/23982] " pinskia at gcc dot gnu dot 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).