This is the mail archive of the gcc-prs@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]

c++/950: Template compilation failure



>Number:         950
>Category:       c++
>Synopsis:       Template compilation failure
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Thu Nov 30 22:16:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Peter J. Bartlett
>Release:        gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
RedHat Linux 6.2.
Also fails under Redhat 7.0 with unofficial gcc-2.96.
>Description:
Strange compile problem with function templates involving pointers to virtual member functions of a derived class.
In the attached test code, compiler doesn't seem to think the virtual functions w::a() and w::b() exists in the derived class unless addresses are first copied into pointer variables.

g++ test.cc -otest
test.cc: In function `int main(unsigned int, const char *const *)':
test.cc:49: no matching function for call to `c<w>::fails_sometimes (int &, void (y::*)(int) const)'
test.cc:50: no matching function for call to `c<w>::fails_sometimes (const char *&, void (y::*)(const char *) const)'
make: *** [test] Error 1
>How-To-Repeat:
#include <iostream>


class y
{
public:
  virtual void a (int n) const { }
  virtual void b (const char *s) const { }
};

class w: public y
{
};


template <class m>
class c
{
public:
  template<class d>
  void works (const d& x) const
  { cerr << x << endl; }

  template<class d>
  void fails_sometimes (const d& x, void (m::*func)(d) const) const
  { cerr << x << endl; }
};


int main (unsigned argc, const char *const argv[])
{
  int n = 3;
  const char *s = "hey!";
  c<w> c1;

  // This works OK...
  c1.works(n);
  c1.works(s);

  // This works OK...
  void (w::*a_func)(int) const = &w::a;
  void (w::*b_func)(const char *) const = &w::b;

  // This works OK...
  c1.fails_sometimes(n, a_func);
  c1.fails_sometimes(s, b_func);
  
  // This fails compilation, but should pass...
  c1.fails_sometimes(n, &w::a);
  c1.fails_sometimes(s, &w::b);
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:

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