This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/8099: Friend classes and template specializations
- From: bangerth at ticam dot utexas dot edu
- To: gcc-gnats at gcc dot gnu dot org
- Date: 30 Sep 2002 17:07:52 -0000
- Subject: c++/8099: Friend classes and template specializations
- Reply-to: bangerth at ticam dot utexas dot edu
>Number: 8099
>Category: c++
>Synopsis: Friend classes and template specializations
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Sep 30 10:16:13 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Wolfgang Bangerth
>Release: unknown-1.0
>Organization:
>Environment:
all gcc versions up to gcc3.2
>Description:
[Note that there are already a number of related bug reports,
at least c++/8056 comes to my mind, but there may be more.]
Maybe this is just some point where the standard is unclear:
in 14.5.3.1, the following example is given of a friend
declaration:
template <typename T> class X {
friend class X<int>;
};
One would presume that this syntax also holds if a class
Y would name a particular (fully specialized) instance of
X as a friend. That would be irrespective of whether this
instance is derived from the general template for X, or
from a partial or full explicit specialization of X. Then
the following example should compile (as it does with
Compaq's cxx and Intel's icc):
--------------------------------
template <int N, typename T> class X;
template <typename T> class X<1,T>;
template <typename P> class Y {
static int i;
template <int N, typename T> friend class X;
friend class X<1,P>;
};
template <typename T> class X<1,T> {
X () { Y<T>::i; }; // access private field
};
-------------------------------------
gcc rejects the second friend declaration, apparently
refering to 14.7.3.17, which states that "An explicit
specialization declaration shall not be a friend
declaration".
So I admit I am confused, both about the standard and
the behavior of different compilers. Since gcc behavior
restricts the use of the language (IMHO) unduly, I would
opt for it to follow the other compiler's interpretation.
Regards
Wolfgang
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: