public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/29615] New: Class can't be friends of itself?
@ 2006-10-27 14:06 danny dot boelens at artwork-systems dot com
2006-10-27 22:57 ` [Bug c++/29615] " bangerth at dealii dot org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: danny dot boelens at artwork-systems dot com @ 2006-10-27 14:06 UTC (permalink / raw)
To: gcc-bugs
The following simple C++ file:
<test.cpp>
class A
{
friend class A;
};
int main() { return 0; }
</test.cpp>
results in the following error when I try to compile it with g++:
$ ~/gcc-build-4.2-20061007/gcc/g++ -o test test.cpp
test.cpp:3: error: class 'A' is implicitly friends with itself
I was using a snapshot (GCC 4.2 2006/10/07), but I got the same behaviour with
several 4.1.x and 4.0.x builds on both Linux and Windows 2000 (Cygwin).
I agree that it's pointless to make a class a friend of itself (which is why I
used severity 'minor'), but I haven't found anything in my C++ spec (ISO/IEC
14882) that say it is not allowed. Please point my to the relevant section in
case I missed anything.
By the way: all other compilers I've tried accept this file without a problem.
These include Visual Studio .NET 2003, CodeWarrior 8.3, CodeWarrior 9.6 and the
online test drive for Comeau. Comeau does exactly what I'd expect:
Your Comeau C/C++ test results are as follows:
Comeau C/C++ 4.3.8 (Aug 19 2006 13:36:48) for ONLINE_EVALUATION_Alpha1
Copyright 1988-2006 Comeau Computing. All rights reserved.
MODE:strict errors C++
"ComeauTest.c", line 3: warning: pointless friend declaration
friend class A;
^
Not a big issue, but I thought it might be a good idea to log this anyway,
since a search didn't result in relevant hits :-)
--
Summary: Class can't be friends of itself?
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: danny dot boelens at artwork-systems dot com
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29615
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/29615] Class can't be friends of itself?
2006-10-27 14:06 [Bug c++/29615] New: Class can't be friends of itself? danny dot boelens at artwork-systems dot com
@ 2006-10-27 22:57 ` bangerth at dealii dot org
2006-10-28 18:44 ` pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2006-10-27 22:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from bangerth at dealii dot org 2006-10-27 22:57 -------
Confirmed.
--
bangerth at dealii dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bangerth at dealii dot org
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2006-10-27 22:57:33
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29615
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/29615] Class can't be friends of itself?
2006-10-27 14:06 [Bug c++/29615] New: Class can't be friends of itself? danny dot boelens at artwork-systems dot com
2006-10-27 22:57 ` [Bug c++/29615] " bangerth at dealii dot org
@ 2006-10-28 18:44 ` pinskia at gcc dot gnu dot org
2007-09-21 19:42 ` pcarlini at suse dot de
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-10-28 18:44 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2006-10-28 18:44 -------
As far as I can tell this has been a pedwarning since the begining of the C++
front-end.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29615
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/29615] Class can't be friends of itself?
2006-10-27 14:06 [Bug c++/29615] New: Class can't be friends of itself? danny dot boelens at artwork-systems dot com
2006-10-27 22:57 ` [Bug c++/29615] " bangerth at dealii dot org
2006-10-28 18:44 ` pinskia at gcc dot gnu dot org
@ 2007-09-21 19:42 ` pcarlini at suse dot de
2007-09-21 22:19 ` pcarlini at suse dot de
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pcarlini at suse dot de @ 2007-09-21 19:42 UTC (permalink / raw)
To: gcc-bugs
--
pcarlini at suse dot de changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |pcarlini at suse dot de
|dot org |
Status|NEW |ASSIGNED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29615
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/29615] Class can't be friends of itself?
2006-10-27 14:06 [Bug c++/29615] New: Class can't be friends of itself? danny dot boelens at artwork-systems dot com
` (2 preceding siblings ...)
2007-09-21 19:42 ` pcarlini at suse dot de
@ 2007-09-21 22:19 ` pcarlini at suse dot de
2007-10-15 12:48 ` jens-devel at gmx dot de
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pcarlini at suse dot de @ 2007-09-21 22:19 UTC (permalink / raw)
To: gcc-bugs
--
pcarlini at suse dot de changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|pcarlini at suse dot de |unassigned at gcc dot gnu
| |dot org
Status|ASSIGNED |NEW
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29615
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/29615] Class can't be friends of itself?
2006-10-27 14:06 [Bug c++/29615] New: Class can't be friends of itself? danny dot boelens at artwork-systems dot com
` (3 preceding siblings ...)
2007-09-21 22:19 ` pcarlini at suse dot de
@ 2007-10-15 12:48 ` jens-devel at gmx dot de
2010-03-26 21:08 ` potswa at mac dot com
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: jens-devel at gmx dot de @ 2007-10-15 12:48 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from jens-devel at gmx dot de 2007-10-15 12:48 -------
Subject: Class can't be friends of itself?
Hi,
I think gcc should be able to compile something like this.
There is no other way to make a member-variable accessible only from all
objects which are of the same type. Am I wrong?
<test.cpp>
class A
{
friend class A;
private:
int var_accessible_from_all_A_objects;
};
int main() { return 0; }
</test.cpp>
Greetings
Jens
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29615
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/29615] Class can't be friends of itself?
2006-10-27 14:06 [Bug c++/29615] New: Class can't be friends of itself? danny dot boelens at artwork-systems dot com
` (4 preceding siblings ...)
2007-10-15 12:48 ` jens-devel at gmx dot de
@ 2010-03-26 21:08 ` potswa at mac dot com
2010-03-27 20:15 ` redi at gcc dot gnu dot org
2010-03-27 20:19 ` redi at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: potswa at mac dot com @ 2010-03-26 21:08 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from potswa at mac dot com 2010-03-26 21:08 -------
The error doesn't occur if the friend is a template instance, so it really
doesn't hurt anyone. But it's weird.
template< int z >
class F {
friend class F<0>; // error only if <0> removed
};
template class F<0>;
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29615
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/29615] Class can't be friends of itself?
2006-10-27 14:06 [Bug c++/29615] New: Class can't be friends of itself? danny dot boelens at artwork-systems dot com
` (5 preceding siblings ...)
2010-03-26 21:08 ` potswa at mac dot com
@ 2010-03-27 20:15 ` redi at gcc dot gnu dot org
2010-03-27 20:19 ` redi at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-03-27 20:15 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1118 bytes --]
------- Comment #5 from redi at gcc dot gnu dot org 2010-03-27 20:14 -------
With current versions this is only a warning not an error, changing keywords
from rejects-valid to diagnostic
(In reply to comment #3)
> There is no other way to make a member-variable accessible only from all
> objects which are of the same type. Am I wrong?
Yes.
(In reply to comment #4)
> The error doesn't occur if the friend is a template instance, so it really
> doesn't hurt anyone. But it's weird.
>
> template< int z >
> class F {
> friend class F<0>; // error only if <0> removed
> };
Well in that case it isn't friends with itself, so not really weird.
This shows that being a template has nothing to do with it:
template< int z >
class F {
friend class F<z>;
};
warning: class F<z> is implicitly friends with itself
--
redi at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|rejects-valid |diagnostic
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29615
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/29615] Class can't be friends of itself?
2006-10-27 14:06 [Bug c++/29615] New: Class can't be friends of itself? danny dot boelens at artwork-systems dot com
` (6 preceding siblings ...)
2010-03-27 20:15 ` redi at gcc dot gnu dot org
@ 2010-03-27 20:19 ` redi at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-03-27 20:19 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from redi at gcc dot gnu dot org 2010-03-27 20:19 -------
I think the warning is reasonable, but it would be nice if it could be
disabled.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29615
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-03-27 20:19 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-27 14:06 [Bug c++/29615] New: Class can't be friends of itself? danny dot boelens at artwork-systems dot com
2006-10-27 22:57 ` [Bug c++/29615] " bangerth at dealii dot org
2006-10-28 18:44 ` pinskia at gcc dot gnu dot org
2007-09-21 19:42 ` pcarlini at suse dot de
2007-09-21 22:19 ` pcarlini at suse dot de
2007-10-15 12:48 ` jens-devel at gmx dot de
2010-03-26 21:08 ` potswa at mac dot com
2010-03-27 20:15 ` redi at gcc dot gnu dot org
2010-03-27 20:19 ` redi 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).