Debian Codegraph @

gcc/testsuite/g++.dg/torture/accessor-fixits-9-xobj.C

raw
1 // PR c++/84993
2 // { dg-options "-fdiagnostics-show-caret -std=c++23" }
3
4 /* Misspelling (by omitting a leading "m_") of a private member for which
5 there's a public accessor.
6
7 We expect a fix-it hint suggesting the accessor. */
8
9 class t1
10 {
11 public:
12 int get_ratio (this const t1& x) { return x.m_ratio; }
13
14 private:
15 int m_ratio;
16 };
17
18 int test (t1 *ptr_1)
19 {
20 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&\\)'\\)" }
21 /* { dg-begin-multiline-output "" }
22 return ptr_1->ratio;
23 ^~~~~
24 get_ratio()
25 { dg-end-multiline-output "" } */
26 }
27
28
29 /* Misspelling of a private member for which there's a public accessor.
30
31 We expect a fix-it hint suggesting the accessor. */
32
33 class t2
34 {
35 public:
36 int get_color (this const t2& x) { return x.m_color; }
37
38 private:
39 int m_color;
40 };
41
42 int test (t2 *ptr_2)
43 {
44 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&\\)'\\)" }
45 /* { dg-begin-multiline-output "" }
46 return ptr_2->m_colour;
47 ^~~~~~~~
48 get_color()
49 { dg-end-multiline-output "" } */
50 }
51
52
53 /* Misspelling of a private member via a subclass pointer, for which there's
54 a public accessor in the base class.
55
56 We expect a fix-it hint suggesting the accessor. */
57
58 class t3 : public t2 {};
59
60 int test (t3 *ptr_3)
61 {
62 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&\\)'\\)" }
63 /* { dg-begin-multiline-output "" }
64 return ptr_3->m_colour;
65 ^~~~~~~~
66 get_color()
67 { dg-end-multiline-output "" } */
68 }
69
70
71 /* Misspelling of a protected member, for which there's isn't a public
72 accessor.
73
74 We expect no fix-it hint; instead a message identifying where the
75 data member was declared. */
76
77 class t4
78 {
79 protected:
80 int m_color; // { dg-message "declared protected here" }
81 };
82
83 int test (t4 *ptr_4)
84 {
85 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\\)" }
86 /* { dg-begin-multiline-output "" }
87 return ptr_4->m_colour;
88 ^~~~~~~~
89 { dg-end-multiline-output "" } */
90 /* { dg-begin-multiline-output "" }
91 int m_color;
92 ^~~~~~~
93 { dg-end-multiline-output "" } */
94 }
95
96
97 /* Misspelling of a private member, for which the accessor is also private.
98
99 We expect no fix-it hint; instead a message identifying where the
100 data member was declared. */
101
102 class t5
103 {
104 int get_color (this const t5& x) { return x.m_color; }
105 int m_color; // { dg-message "declared private here" }
106 };
107
108 int test (t5 *ptr_5)
109 {
110 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\\)" }
111 /* { dg-begin-multiline-output "" }
112 return ptr_5->m_colour;
113 ^~~~~~~~
114 { dg-end-multiline-output "" } */
115 /* { dg-begin-multiline-output "" }
116 int m_color;
117 ^~~~~~~
118 { dg-end-multiline-output "" } */
119 }