public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105703] New: Add fix-it for missing nested-name-specifier on non-member function using 'this'
@ 2022-05-23 11:10 redi at gcc dot gnu.org
2023-05-19 4:48 ` [Bug c++/105703] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2022-05-23 11:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105703
Bug ID: 105703
Summary: Add fix-it for missing nested-name-specifier on
non-member function using 'this'
Product: gcc
Version: 12.1.1
Status: UNCONFIRMED
Keywords: diagnostic
Severity: enhancement
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
This is a generalization of the suggestion in PR 105702.
Given:
struct A {
void f();
};
void f() { (void) *this; }
We correctly diagnose the use of 'this'
ool.C:5:20: error: invalid use of 'this' outside of a non-static member
function
void f() { (void) *this; }
^
However, the use of 'this' is not the problem. The user intended to define
A::f() here but missed the A:: qualification (maybe by moving an in-class
definition to be out-of-class, and forgetting to add the A:: to it).
If we give this error for use of 'this' in a non-member function with signature
R(Args...), we should look to see if any class previously defined has a
non-defining declaration for a member function with that same signature. If
yes, assume the non-member function was meant to be qualified with the class
name.
So we would print:
ool.C:5:20: error: invalid use of 'this' outside of a non-static member
function
void f() { (void) *this; }
^
ool.C:5:6: note: did you mean to define a member of A?
5 | void f() { (void) *this; }
| ^
| A::
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/105703] Add fix-it for missing nested-name-specifier on non-member function using 'this'
2022-05-23 11:10 [Bug c++/105703] New: Add fix-it for missing nested-name-specifier on non-member function using 'this' redi at gcc dot gnu.org
@ 2023-05-19 4:48 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-19 4:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105703
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2023-05-19
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-05-19 4:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-23 11:10 [Bug c++/105703] New: Add fix-it for missing nested-name-specifier on non-member function using 'this' redi at gcc dot gnu.org
2023-05-19 4:48 ` [Bug c++/105703] " pinskia 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).