In the following example: template<typename G, template<typename H> class I = B> class J; template<typename C, template<typename D> class E> class F { template<typename G, template<typename H> class I = B> friend class J; template<typename K, template<typename L> class M = B> friend class N; friend class O; J<int, B>* j; N<int, B>* n; O* o; }; int main() { return 0; } N appears to not be recognized as a template (in the declaration of n) based on its declaration as a template friend, whereas exactly the same declaration with an additional declaration in file scope is acceptable (template class J, declaring j), as is a friend declaration of a plain class. The c++ rules in this area are incomprehensible to me, but admitting friend declarations in one case and not the other seems unreasonable if not incorrect. Ivan
ICC 6.0 accepts this. I am leaving someone more confidence than I am in C++ standard confirming this bug.
I had forgot to give a little better example (which is the one which works for ICC): template<typename G, template<typename H> class I> class J; template<typename C, template<typename D> class B> class F { template<typename G, template<typename H> class I = B> friend class J; template<typename K, template<typename L> class M = B> friend class N; friend class O; J<int, B>* j; N<int, B>* n; O* o; }; int main() { return 0; }
No, the problem is the opposite. The standard says that a friend declaration does not introduce the name into the scope in which it is declared ([basic.scope]/3). So, if we have a bug here, is that we accept the non- template case: --------------------------- class A { friend class O; O* o; }; --------------------------- This should be rejected but it is accepted by GCC. I keep this as the bug tracked in this report. BTW, latest EDG agrees with my interpretation, so either Andrew is using an old ICC, or he hasn't activated strict ansi mode.
I forgot to say, there might be a duplicate of this somewhere in Bugzilla.
Working on friend injection issues.
The patch for PR1016 will also fix this bug. That patch is ready and the plan is getting it in after GCC 4.0 is branched. I am closing this as a duplicate. *** This bug has been marked as a duplicate of 1016 ***
Also fixed in GCC 4.0.1.