forked from ruyisdk/riscv-gcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
c++: adjust accessor fixits for explicit object parm
In a couple of places in the xobj patch I noticed that is_this_parameter probably wanted to change to is_object_parameter; this implements that and does the additional adjustments needed to make the accessor fixits handle xobj parms. gcc/cp/ChangeLog: * semantics.cc (is_object_parameter): New. * cp-tree.h (is_object_parameter): Declare. * call.cc (maybe_warn_class_memaccess): Use it. * search.cc (field_access_p): Use it. (class_of_object_parm): New. (field_accessor_p): Adjust for explicit object parms. gcc/testsuite/ChangeLog: * g++.dg/torture/accessor-fixits-9-xobj.C: New test.
- Loading branch information
1 parent
283f10d
commit ba36d15
Showing
5 changed files
with
149 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// PR c++/84993 | ||
// { dg-options "-fdiagnostics-show-caret -std=c++23" } | ||
|
||
/* Misspelling (by omitting a leading "m_") of a private member for which | ||
there's a public accessor. | ||
|
||
We expect a fix-it hint suggesting the accessor. */ | ||
|
||
class t1 | ||
{ | ||
public: | ||
int get_ratio (this const t1& x) { return x.m_ratio; } | ||
|
||
private: | ||
int m_ratio; | ||
}; | ||
|
||
int test (t1 *ptr_1) | ||
{ | ||
return ptr_1->ratio; // { dg-error "'class t1' has no member named 'ratio'; did you mean 'int t1::m_ratio'\\? \\(accessible via 'int t1::get_ratio\\(this const t1&\\)'\\)" } | ||
/* { dg-begin-multiline-output "" } | ||
return ptr_1->ratio; | ||
^~~~~ | ||
get_ratio() | ||
{ dg-end-multiline-output "" } */ | ||
} | ||
|
||
|
||
/* Misspelling of a private member for which there's a public accessor. | ||
|
||
We expect a fix-it hint suggesting the accessor. */ | ||
|
||
class t2 | ||
{ | ||
public: | ||
int get_color (this const t2& x) { return x.m_color; } | ||
|
||
private: | ||
int m_color; | ||
}; | ||
|
||
int test (t2 *ptr_2) | ||
{ | ||
return ptr_2->m_colour; // { dg-error "'class t2' has no member named 'm_colour'; did you mean 'int t2::m_color'\\? \\(accessible via 'int t2::get_color\\(this const t2&\\)'\\)" } | ||
/* { dg-begin-multiline-output "" } | ||
return ptr_2->m_colour; | ||
^~~~~~~~ | ||
get_color() | ||
{ dg-end-multiline-output "" } */ | ||
} | ||
|
||
|
||
/* Misspelling of a private member via a subclass pointer, for which there's | ||
a public accessor in the base class. | ||
|
||
We expect a fix-it hint suggesting the accessor. */ | ||
|
||
class t3 : public t2 {}; | ||
|
||
int test (t3 *ptr_3) | ||
{ | ||
return ptr_3->m_colour; // { dg-error "'class t3' has no member named 'm_colour'; did you mean 'int t2::m_color'\\? \\(accessible via 'int t2::get_color\\(this const t2&\\)'\\)" } | ||
/* { dg-begin-multiline-output "" } | ||
return ptr_3->m_colour; | ||
^~~~~~~~ | ||
get_color() | ||
{ dg-end-multiline-output "" } */ | ||
} | ||
|
||
|
||
/* Misspelling of a protected member, for which there's isn't a public | ||
accessor. | ||
|
||
We expect no fix-it hint; instead a message identifying where the | ||
data member was declared. */ | ||
|
||
class t4 | ||
{ | ||
protected: | ||
int m_color; // { dg-message "declared protected here" } | ||
}; | ||
|
||
int test (t4 *ptr_4) | ||
{ | ||
return ptr_4->m_colour; // { dg-error "'class t4' has no member named 'm_colour'; did you mean 'int t4::m_color'\\? \\(not accessible from this context\\)" } | ||
/* { dg-begin-multiline-output "" } | ||
return ptr_4->m_colour; | ||
^~~~~~~~ | ||
{ dg-end-multiline-output "" } */ | ||
/* { dg-begin-multiline-output "" } | ||
int m_color; | ||
^~~~~~~ | ||
{ dg-end-multiline-output "" } */ | ||
} | ||
|
||
|
||
/* Misspelling of a private member, for which the accessor is also private. | ||
|
||
We expect no fix-it hint; instead a message identifying where the | ||
data member was declared. */ | ||
|
||
class t5 | ||
{ | ||
int get_color (this const t5& x) { return x.m_color; } | ||
int m_color; // { dg-message "declared private here" } | ||
}; | ||
|
||
int test (t5 *ptr_5) | ||
{ | ||
return ptr_5->m_colour; // { dg-error "'class t5' has no member named 'm_colour'; did you mean 'int t5::m_color'\\? \\(not accessible from this context\\)" } | ||
/* { dg-begin-multiline-output "" } | ||
return ptr_5->m_colour; | ||
^~~~~~~~ | ||
{ dg-end-multiline-output "" } */ | ||
/* { dg-begin-multiline-output "" } | ||
int m_color; | ||
^~~~~~~ | ||
{ dg-end-multiline-output "" } */ | ||
} |