public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: David Decotigny <David.Decotigny@irisa.fr>
To: gcc-gnats@gcc.gnu.org
Cc: ddecotig@irisa.fr
Subject: c++/7818: Bug collection for unbound template friend member functions that cannot access protected members (gcc 3.x)
Date: Tue, 03 Sep 2002 05:46:00 -0000	[thread overview]
Message-ID: <200209031242.OAA26948@blutch.irisa.fr> (raw)


>Number:         7818
>Category:       c++
>Synopsis:       protected members still non-reachable from an unbound friend template member function
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 03 05:46:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     David Decotigny
>Release:        3.1
>Organization:
IRISA, Campus de Beaulieu, 35042 Rennes Cedex, FRANCE
>Environment:
System: SunOS blutch 5.7 Generic_106541-19 sun4u sparc SUNW,Ultra-5_10
Architecture: sun4

	
host: sparc-sun-solaris2.7
build: sparc-sun-solaris2.7
target: sparc-sun-solaris2.7
configured with: ../gcc/gcc-3.1/configure --prefix /usr/local/gcc-3.1 --enable-shared --enable-languages=c++,f77
>Description:
	
3 problems.

1/ When a friend member function F() of an unbound template class
T<class Bar> is declared inside a template class C<class Foo>, gcc
forbids access to the protected members of C<Foo> from
T<Bar>::F(). Work-around: declare an additional unbound friend class
U<class Baz> of C<Foo>, with a member function U<Baz>::Toto() that
accesses the protected members of C<Foo>, with the same "Foo" for T
and U.

2/ If T binds C<Foo> with Foo = Zorglub1, and U binds it with a
different Foo = Zorglub2, then none of the previous configurations
suite gcc: the same error for both T<Bar>::F() and U<Baz>::Toto(),
complaining that the member they try to access is protected. No
work-around found.

3/ If class C is not a template class anymore, then same symptoms. No
work-around found.

This behavior is common to gcc 3.0, 3.0.1, 3.0.4 and 3.1 at least
(solaris 2.7/sparc64). gcc-2.95.3 always fails (no work-around found,
even for 1/).

>How-To-Repeat:

See comments at the top of the file:

--------------------------------------------------------

// Bug 1: undefine macro HIDE_ERROR
// Bug 2: Bind "TheClass<short> c" with something different then
//        "short" in bar() or member() (but not both)
// Bug 3: replace "template <class Foo> class TheClass" with "class
//        TheClass" (ie no template) and update the "TheClass<short> c"
//        accordingly

// Forward declaration
template <class T> class AnotherFriend;

template <class Foo>
class TheClass
{
public:
protected:
  int prot_data;

  template <class Baz>
  friend class Friend;    // unbound friend class

  template <class Bar>      // unbound friend member function
  friend void AnotherFriend<Bar>::member();
};


#ifdef HIDE_ERROR
template <class Baz>
class Friend
{
public:
  void bar()
  {
    TheClass<short> c;
    c.prot_data = 2;
  }
};
#endif

        
template <class Bar>
class AnotherFriend
{
public:
  void member()
  {
    TheClass<short> c;
    c.prot_data = 2;
  }
};

int f()
{
#ifdef HIDE_ERROR
  Friend<char> t;
  t.bar();
#endif

  AnotherFriend<int> ff;
  ff.member();

  return 0;
}
--------------------------------------------------------

Here is how it looks like:

  [blutch] /tmp/ddecotig >g++-3.1 -DHIDE_ERROR -c a.cc
  # Ok
  [blutch] /tmp/ddecotig >g++-3.1 -c a.cc
  a.cc: In member function `void AnotherFriend<T>::member() [with Bar = int]':
  a.cc:59:   instantiated from here
  a.cc:16: `int TheClass<short int>::prot_data' is protected
  a.cc:47: within this context
  zsh: exit 1     g++-3.1 -c a.cc

>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted:


                 reply	other threads:[~2002-09-03 12:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=200209031242.OAA26948@blutch.irisa.fr \
    --to=david.decotigny@irisa.fr \
    --cc=ddecotig@irisa.fr \
    --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).