public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: bangerth@ticam.utexas.edu
To: gcc-gnats@gcc.gnu.org
Subject: c++/8099: Friend classes and template specializations
Date: Mon, 30 Sep 2002 10:16:00 -0000	[thread overview]
Message-ID: <20020930170752.5605.qmail@sources.redhat.com> (raw)


>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:


             reply	other threads:[~2002-09-30 17:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-30 10:16 bangerth [this message]
2002-12-16  8:26 Kriang Lerdsuwanakij
2002-12-19  7:33 lerdsuwa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020930170752.5605.qmail@sources.redhat.com \
    --to=bangerth@ticam.utexas.edu \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).