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]

Re: Yet another template bug in gcc-2.95.1


>      With the advent of explicit template
>      specification support in g++, if the name of the friend is an
>      unqualified-id (ie, `friend foo(int)'), the C++ language
>      specification demands that the friend declare or define an
>      ordinary, nontemplate function. (Section 14.5.3).

OK, I think the passage this refers to is [temp.friend]/1

# A friend of a class or class template can be a function template or
# class template, a specialization of a func­tion template or class
# template, or an ordinary (nontemplate) function or class. For a
# friend function decla­ration that is not a template declaration:
# - if the name of the friend is a qualified or unqualified templateid,
#   the friend declaration refers to a specialization of a function
#   template, otherwise
# - if the name of the friend is a qualified­id and a matching
#   nontemplate function is found in the specified class or namespace,
#   the friend declaration refers to that function, otherwise,
# - if the name of the friend is a qualified­id and a matching
#   specialization of a template function is found in the specified
#   class or namespace, the friend declaration refers to that function
#   specialization, otherwise,
# - the name shall be an unqualified­id that declares (or redeclares)
#   an ordinary (nontemplate) function.

So, it now seems to me that gcc 2.95 is right and egcs 1.1.x was
wrong: The syntax the g++ message proposes is obviously a
specialization. This shall refer to a qualified or unqualified
template-id, but doesn't: In the scope of the class, the identifier of
refers to a template method.

It should be possible to qualify the global template in the
template-id. Unfortunately, g++ 2.95 doesn't support
global-qualification of friends.

> I'm sorry to tell you that this fix doesn't work on my box.

I'm not surprised, as you didn't follow the solution I was proposing.
In your example, your template parameter was RandomAccessIterator, so
I chose T.

> friend.cc:20: declaration of `class T'
> friend.cc:17:  shadows template parm `class T'

So you should write

  template <class A> 
  friend   ptrdiff_t operator- (const _r__It<A>& x, const _r__It<A>& y);
  
  template <class A> 
  friend   _r__It<A> operator+ (ptrdiff_t n, const _r__It<A>& x);

instead.

>   Again, egcs-1.1.2 seems to be more tolerant.

Maybe, but is also more incorrect...

> Anyways, thanks for your reply and hopefully we can work out some solution
> for my problems.

Well, the problem appears to be a misunderstanding of C++ syntax and
semantics. I would have appreciated if people make sure they are
correct before starting a message with a subject "Yet another template
bug" when it turns out that there is no template
bug. comp.lang.c++.moderated is a great place for such questions.

Regards,
Martin


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