public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/31423] New: Improve upon "invalid use of member (did you forget the '&' ?)"
@ 2007-04-01 22:01 gerald at pfeifer dot com
2007-04-02 16:09 ` [Bug c++/31423] " bangerth at dealii dot org
` (7 more replies)
0 siblings, 8 replies; 12+ messages in thread
From: gerald at pfeifer dot com @ 2007-04-01 22:01 UTC (permalink / raw)
To: gcc-bugs
For the program
struct C {
int f() { return 1; }
};
int f(C &c) {
return ( 1 == c.f );
}
we currently issue
In function 'int f(C&)':
6: error: invalid use of member (did you forget the '&' ?)
Basically, my thought is that whenever we encounter a comparison of a
member function c.f with a value that is compatible with its return type,
the author of the code probably ment to write c.f() instead of &c.f, so
the error message could propose the former.
Specifically, I suggest to issue
error: invalid use of member (did you forget the "()" ?)
instead of
error: invalid use of member (did you forget the '&' ?)
when the return type of the function c.f is an integer type and we
compare against an integer constant as per my original example.
--
Summary: Improve upon "invalid use of member (did you forget the
'&' ?)"
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gerald at pfeifer dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31423
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/31423] Improve upon "invalid use of member (did you forget the '&' ?)"
2007-04-01 22:01 [Bug c++/31423] New: Improve upon "invalid use of member (did you forget the '&' ?)" gerald at pfeifer dot com
@ 2007-04-02 16:09 ` bangerth at dealii dot org
2009-08-05 15:33 ` manu at gcc dot gnu dot org
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: bangerth at dealii dot org @ 2007-04-02 16:09 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from bangerth at dealii dot org 2007-04-02 17:09 -------
Confirmed.
W.
--
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 |2007-04-02 17:09:15
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31423
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/31423] Improve upon "invalid use of member (did you forget the '&' ?)"
2007-04-01 22:01 [Bug c++/31423] New: Improve upon "invalid use of member (did you forget the '&' ?)" gerald at pfeifer dot com
2007-04-02 16:09 ` [Bug c++/31423] " bangerth at dealii dot org
@ 2009-08-05 15:33 ` manu at gcc dot gnu dot org
2009-08-05 16:41 ` jwakely dot gcc at gmail dot com
` (5 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-08-05 15:33 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from manu at gcc dot gnu dot org 2009-08-05 15:33 -------
Perhaps we could just mention both '&' and '()'? It seems a bit difficult to
check all the conditions that you mention.
BTW, shouldn't it say 'member function'? Can this be anything different than a
member function?
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2007-04-02 17:09:15 |2009-08-05 15:33:05
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31423
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/31423] Improve upon "invalid use of member (did you forget the '&' ?)"
2007-04-01 22:01 [Bug c++/31423] New: Improve upon "invalid use of member (did you forget the '&' ?)" gerald at pfeifer dot com
2007-04-02 16:09 ` [Bug c++/31423] " bangerth at dealii dot org
2009-08-05 15:33 ` manu at gcc dot gnu dot org
@ 2009-08-05 16:41 ` jwakely dot gcc at gmail dot com
2009-08-05 17:55 ` bangerth at gmail dot com
` (4 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: jwakely dot gcc at gmail dot com @ 2009-08-05 16:41 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from jwakely dot gcc at gmail dot com 2009-08-05 16:40 -------
&c.f isn't even valid, it should be &C::f
I didn't check the code, but that message isn't used for member variables or
nested types, so if it does only apply to member functions then I think
changing '&' to '()' unconditionally makes sense.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31423
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/31423] Improve upon "invalid use of member (did you forget the '&' ?)"
2007-04-01 22:01 [Bug c++/31423] New: Improve upon "invalid use of member (did you forget the '&' ?)" gerald at pfeifer dot com
` (2 preceding siblings ...)
2009-08-05 16:41 ` jwakely dot gcc at gmail dot com
@ 2009-08-05 17:55 ` bangerth at gmail dot com
2009-08-05 17:57 ` bangerth at gmail dot com
` (3 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: bangerth at gmail dot com @ 2009-08-05 17:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from bangerth at gmail dot com 2009-08-05 17:54 -------
(In reply to comment #3)
> &c.f isn't even valid, it should be &C::f
>
> I didn't check the code, but that message isn't used for member variables or
> nested types, so if it does only apply to member functions then I think
> changing '&' to '()' unconditionally makes sense.
It also strictly wouldn't make things worse: the message we currently print
hardly ever has anything to do with what is really happening, and replacing
the ampersand by parentheses can only make things better even if it isn't
always correct.
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31423
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/31423] Improve upon "invalid use of member (did you forget the '&' ?)"
2007-04-01 22:01 [Bug c++/31423] New: Improve upon "invalid use of member (did you forget the '&' ?)" gerald at pfeifer dot com
` (3 preceding siblings ...)
2009-08-05 17:55 ` bangerth at gmail dot com
@ 2009-08-05 17:57 ` bangerth at gmail dot com
2009-08-05 18:19 ` manu at gcc dot gnu dot org
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: bangerth at gmail dot com @ 2009-08-05 17:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from bangerth at gmail dot com 2009-08-05 17:57 -------
However, one of my gripes with the previous error message is that it's
just too obscure: where did I forget the '&', and why would I have wanted
to write them in the first place? It could have said "did you forget to
take the address of this member function?" and it would have been clearer
to me what the message is supposed to tell me.
So, in order to be a bit less obscure, how about this wording:
6: error: invalid use of member (did you forget the argument list?)
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31423
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/31423] Improve upon "invalid use of member (did you forget the '&' ?)"
2007-04-01 22:01 [Bug c++/31423] New: Improve upon "invalid use of member (did you forget the '&' ?)" gerald at pfeifer dot com
` (4 preceding siblings ...)
2009-08-05 17:57 ` bangerth at gmail dot com
@ 2009-08-05 18:19 ` manu at gcc dot gnu dot org
2009-08-05 18:47 ` bangerth at gmail dot com
2009-08-06 9:51 ` jwakely dot gcc at gmail dot com
7 siblings, 0 replies; 12+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-08-05 18:19 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from manu at gcc dot gnu dot org 2009-08-05 18:19 -------
Examples where the ampersand probably makes more sense are:
g++.dg/rtti/typeid8.C
g++.dg/conversion/memfn2.C
g++.old-deja/g++.other/asm2.C
Not so sure about:
g++.dg/template/pseudodtor3.C
g++.dg/template/using14.C
So this is not as trivial.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31423
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/31423] Improve upon "invalid use of member (did you forget the '&' ?)"
2007-04-01 22:01 [Bug c++/31423] New: Improve upon "invalid use of member (did you forget the '&' ?)" gerald at pfeifer dot com
` (5 preceding siblings ...)
2009-08-05 18:19 ` manu at gcc dot gnu dot org
@ 2009-08-05 18:47 ` bangerth at gmail dot com
2009-08-06 9:51 ` jwakely dot gcc at gmail dot com
7 siblings, 0 replies; 12+ messages in thread
From: bangerth at gmail dot com @ 2009-08-05 18:47 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from bangerth at gmail dot com 2009-08-05 18:47 -------
(In reply to comment #6)
> Examples where the ampersand probably makes more sense are:
>
> g++.dg/rtti/typeid8.C
> g++.dg/conversion/memfn2.C
> g++.old-deja/g++.other/asm2.C
Possibly, but in all those cases, it may also have been a
call expression:
- in typeid8.C, did the user mean
typeid (&A::foo).name ();
or
typeid (A::foo()).name ();
(assuming A::foo is static)? Certainly in the case
typeid (foo).name ();
it is more likely that she wanted to say foo() than &A::foo.
- in memfn2.C,
void (*p)() = i ? foo : foo
was more likely meant to say
void (*p)() = i ? foo() : foo()
than
void (*p)() = i ? &A::foo : &A::foo
All I really mean is that it's at the very least equally likely
that people forget the parentheses than the ampersand. Just as
another argument, people *call* functions much more often than
they *take the address* of them -- so, all things being equal,
it's probably more likely that in any given context the intent
was a call, rather than taking the address.
W.
>
> Not so sure about:
>
> g++.dg/template/pseudodtor3.C
> g++.dg/template/using14.C
>
> So this is not as trivial.
>
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31423
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/31423] Improve upon "invalid use of member (did you forget the '&' ?)"
2007-04-01 22:01 [Bug c++/31423] New: Improve upon "invalid use of member (did you forget the '&' ?)" gerald at pfeifer dot com
` (6 preceding siblings ...)
2009-08-05 18:47 ` bangerth at gmail dot com
@ 2009-08-06 9:51 ` jwakely dot gcc at gmail dot com
7 siblings, 0 replies; 12+ messages in thread
From: jwakely dot gcc at gmail dot com @ 2009-08-06 9:51 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from jwakely dot gcc at gmail dot com 2009-08-06 09:51 -------
I don't think any of those tests would be made correct simply by replacing 'f'
with '&f'
Maybe they would have been accepted by GCC 2.95 with the ampersand present, but
current GCC correctly requires '&C::f'
I know some users want the compiler to suggest how to fix their errors, but
it's hard to make a useful suggestion for most of the nearly infinite number of
invalid expressions users can come up with. The suggestion is misleading in
too many cases (specifically, the "did you forget the '&'?" hint doesn't solve
the problem in any of the examples given in this PR.)
--
jwakely dot gcc at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jwakely dot gcc at gmail dot
| |com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31423
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/31423] Improve upon "invalid use of member (did you forget the '&' ?)"
[not found] <bug-31423-4@http.gcc.gnu.org/bugzilla/>
2011-10-19 21:50 ` paolo.carlini at oracle dot com
2011-10-21 18:21 ` paolo at gcc dot gnu.org
@ 2011-10-21 18:21 ` paolo.carlini at oracle dot com
2 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-10-21 18:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31423
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC|gcc-bugs at gcc dot gnu.org |
Resolution| |FIXED
Target Milestone|--- |4.7.0
--- Comment #11 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-10-21 18:20:07 UTC ---
Fixed for 4.7.0.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/31423] Improve upon "invalid use of member (did you forget the '&' ?)"
[not found] <bug-31423-4@http.gcc.gnu.org/bugzilla/>
2011-10-19 21:50 ` paolo.carlini at oracle dot com
@ 2011-10-21 18:21 ` paolo at gcc dot gnu.org
2011-10-21 18:21 ` paolo.carlini at oracle dot com
2 siblings, 0 replies; 12+ messages in thread
From: paolo at gcc dot gnu.org @ 2011-10-21 18:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31423
--- Comment #10 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2011-10-21 18:19:00 UTC ---
Author: paolo
Date: Fri Oct 21 18:18:55 2011
New Revision: 180309
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=180309
Log:
/cp
2011-10-21 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/31423
* typeck2.c (cxx_incomplete_type_diagnostic): Improve error message
for invalid use of member function.
/testsuite
2011-10-21 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/31423
* g++.dg/parse/error43.C: New.
* g++.dg/parse/error44.C: Likewise.
Added:
trunk/gcc/testsuite/g++.dg/parse/error43.C
trunk/gcc/testsuite/g++.dg/parse/error44.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/typeck2.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/31423] Improve upon "invalid use of member (did you forget the '&' ?)"
[not found] <bug-31423-4@http.gcc.gnu.org/bugzilla/>
@ 2011-10-19 21:50 ` paolo.carlini at oracle dot com
2011-10-21 18:21 ` paolo at gcc dot gnu.org
2011-10-21 18:21 ` paolo.carlini at oracle dot com
2 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-10-19 21:50 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31423
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ian at airs dot com
--- Comment #9 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-10-19 21:49:18 UTC ---
*** Bug 48630 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2011-10-21 18:21 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-01 22:01 [Bug c++/31423] New: Improve upon "invalid use of member (did you forget the '&' ?)" gerald at pfeifer dot com
2007-04-02 16:09 ` [Bug c++/31423] " bangerth at dealii dot org
2009-08-05 15:33 ` manu at gcc dot gnu dot org
2009-08-05 16:41 ` jwakely dot gcc at gmail dot com
2009-08-05 17:55 ` bangerth at gmail dot com
2009-08-05 17:57 ` bangerth at gmail dot com
2009-08-05 18:19 ` manu at gcc dot gnu dot org
2009-08-05 18:47 ` bangerth at gmail dot com
2009-08-06 9:51 ` jwakely dot gcc at gmail dot com
[not found] <bug-31423-4@http.gcc.gnu.org/bugzilla/>
2011-10-19 21:50 ` paolo.carlini at oracle dot com
2011-10-21 18:21 ` paolo at gcc dot gnu.org
2011-10-21 18:21 ` 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).