Bug 58053 - Bogus "error ... is private ... within this context"
Summary: Bogus "error ... is private ... within this context"
Status: RESOLVED DUPLICATE of bug 58054
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2013-08-02 05:28 UTC by Paul Pluzhnikov
Modified: 2013-08-05 04:13 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Pluzhnikov 2013-08-02 05:28:18 UTC
Test case:

class Foo {
  struct Bar { };
  friend class F;
};

class F
#ifdef BUG
  : public Foo::Bar
#endif
{
  void Fn() { Foo::Bar b; }
};

Using "g++ (GCC) 4.9.0 20130730 (experimental)", the test compiles (clearly Foo::Bar is accessible to F::Fn()), but fails with -DBUG:

t.cc:2:10: error: ‘struct Foo::Bar’ is private
   struct Bar { };
          ^
t.cc:8:17: error: within this context
   : public Foo::Bar
                 ^
Comment 1 Andrew Pinski 2013-08-02 05:50:06 UTC
Copied from bug 14281:

[class.friend]/2 in the C++ 1998 
Standard, which says: "Also, because the base-clause of the friend class is not 
part of its member declarations, the base-clause of the friend class cannot 
access the names of the private and protected members from the class granting 
friendship."

So this is invalid code unless this changed for C++11 or C++14.
Comment 2 Paul Pluzhnikov 2013-08-05 03:20:41 UTC
Quoting Richard Smith:

The standard used to say this was invalid and now says it's valid, per DR372.

This is a g++ bug, at least in C++11 mode and probably also in C++98 mode (things aren't really clear-cut for issues that were resolved post-C++03, but this seems like a clear case of a DR to me).

See llvm.org/PR16774 and
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#372
Comment 3 Andrew Pinski 2013-08-05 04:13:05 UTC
Dup of bug 58054 then.

*** This bug has been marked as a duplicate of bug 58054 ***