public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/45917] New: Friend of friend is allowed the access to the private type through the template
@ 2010-10-06 21:20 yuri at tsoft dot com
  2010-10-06 21:40 ` [Bug c++/45917] " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: yuri at tsoft dot com @ 2010-10-06 21:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45917

           Summary: Friend of friend is allowed the access to the private
                    type through the template
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: yuri@tsoft.com


testcase below has struct R as private in class F.
class F declares class Q a friend, allowing it to see it's private members.
But operator<< is friend in Q, not in F.
Why is it allowed for operator<< to instantiate list<R> but not R r? This is a
bug.

--- testcase ---
#include <list>
#include <ostream>
using namespace std;

class F {
private:
  struct R {
  }; // R
  friend class Q;
  class Q {
    list<R> l;
    friend ostream& operator<<(ostream &os, const Q &q) {
      // R r; // this breaks!
      for (list<R>::const_iterator it = q.l.begin(); it != q.l.end(); it++) {
// this doesn't break! Why?
      }
      return os;
    }
  }; // Q
}; // F


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/45917] Friend of friend is allowed the access to the private type through the template
  2010-10-06 21:20 [Bug c++/45917] New: Friend of friend is allowed the access to the private type through the template yuri at tsoft dot com
@ 2010-10-06 21:40 ` redi at gcc dot gnu.org
  2010-10-06 21:48 ` [Bug c++/45917] inaccessible types allowed as template argument in nested-name-specifier redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2010-10-06 21:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45917

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2010.10.06 21:40:27
     Ever Confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-06 21:40:27 UTC ---
(In reply to comment #0)
> class F declares class Q a friend

There's no need for that, Q is a member of F so has access like any other
member.

Reduced:

template<class T>
struct list
{
  struct nested { };
};


class F
{
  struct R { };
  class Q
  {
    friend void f(const Q &q) { list<R>::nested n; }
  };
};


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/45917] inaccessible types allowed as template argument in nested-name-specifier
  2010-10-06 21:20 [Bug c++/45917] New: Friend of friend is allowed the access to the private type through the template yuri at tsoft dot com
  2010-10-06 21:40 ` [Bug c++/45917] " redi at gcc dot gnu.org
@ 2010-10-06 21:48 ` redi at gcc dot gnu.org
  2013-03-14 21:15 ` jason at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2010-10-06 21:48 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45917

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
            Summary|Friend of friend is allowed |inaccessible types allowed
                   |the access to the private   |as template argument in
                   |type through the template   |nested-name-specifier

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-06 21:48:01 UTC ---
Here's another variation that should fail but doesn't, showing this has nothing
to do with friends:

template<class T>
struct list
{
  struct nested { };
};

class F
{
  struct R { };
};

void f() { list<F::R>::nested n; }

list<F::R>::nested n;


I've changed the summary to reflect this


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/45917] inaccessible types allowed as template argument in nested-name-specifier
  2010-10-06 21:20 [Bug c++/45917] New: Friend of friend is allowed the access to the private type through the template yuri at tsoft dot com
  2010-10-06 21:40 ` [Bug c++/45917] " redi at gcc dot gnu.org
  2010-10-06 21:48 ` [Bug c++/45917] inaccessible types allowed as template argument in nested-name-specifier redi at gcc dot gnu.org
@ 2013-03-14 21:15 ` jason at gcc dot gnu.org
  2013-03-14 21:40 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-14 21:15 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45917

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |jason at gcc dot gnu.org
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/45917] inaccessible types allowed as template argument in nested-name-specifier
  2010-10-06 21:20 [Bug c++/45917] New: Friend of friend is allowed the access to the private type through the template yuri at tsoft dot com
                   ` (2 preceding siblings ...)
  2013-03-14 21:15 ` jason at gcc dot gnu.org
@ 2013-03-14 21:40 ` jason at gcc dot gnu.org
  2013-03-17  2:40 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-14 21:40 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45917

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-14 21:40:38 UTC ---
Created attachment 29671
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29671
patch

Simple fix, waiting for 4.8 to branch.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/45917] inaccessible types allowed as template argument in nested-name-specifier
  2010-10-06 21:20 [Bug c++/45917] New: Friend of friend is allowed the access to the private type through the template yuri at tsoft dot com
                   ` (3 preceding siblings ...)
  2013-03-14 21:40 ` jason at gcc dot gnu.org
@ 2013-03-17  2:40 ` jason at gcc dot gnu.org
  2013-03-22 11:18 ` paolo.carlini at oracle dot com
  2013-04-01 21:04 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-17  2:40 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45917

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-17 02:39:39 UTC ---
Author: jason
Date: Sun Mar 17 02:39:22 2013
New Revision: 196744

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196744
Log:
    PR c++/45917
    * parser.c (cp_parser_template_id): Don't forget access checks.

Added:
    trunk/gcc/testsuite/g++.dg/template/access26.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/45917] inaccessible types allowed as template argument in nested-name-specifier
  2010-10-06 21:20 [Bug c++/45917] New: Friend of friend is allowed the access to the private type through the template yuri at tsoft dot com
                   ` (4 preceding siblings ...)
  2013-03-17  2:40 ` jason at gcc dot gnu.org
@ 2013-03-22 11:18 ` paolo.carlini at oracle dot com
  2013-04-01 21:04 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-03-22 11:18 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45917

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |antoinep92 at gmail dot com

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-03-22 11:17:35 UTC ---
*** Bug 56687 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/45917] inaccessible types allowed as template argument in nested-name-specifier
  2010-10-06 21:20 [Bug c++/45917] New: Friend of friend is allowed the access to the private type through the template yuri at tsoft dot com
                   ` (5 preceding siblings ...)
  2013-03-22 11:18 ` paolo.carlini at oracle dot com
@ 2013-04-01 21:04 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2013-04-01 21:04 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45917

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.9.0

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2013-04-01 21:04:03 UTC ---
Fixed for 4.9.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-04-01 21:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-06 21:20 [Bug c++/45917] New: Friend of friend is allowed the access to the private type through the template yuri at tsoft dot com
2010-10-06 21:40 ` [Bug c++/45917] " redi at gcc dot gnu.org
2010-10-06 21:48 ` [Bug c++/45917] inaccessible types allowed as template argument in nested-name-specifier redi at gcc dot gnu.org
2013-03-14 21:15 ` jason at gcc dot gnu.org
2013-03-14 21:40 ` jason at gcc dot gnu.org
2013-03-17  2:40 ` jason at gcc dot gnu.org
2013-03-22 11:18 ` paolo.carlini at oracle dot com
2013-04-01 21:04 ` jason at gcc dot gnu.org

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).