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
* [Bug c++/50344] friend declaration confused by const qualifier
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 ` redi at gcc dot gnu.org
2011-09-14 21:35 ` paolo.carlini at oracle dot com
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2011-09-09 19:50 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50344
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-09-09 19:47:42 UTC ---
both testcases are fixed simply by adding this to the top of make_friend_class
in friend.c
friend_type = cv_unqualified (friend_type);
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/50344] friend declaration confused by const qualifier
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
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-14 21:35 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50344
--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-14 21:11:02 UTC ---
So, I guess we only need confirmation that your analysis is correct. Indeed, I
can confirm that the patch, only one line thus not requiring a Copyright
assignment, works for the testcase (however, I didn't fully regression test it
yet).
Jason, can you have a look?
PS: Current Comeau accepts the snippet.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/50344] friend declaration confused by const qualifier
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
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-14 22:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50344
--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-14 21:34:35 UTC ---
Passes the testsuite.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/50344] friend declaration confused by const qualifier
2011-09-09 15:33 [Bug c++/50344] New: friend declaration confused by const qualifier redi at gcc dot gnu.org
` (2 preceding siblings ...)
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
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2011-09-15 10:28 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50344
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-09-15 10:06:31 UTC ---
Thanks Paolo - I forgot to add a follow-up comment to say I'd tested it
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/50344] friend declaration confused by const qualifier
2011-09-09 15:33 [Bug c++/50344] New: friend declaration confused by const qualifier redi at gcc dot gnu.org
` (3 preceding siblings ...)
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
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-21 15:04 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50344
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2011-09-21
AssignedTo|unassigned at gcc dot |paolo.carlini at oracle dot
|gnu.org |com
Target Milestone|--- |4.7.0
Ever Confirmed|0 |1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/50344] friend declaration confused by const qualifier
2011-09-09 15:33 [Bug c++/50344] New: friend declaration confused by const qualifier redi at gcc dot gnu.org
` (4 preceding siblings ...)
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
6 siblings, 0 replies; 8+ messages in thread
From: paolo at gcc dot gnu.org @ 2011-09-22 14:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50344
--- Comment #5 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2011-09-22 14:16:33 UTC ---
Author: paolo
Date: Thu Sep 22 14:16:27 2011
New Revision: 179088
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179088
Log:
/cp
2011-09-22 Jonathan Wakely <jwakely.gcc@gmail.com>
Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50344
* friend.c (make_friend_class): cv-qualification is ok in a
friend declaration.
/testsuite
2011-09-22 Jonathan Wakely <jwakely.gcc@gmail.com>
Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50344
* g++.dg/template/friend52.C: New.
Added:
trunk/gcc/testsuite/g++.dg/template/friend52.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/friend.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/50344] friend declaration confused by const qualifier
2011-09-09 15:33 [Bug c++/50344] New: friend declaration confused by const qualifier redi at gcc dot gnu.org
` (5 preceding siblings ...)
2011-09-22 14:21 ` paolo at gcc dot gnu.org
@ 2011-09-22 14:26 ` paolo.carlini at oracle dot com
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-22 14:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50344
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-22 14:17:54 UTC ---
Done.
^ 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).