public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58263] New: [feature request] friend class $UndefinedClass
@ 2013-08-28 14:45 vova7890 at mail dot ru
2013-08-28 14:51 ` [Bug c++/58263] " redi at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: vova7890 at mail dot ru @ 2013-08-28 14:45 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58263
Bug ID: 58263
Summary: [feature request] friend class $UndefinedClass
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: trivial
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: vova7890 at mail dot ru
Idea is in:
class MyClass1
{
friend class MyClas2; // trivial stupid human issue with MyClas2 -> MyClass2
private:
void help();
};
class MyClass2
{
public:
void need(MyClass1 *cl) {
cl->help(); // error: is private!!
}
};
Maybe need to check, have we declaration or not. If not - got a warning about
missing declaration.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/58263] [feature request] friend class $UndefinedClass
2013-08-28 14:45 [Bug c++/58263] New: [feature request] friend class $UndefinedClass vova7890 at mail dot ru
@ 2013-08-28 14:51 ` redi at gcc dot gnu.org
2013-08-28 16:32 ` vova7890 at mail dot ru
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2013-08-28 14:51 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58263
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|trivial |enhancement
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to vova7890 from comment #0)
> Maybe need to check, have we declaration or not. If not - got a warning
> about missing declaration.
That can't work, consider:
// A.h
class A {
A();
friend class B;
};
// B.h
#include "A.h"
class B { };
// A.cc
#include "A.h"
A::A() {}
Do we warn in A.cc that B is not defined? It is defined in another header, but
that isn't included by A.cc because it isn't needed.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/58263] [feature request] friend class $UndefinedClass
2013-08-28 14:45 [Bug c++/58263] New: [feature request] friend class $UndefinedClass vova7890 at mail dot ru
2013-08-28 14:51 ` [Bug c++/58263] " redi at gcc dot gnu.org
@ 2013-08-28 16:32 ` vova7890 at mail dot ru
2013-08-28 17:29 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: vova7890 at mail dot ru @ 2013-08-28 16:32 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58263
--- Comment #2 from vova7890 <vova7890 at mail dot ru> ---
(In reply to Jonathan Wakely from comment #1)
> Do we warn in A.cc that B is not defined? It is defined in another header,
> but that isn't included by A.cc because it isn't needed.
We warn about implicit friend class MyClas2. For example, we wrong writed class
name(as in example MyClas2 -> MyClass2, missed the letter "s" in the word
Class), try to compile that and see:
[vova7890@localhost tmp]$ g++ -O2 main.cpp
main.cpp: In member function 'void MyClass2::need(MyClass1*)':
main.cpp:10:9: error: 'void MyClass1::help()' is private
void help();
^
main.cpp:18:16: error: within this context
cl->help(); // error: is private!!
But, we don`t understand why it`s private, because we think that we correctly
writed class name(friend class MyClass2), and do not see where is the bug
exactly. But, if compiler say as, about implicit friend class MyClas2, like
this:
[vova7890@localhost tmp]$ g++ -O2 main.cpp
main.cpp:8:12: warning: implicit declaration of friend 'MyClas2'
friend class MyClas2;
^
main.cpp: In member function 'void MyClass2::need(MyClass1*)':
main.cpp:10:9: error: 'void MyClass1::help()' is private
void help();
^
main.cpp:18:16: error: within this context
cl->help(); // error: is private!!
we see where is exactly issue, and just correct that stupid typo.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/58263] [feature request] friend class $UndefinedClass
2013-08-28 14:45 [Bug c++/58263] New: [feature request] friend class $UndefinedClass vova7890 at mail dot ru
2013-08-28 14:51 ` [Bug c++/58263] " redi at gcc dot gnu.org
2013-08-28 16:32 ` vova7890 at mail dot ru
@ 2013-08-28 17:29 ` redi at gcc dot gnu.org
2013-08-28 17:42 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2013-08-28 17:29 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58263
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
But that will warn about valid code, where you didn't spell the name wrong.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/58263] [feature request] friend class $UndefinedClass
2013-08-28 14:45 [Bug c++/58263] New: [feature request] friend class $UndefinedClass vova7890 at mail dot ru
` (2 preceding siblings ...)
2013-08-28 17:29 ` redi at gcc dot gnu.org
@ 2013-08-28 17:42 ` pinskia at gcc dot gnu.org
2013-08-28 18:01 ` vova7890 at mail dot ru
2013-08-28 18:15 ` vova7890 at mail dot ru
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-08-28 17:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58263
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
How about looking into the MyClass1 to see if there is a friend class and have
a quick heuristic about the spelling mistake when doing the error message?
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/58263] [feature request] friend class $UndefinedClass
2013-08-28 14:45 [Bug c++/58263] New: [feature request] friend class $UndefinedClass vova7890 at mail dot ru
` (3 preceding siblings ...)
2013-08-28 17:42 ` pinskia at gcc dot gnu.org
@ 2013-08-28 18:01 ` vova7890 at mail dot ru
2013-08-28 18:15 ` vova7890 at mail dot ru
5 siblings, 0 replies; 7+ messages in thread
From: vova7890 at mail dot ru @ 2013-08-28 18:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58263
--- Comment #5 from vova7890 <vova7890 at mail dot ru> ---
(In reply to Jonathan Wakely from comment #3)
> But that will warn about valid code, where you didn't spell the name wrong.
Yes, but it can be not in one file, as in example. If it in one file, and
friend class is below the main class, can avoid warning by this:
class MyClass2;
class MyClass1
{
friend class MyClass2; // trivial stupid human issue with MyClas2 ->
MyClass2
private:
void help();
};
class MyClass2
{
public:
void need(MyClass1 *cl) {
cl->help(); // error: is private!!
}
};
Also, maybe can use it on paranoid level warnings, for example.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/58263] [feature request] friend class $UndefinedClass
2013-08-28 14:45 [Bug c++/58263] New: [feature request] friend class $UndefinedClass vova7890 at mail dot ru
` (4 preceding siblings ...)
2013-08-28 18:01 ` vova7890 at mail dot ru
@ 2013-08-28 18:15 ` vova7890 at mail dot ru
5 siblings, 0 replies; 7+ messages in thread
From: vova7890 at mail dot ru @ 2013-08-28 18:15 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58263
--- Comment #6 from vova7890 <vova7890 at mail dot ru> ---
(In reply to Andrew Pinski from comment #4)
> How about looking into the MyClass1 to see if there is a friend class and
> have a quick heuristic about the spelling mistake when doing the error
> message?
Good idea. Can lookup for class name in visible fields, and also in curent
source, including fields after friend-contained class.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-08-28 18:15 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-28 14:45 [Bug c++/58263] New: [feature request] friend class $UndefinedClass vova7890 at mail dot ru
2013-08-28 14:51 ` [Bug c++/58263] " redi at gcc dot gnu.org
2013-08-28 16:32 ` vova7890 at mail dot ru
2013-08-28 17:29 ` redi at gcc dot gnu.org
2013-08-28 17:42 ` pinskia at gcc dot gnu.org
2013-08-28 18:01 ` vova7890 at mail dot ru
2013-08-28 18:15 ` vova7890 at mail dot ru
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).