public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/13495] New: Impossible "friend"-ship to nested template
@ 2003-12-27 7:46 sstrasser at systemhaus-gruppe dot de
2003-12-27 16:45 ` [Bug c++/13495] Friendship to class nested withint a template is broken giovannibajo at libero dot it
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: sstrasser at systemhaus-gruppe dot de @ 2003-12-27 7:46 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1540 bytes --]
Hi.
I don´t exactly know what the correct syntax to do this is, since I couldn´t
look up in the specification, but it looks like a bug because
a) I couldn´t figure out a way to do this with GCC
b) I could figure out a way which does work with MSVC but doesn´t with GCC
so here it is:
a template class which contains a nested class which itself is no template but
inherits the template parameter:
template<typename T>
class A{
public:
class B{};
};
class A<T>::B should be friend of another class:
template<typename T>
class OtherClass{
XXX
};
A<T>::B is a dependent type, so using it requires the 'typename'-keyword.
("implicit typename deprecated")
a) XXX == friend typename A<T>::B; doesn´t work because it requires the
'class'-keyword because it´s a class friendship
b) XXX == friend class A<T>::B; doesn´t work because A<T>::B is a dependent
typename, which requires the 'typename' keyword.
c) XXX == friend typename class A<T>::B; or
d) XXX == friend class typename A<T>::B pass out with parse error.
MSVC compiles a) (wrongly) and c) (possibly correct)
Thank you,
Stefan
--
Summary: Impossible "friend"-ship to nested template
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: minor
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: sstrasser at systemhaus-gruppe dot de
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13495
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/13495] Friendship to class nested withint a template is broken
2003-12-27 7:46 [Bug c++/13495] New: Impossible "friend"-ship to nested template sstrasser at systemhaus-gruppe dot de
@ 2003-12-27 16:45 ` giovannibajo at libero dot it
2004-02-23 15:40 ` lerdsuwa at gcc dot gnu dot org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: giovannibajo at libero dot it @ 2003-12-27 16:45 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From giovannibajo at libero dot it 2003-12-27 09:03 -------
It's been clarified by DR180 that the form:
friend class A<T>::B;
is the only allowed. In fact, the name is implicitily a type because of
the 'class' keyword put in front of it, so a typename is not needed (and it is
not allowed by syntax either). This has been correctly implemented by the new
parser in GCC 3.4.
Then you must understand the difference between:
template<class T> class OtherClass {
friend class A<T>::B;
};
and:
template<class T> class OtherClass {
template <class Q>
friend class A<Q>::B;
};
In the first case, you're saying that, for each OtherClass<X>, A<X>::B is a
friend (only for the same X!). In the second, you're saying that for each
OtherClass<X>, any A<Y>::B is a friend (for any Y).
Nonetheless, there is indeed a bug in GCC. I propose this testcase:
--------------------------------------------
template<typename T>
class A{
public:
class B
{
void func1(void);
void func2(void);
};
};
template<typename Q>
class F1
{
friend class A<Q>::B;
enum { foo = 0 };
};
template<typename Q>
class F2
{
template<typename T>
friend class A<T>::B;
enum { foo = 0 };
};
template <typename T>
void A<T>::B::func1(void)
{
(void)F1<T>::foo; // OK, A<T>::B is a friend for this T (#1)
(void)F2<T>::foo; // OK, any A<K>::B is a friend (#2)
}
template <typename T>
void A<T>::B::func2(void)
{
(void)F1<double>::foo; // ERROR, A<double>::T is not a friend (#3)
(void)F2<double>::foo; // OK, any A<K>::B is a friend (#4)
}
template class A<void>;
--------------------------------------------
Thus, GCC should emit an error only for #3. Instead it emits an error for #2
and not for #3. This is clearly a bug (but not a regression, since the previous
versions of GCC were even more broken wrt friendships to nested classes or
specializations of templates).
This is a job for Kriang :)
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Keywords| |accepts-invalid, rejects-
| |valid
Last reconfirmed|0000-00-00 00:00:00 |2003-12-27 09:03:43
date| |
Summary|Impossible "friend"-ship to |Friendship to class nested
|nested template |withint a template is broken
Version|3.3 |3.4.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13495
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/13495] Friendship to class nested withint a template is broken
2003-12-27 7:46 [Bug c++/13495] New: Impossible "friend"-ship to nested template sstrasser at systemhaus-gruppe dot de
2003-12-27 16:45 ` [Bug c++/13495] Friendship to class nested withint a template is broken giovannibajo at libero dot it
@ 2004-02-23 15:40 ` lerdsuwa at gcc dot gnu dot org
2004-08-30 15:33 ` giovannibajo at libero dot it
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: lerdsuwa at gcc dot gnu dot org @ 2004-02-23 15:40 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |lerdsuwa at gcc dot gnu dot
|dot org |org
Status|NEW |ASSIGNED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13495
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/13495] Friendship to class nested withint a template is broken
2003-12-27 7:46 [Bug c++/13495] New: Impossible "friend"-ship to nested template sstrasser at systemhaus-gruppe dot de
2003-12-27 16:45 ` [Bug c++/13495] Friendship to class nested withint a template is broken giovannibajo at libero dot it
2004-02-23 15:40 ` lerdsuwa at gcc dot gnu dot org
@ 2004-08-30 15:33 ` giovannibajo at libero dot it
2004-08-31 10:56 ` lerdsuwa at gcc dot gnu dot org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: giovannibajo at libero dot it @ 2004-08-30 15:33 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From giovannibajo at libero dot it 2004-08-30 15:33 -------
Kriang, it looks like g++.old-deja/g++.pt/friend44.C is related to this bug.
The testcase is xfailed on mainline, and you already fixed half of it with your
patch for PR5369. I guess your patch for this bug also cures that testcase?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13495
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/13495] Friendship to class nested withint a template is broken
2003-12-27 7:46 [Bug c++/13495] New: Impossible "friend"-ship to nested template sstrasser at systemhaus-gruppe dot de
` (2 preceding siblings ...)
2004-08-30 15:33 ` giovannibajo at libero dot it
@ 2004-08-31 10:56 ` lerdsuwa at gcc dot gnu dot org
2004-09-04 15:59 ` lerdsuwa at gcc dot gnu dot org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: lerdsuwa at gcc dot gnu dot org @ 2004-08-31 10:56 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From lerdsuwa at gcc dot gnu dot org 2004-08-31 10:56 -------
Yes, the patch will also fix the warning produced
when testing g++.old-deja/g++.pt/friend44.C.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13495
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/13495] Friendship to class nested withint a template is broken
2003-12-27 7:46 [Bug c++/13495] New: Impossible "friend"-ship to nested template sstrasser at systemhaus-gruppe dot de
` (3 preceding siblings ...)
2004-08-31 10:56 ` lerdsuwa at gcc dot gnu dot org
@ 2004-09-04 15:59 ` lerdsuwa at gcc dot gnu dot org
2004-09-06 15:56 ` lerdsuwa at gcc dot gnu dot org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: lerdsuwa at gcc dot gnu dot org @ 2004-09-04 15:59 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From lerdsuwa at gcc dot gnu dot org 2004-09-04 15:59 -------
Patch in progress. Note that even with the fix,
GCC still doesn't diagnose the code in Comment #1
correctly because of PR16617.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13495
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/13495] Friendship to class nested withint a template is broken
2003-12-27 7:46 [Bug c++/13495] New: Impossible "friend"-ship to nested template sstrasser at systemhaus-gruppe dot de
` (4 preceding siblings ...)
2004-09-04 15:59 ` lerdsuwa at gcc dot gnu dot org
@ 2004-09-06 15:56 ` lerdsuwa at gcc dot gnu dot org
2004-10-20 16:21 ` [Bug c++/13495] Friendship to class nested within " cvs-commit at gcc dot gnu dot org
2004-10-20 16:25 ` lerdsuwa at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: lerdsuwa at gcc dot gnu dot org @ 2004-09-06 15:56 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From lerdsuwa at gcc dot gnu dot org 2004-09-06 15:55 -------
Patch submitted:
http://gcc.gnu.org/ml/gcc-patches/2004-09/msg00557.html
--
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13495
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/13495] Friendship to class nested within a template is broken
2003-12-27 7:46 [Bug c++/13495] New: Impossible "friend"-ship to nested template sstrasser at systemhaus-gruppe dot de
` (5 preceding siblings ...)
2004-09-06 15:56 ` lerdsuwa at gcc dot gnu dot org
@ 2004-10-20 16:21 ` cvs-commit at gcc dot gnu dot org
2004-10-20 16:25 ` lerdsuwa at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-10-20 16:21 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2004-10-20 16:20 -------
Subject: Bug 13495
CVSROOT: /cvs/gcc
Module name: gcc
Changes by: lerdsuwa@gcc.gnu.org 2004-10-20 16:20:51
Modified files:
gcc/cp : ChangeLog cp-tree.h decl.c friend.c parser.c
pt.c
gcc/testsuite : ChangeLog
gcc/testsuite/g++.old-deja/g++.pt: friend44.C
Added files:
gcc/testsuite/g++.dg/template: memfriend9.C memfriend10.C
memfriend11.C memfriend12.C
memfriend13.C memfriend14.C
memfriend15.C memfriend16.C
memfriend17.C
Log message:
PR c++/13495
* decl.c (make_unbound_class_template): Add PARM_LIST parameter.
* cp-tree.h (make_unbound_class_template): Adjust prototype.
* parser.c (cp_parser_lookup_name): Adjust call to
make_unbound_class_template.
(cp_parser_single_declaration): Handle member class of class
template as template friend parsing correctly.
* friend.c (is_friend): Call is_specialization_of_friend for
template friend class.
(make_friend_class): Handle member class of class template as
template friend.
* pt.c (is_specialization_of_friend): Likewise.
(instantiate_class_template): Likewise.
(tsubst): Adjust call to make_unbound_class_template.
* g++.dg/template/memfriend9.C: New test.
* g++.dg/template/memfriend10.C: Likewise.
* g++.dg/template/memfriend11.C: Likewise.
* g++.dg/template/memfriend12.C: Likewise.
* g++.dg/template/memfriend13.C: Likewise.
* g++.dg/template/memfriend14.C: Likewise.
* g++.dg/template/memfriend15.C: Likewise.
* g++.dg/template/memfriend16.C: Likewise.
* g++.dg/template/memfriend17.C: Likewise.
* g++.old-deja/g++.pt/friend44.C: Remove bogus error.
Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4447&r2=1.4448
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.1065&r2=1.1066
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1316&r2=1.1317
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/friend.c.diff?cvsroot=gcc&r1=1.101&r2=1.102
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.267&r2=1.268
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.936&r2=1.937
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4478&r2=1.4479
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend9.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend10.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend11.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend12.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend13.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend14.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend15.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend16.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/memfriend17.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.pt/friend44.C.diff?cvsroot=gcc&r1=1.3&r2=1.4
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13495
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/13495] Friendship to class nested within a template is broken
2003-12-27 7:46 [Bug c++/13495] New: Impossible "friend"-ship to nested template sstrasser at systemhaus-gruppe dot de
` (6 preceding siblings ...)
2004-10-20 16:21 ` [Bug c++/13495] Friendship to class nested within " cvs-commit at gcc dot gnu dot org
@ 2004-10-20 16:25 ` lerdsuwa at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: lerdsuwa at gcc dot gnu dot org @ 2004-10-20 16:25 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From lerdsuwa at gcc dot gnu dot org 2004-10-20 16:25 -------
I am closing this as fixed by patch:
http://gcc.gnu.org/ml/gcc-patches/2004-10/msg01709.html
For access checking problem mentioned in the comments, it's
already covered in PR16617. That part requires some structural
changes that won't be investigated for some time.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.0.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13495
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2004-10-20 16:25 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-27 7:46 [Bug c++/13495] New: Impossible "friend"-ship to nested template sstrasser at systemhaus-gruppe dot de
2003-12-27 16:45 ` [Bug c++/13495] Friendship to class nested withint a template is broken giovannibajo at libero dot it
2004-02-23 15:40 ` lerdsuwa at gcc dot gnu dot org
2004-08-30 15:33 ` giovannibajo at libero dot it
2004-08-31 10:56 ` lerdsuwa at gcc dot gnu dot org
2004-09-04 15:59 ` lerdsuwa at gcc dot gnu dot org
2004-09-06 15:56 ` lerdsuwa at gcc dot gnu dot org
2004-10-20 16:21 ` [Bug c++/13495] Friendship to class nested within " cvs-commit at gcc dot gnu dot org
2004-10-20 16:25 ` lerdsuwa at gcc dot gnu dot 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).