Bug 15453 - Friend declaration treated as a declaration in scope.
Friend declaration treated as a declaration in scope.
Status: RESOLVED DUPLICATE of bug 1016
Product: gcc
Classification: Unclassified
Component: c++
3.4.0
: P2 normal
: 4.0.1
Assigned To: Kriang Lerdsuwanakij
: rejects-valid
Depends on:
Blocks: 12944 16995
  Show dependency treegraph
 
Reported: 2004-05-15 03:38 UTC by Ivan Godard
Modified: 2005-05-22 14:06 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 2.95.3 3.0.4 3.2.3 3.3.3 3.4.0 4.0.0
Last reconfirmed: 2004-05-15 09:46:30


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Godard 2004-05-15 03:38:06 UTC
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
Comment 1 Andrew Pinski 2004-05-15 03:47:16 UTC
ICC 6.0 accepts this.  I am leaving someone more confidence than I am in C++ standard confirming this 
bug.
Comment 2 Andrew Pinski 2004-05-15 03:49:40 UTC
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;
    }
Comment 3 Giovanni Bajo 2004-05-15 09:46:28 UTC
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.
Comment 4 Giovanni Bajo 2004-05-15 09:47:21 UTC
I forgot to say, there might be a duplicate of this somewhere in Bugzilla.
Comment 5 Kriang Lerdsuwanakij 2004-10-13 15:21:02 UTC
Working on friend injection issues.
Comment 6 Kriang Lerdsuwanakij 2004-12-28 15:30:32 UTC
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 ***
Comment 7 Kriang Lerdsuwanakij 2005-05-22 11:43:25 UTC
Also fixed in GCC 4.0.1.