public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50344] New: friend declaration confused by const qualifier
@ 2011-09-09 15:33 redi at gcc dot gnu.org
  2011-09-09 19:50 ` [Bug c++/50344] " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2011-09-09 15:33 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50344
           Summary: friend declaration confused by const qualifier
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: redi@gcc.gnu.org
                CC: jason@gcc.gnu.org


template <typename T> class C
{
   friend T;
   int i;
};

struct S
{
    int f()
    {
       C<const S> c;
       return c.i;
    }
};

This is valid C++11, but fails with:

ac.cc: In member function 'int S::f()':
ac.cc:4:8: error: 'int C<const S>::i' is private
ac.cc:12:17: error: within this context

The problem is that the friend declaration names "const S" so S is not
considered a friend, it works if C<S> is used.  The standard says "If the type
specifier in a friend declaration designates a (possibly cv-qualified) class
type, that class
is declared as a friend"


This bug predates the implementation of the C++0x extended friend rules, as
shown by this example using a non-standard friend declaration supported by G++:

template<typename T> struct identity { typedef T type; };

template <typename T> class C
{
   friend class identity<T>::type;
   int i;
};

struct S
{
    int f()
    {
       C<const S> c;
       return c.i;
    }
};

This works with all versions of G++ is C<S> is used, but not C<const S>


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

end of thread, other threads:[~2011-09-22 14:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-09 15:33 [Bug c++/50344] New: friend declaration confused by const qualifier redi at gcc dot gnu.org
2011-09-09 19:50 ` [Bug c++/50344] " redi at gcc dot gnu.org
2011-09-14 21:35 ` paolo.carlini at oracle dot com
2011-09-14 22:46 ` paolo.carlini at oracle dot com
2011-09-15 10:28 ` redi at gcc dot gnu.org
2011-09-21 15:04 ` paolo.carlini at oracle dot com
2011-09-22 14:21 ` paolo at gcc dot gnu.org
2011-09-22 14:26 ` paolo.carlini at oracle dot com

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