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]

c++/1064: "friend" fails on partially specialized template functions



>Number:         1064
>Category:       c++
>Synopsis:       "friend" fails on partially specialized template functions
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          support
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 14 08:26:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Gerardo Ballabio
>Release:        gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
FreeBSD 4.2-RELEASE (GENERIC)
>Description:
I declare a template function eval<T, Op> to be a friend of
class expr<T, Op>. Then I define a partial specialization
for the case eval<int, Op>. When the latter function is
called, the compiler doesn't let it access the private
members of expr<int, Op>.
The error message is:

foo.cc: In function `void eval<foo>(int *, const expr<int,foo> &)':
foo.cc:39:   instantiated from here
foo.cc:8: `int expr<int,foo>::val' is private
foo.cc:33: within this context
foo.cc:9: `struct foo expr<int,foo>::op' is private
foo.cc:33: within this context                                                  

Maybe my code isn't standard-conforming (it compiles
correctly under gcc version 2.91, which perhaps is more
tolerant about this). If it is the case, can you tell me
the correct syntax?
>How-To-Repeat:
template <class T, class Op> class expr;
template <class T, class Op> void eval(int *, const expr<T, Op> &);
 
template <class T, class Op> class expr
{
  friend void eval<>(int *, const expr<T, Op> &);
private:
  T val;
  Op op;
public:
  expr(T v, Op o) : val(v), op(o) { }
};
 
struct foo
{
  void eval(int *n, int m) const { *n = m; }
};
 
expr<int, foo> bar(int n)
{
  return expr<int, foo>(n, foo());
}

template <class T, class Op> void eval(int *n, const expr<T, Op> &e)
{
  int temp;
  eval<>(&temp, e.val);
  e.op.eval(n, temp);
}
 
template <class Op> void eval(int *n, const expr<int, Op> &e)
{
  e.op.eval(n, e.val);
}
 
int main()
{
  int n;
  eval<>(&n, bar(1)); 
  return 0;
}
>Fix:
I don't know how to fix it. Please help me!
>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]