public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53281] New: poor error message for calling a non-const method from a const object
@ 2012-05-08 13:27 rui.maciel at gmail dot com
2012-05-08 13:34 ` [Bug c++/53281] " rui.maciel at gmail dot com
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: rui.maciel at gmail dot com @ 2012-05-08 13:27 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53281
Bug #: 53281
Summary: poor error message for calling a non-const method from
a const object
Classification: Unclassified
Product: gcc
Version: 4.6.3
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: rui.maciel@gmail.com
Consider the following code:
<code>
class Foo {
void bar1() {}
void bar2(Foo const &foo) {
foo.bar1();
}
};
int main()
{
return 0;
}
</code>
When this code is compiled with g++, the following error message is shown:
<message>
main.c++: In member function ‘const void Foo::bar2(const Foo&)’:
main.c++:4:26: error: passing ‘const Foo’ as ‘this’ argument of ‘const void
Foo::bar1()’ discards qualifiers [-fpermissive]
</message>
The error message is technically correct. Yet, it is too cryptic and a bit
unhelpful, to the point it may be considered that the point of this error
message is entirely missed.
As an alternative, it would be nice if g++ displayed an error message which
would actually be straight-forward and provided a clear description of the
problem at hand, such as "trying to call a non-const method from a const
object".
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/53281] poor error message for calling a non-const method from a const object
2012-05-08 13:27 [Bug c++/53281] New: poor error message for calling a non-const method from a const object rui.maciel at gmail dot com
@ 2012-05-08 13:34 ` rui.maciel at gmail dot com
2012-05-09 16:00 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rui.maciel at gmail dot com @ 2012-05-08 13:34 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53281
--- Comment #1 from Rui Maciel <rui.maciel at gmail dot com> 2012-05-08 13:27:24 UTC ---
The same suggestion applies to the cases where a non-const method is called
from a const method, such as in the example below:
<code>
class Foo {
void bar1() {}
void bar2() const {
bar1();
}
};
int main()
{
return 0;
}
</code>
The same error message is returned:
<message>
main.c++: In member function ‘void Foo::bar2() const’:
main.c++:4:22: error: passing ‘const Foo’ as ‘this’ argument of ‘void
Foo::bar1()’ discards qualifiers [-fpermissive]
</message>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/53281] poor error message for calling a non-const method from a const object
2012-05-08 13:27 [Bug c++/53281] New: poor error message for calling a non-const method from a const object rui.maciel at gmail dot com
2012-05-08 13:34 ` [Bug c++/53281] " rui.maciel at gmail dot com
@ 2012-05-09 16:00 ` redi at gcc dot gnu.org
2020-03-12 11:58 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2012-05-09 16:00 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53281
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Status|UNCONFIRMED |NEW
Last reconfirmed| |2012-05-09
Ever Confirmed|0 |1
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-05-09 15:59:09 UTC ---
confirmed (but any change to the diagnostic should not mention the word
"method" because C++ has member functions not methods)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/53281] poor error message for calling a non-const method from a const object
2012-05-08 13:27 [Bug c++/53281] New: poor error message for calling a non-const method from a const object rui.maciel at gmail dot com
2012-05-08 13:34 ` [Bug c++/53281] " rui.maciel at gmail dot com
2012-05-09 16:00 ` redi at gcc dot gnu.org
@ 2020-03-12 11:58 ` jakub at gcc dot gnu.org
2020-03-12 12:28 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-03-12 11:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53281
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|9.3 |9.4
--- Comment #13 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 9.3.0 has been released, adjusting target milestone.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/53281] poor error message for calling a non-const method from a const object
2012-05-08 13:27 [Bug c++/53281] New: poor error message for calling a non-const method from a const object rui.maciel at gmail dot com
` (2 preceding siblings ...)
2020-03-12 11:58 ` jakub at gcc dot gnu.org
@ 2020-03-12 12:28 ` redi at gcc dot gnu.org
2021-04-19 10:29 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-12 12:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53281
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|9.4 |11.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/53281] poor error message for calling a non-const method from a const object
2012-05-08 13:27 [Bug c++/53281] New: poor error message for calling a non-const method from a const object rui.maciel at gmail dot com
` (3 preceding siblings ...)
2020-03-12 12:28 ` redi at gcc dot gnu.org
@ 2021-04-19 10:29 ` redi at gcc dot gnu.org
2022-05-24 23:30 ` barry.revzin at gmail dot com
2022-05-26 11:09 ` redi at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2021-04-19 10:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53281
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |NEW
Target Milestone|11.0 |---
Assignee|redi at gcc dot gnu.org |unassigned at gcc dot gnu.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/53281] poor error message for calling a non-const method from a const object
2012-05-08 13:27 [Bug c++/53281] New: poor error message for calling a non-const method from a const object rui.maciel at gmail dot com
` (4 preceding siblings ...)
2021-04-19 10:29 ` redi at gcc dot gnu.org
@ 2022-05-24 23:30 ` barry.revzin at gmail dot com
2022-05-26 11:09 ` redi at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: barry.revzin at gmail dot com @ 2022-05-24 23:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53281
Barry Revzin <barry.revzin at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |barry.revzin at gmail dot com
--- Comment #14 from Barry Revzin <barry.revzin at gmail dot com> ---
Following up on this (and a lot of the ideas presented here are I think better
than "passing [...] discards qualifiers")...
This:
struct B {
void f();
};
struct D : B {
void const_f() const {
f();
}
};
gives me that same error:
<source>:8:10: error: passing 'const D' as 'this' argument discards qualifiers
[-fpermissive]
8 | f();
| ~^~
<source>:2:10: note: in call to 'void B::f()'
2 | void f();
| ^
But this slight difference (D is now a template, though B is a non-dependent
base):
struct B {
void f();
};
template <class T>
struct D : B {
void const_f() const {
f();
}
};
instead emits:
<source>:8:10: error: cannot convert 'const D<T>*' to 'B*'
8 | f();
| ~^~
<source>:2:10: note: initializing argument 'this' of 'void B::f()'
2 | void f();
| ^
Which is... technically correct, that is the problem, but now that I'm used to
seeing the "discards qualifiers" error, this one really threw me for a loop.
It'd be nice at the very least if these two examples gave the same error
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/53281] poor error message for calling a non-const method from a const object
2012-05-08 13:27 [Bug c++/53281] New: poor error message for calling a non-const method from a const object rui.maciel at gmail dot com
` (5 preceding siblings ...)
2022-05-24 23:30 ` barry.revzin at gmail dot com
@ 2022-05-26 11:09 ` redi at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-05-26 11:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53281
--- Comment #15 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Created attachment 53035
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53035&action=edit
Incomplete patch
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-05-26 11:09 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-08 13:27 [Bug c++/53281] New: poor error message for calling a non-const method from a const object rui.maciel at gmail dot com
2012-05-08 13:34 ` [Bug c++/53281] " rui.maciel at gmail dot com
2012-05-09 16:00 ` redi at gcc dot gnu.org
2020-03-12 11:58 ` jakub at gcc dot gnu.org
2020-03-12 12:28 ` redi at gcc dot gnu.org
2021-04-19 10:29 ` redi at gcc dot gnu.org
2022-05-24 23:30 ` barry.revzin at gmail dot com
2022-05-26 11:09 ` redi at gcc dot gnu.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).