Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/torture/accessor-fixits-1.C @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 // { dg-options "-fdiagnostics-show-caret" } | |
2 | |
3 class t1 | |
4 { | |
5 public: | |
6 int get_color () const { return m_color; } | |
7 int get_shape () const { return m_shape; } | |
8 | |
9 private: | |
10 int m_color; | |
11 | |
12 protected: | |
13 int m_shape; | |
14 }; | |
15 | |
16 int test_access_t1_color (t1 &ref) | |
17 { | |
18 return ref.m_color; // { dg-error ".int t1::m_color. is private within this context" } | |
19 /* { dg-begin-multiline-output "" } | |
20 return ref.m_color; | |
21 ^~~~~~~ | |
22 { dg-end-multiline-output "" } */ | |
23 | |
24 // { dg-message "declared private here" "" { target *-*-* } 10 } | |
25 /* { dg-begin-multiline-output "" } | |
26 int m_color; | |
27 ^~~~~~~ | |
28 { dg-end-multiline-output "" } */ | |
29 | |
30 // { dg-message "field .int t1::m_color. can be accessed via .int t1::get_color\\(\\) const." "" { target *-*-* } .-12 } | |
31 /* { dg-begin-multiline-output "" } | |
32 return ref.m_color; | |
33 ^~~~~~~ | |
34 get_color() | |
35 { dg-end-multiline-output "" } */ | |
36 } | |
37 | |
38 int test_access_const_t1_color (const t1 &ref) | |
39 { | |
40 return ref.m_color; // { dg-error ".int t1::m_color. is private within this context" } | |
41 /* { dg-begin-multiline-output "" } | |
42 return ref.m_color; | |
43 ^~~~~~~ | |
44 { dg-end-multiline-output "" } */ | |
45 | |
46 | |
47 /* { dg-begin-multiline-output "" } | |
48 int m_color; | |
49 ^~~~~~~ | |
50 { dg-end-multiline-output "" } */ | |
51 | |
52 // { dg-message "field .int t1::m_color. can be accessed via .int t1::get_color\\(\\) const." "" { target *-*-* } .-12 } | |
53 /* { dg-begin-multiline-output "" } | |
54 return ref.m_color; | |
55 ^~~~~~~ | |
56 get_color() | |
57 { dg-end-multiline-output "" } */ | |
58 } | |
59 | |
60 int test_access_t1_shape (t1 &ref) | |
61 { | |
62 return ref.m_shape; // { dg-error ".int t1::m_shape. is protected within this context" } | |
63 /* { dg-begin-multiline-output "" } | |
64 return ref.m_shape; | |
65 ^~~~~~~ | |
66 { dg-end-multiline-output "" } */ | |
67 | |
68 // { dg-message "declared protected here" "" { target *-*-* } 13 } | |
69 /* { dg-begin-multiline-output "" } | |
70 int m_shape; | |
71 ^~~~~~~ | |
72 { dg-end-multiline-output "" } */ | |
73 | |
74 // { dg-message "field .int t1::m_shape. can be accessed via .int t1::get_shape\\(\\) const." "" { target *-*-* } .-12 } | |
75 /* { dg-begin-multiline-output "" } | |
76 return ref.m_shape; | |
77 ^~~~~~~ | |
78 get_shape() | |
79 { dg-end-multiline-output "" } */ | |
80 } | |
81 | |
82 int test_deref_t1_color (t1 *ptr) | |
83 { | |
84 return ptr->m_color; // { dg-error ".int t1::m_color. is private within this context" } | |
85 /* { dg-begin-multiline-output "" } | |
86 return ptr->m_color; | |
87 ^~~~~~~ | |
88 { dg-end-multiline-output "" } */ | |
89 | |
90 | |
91 /* { dg-begin-multiline-output "" } | |
92 int m_color; | |
93 ^~~~~~~ | |
94 { dg-end-multiline-output "" } */ | |
95 | |
96 // { dg-message "field .int t1::m_color. can be accessed via .int t1::get_color\\(\\) const." "" { target *-*-* } .-12 } | |
97 /* { dg-begin-multiline-output "" } | |
98 return ptr->m_color; | |
99 ^~~~~~~ | |
100 get_color() | |
101 { dg-end-multiline-output "" } */ | |
102 } | |
103 | |
104 int test_deref_const_t1_color (const t1 *ptr) | |
105 { | |
106 return ptr->m_color; // { dg-error ".int t1::m_color. is private within this context" } | |
107 /* { dg-begin-multiline-output "" } | |
108 return ptr->m_color; | |
109 ^~~~~~~ | |
110 { dg-end-multiline-output "" } */ | |
111 | |
112 | |
113 /* { dg-begin-multiline-output "" } | |
114 int m_color; | |
115 ^~~~~~~ | |
116 { dg-end-multiline-output "" } */ | |
117 | |
118 // { dg-message "field .int t1::m_color. can be accessed via .int t1::get_color\\(\\) const." "" { target *-*-* } .-12 } | |
119 /* { dg-begin-multiline-output "" } | |
120 return ptr->m_color; | |
121 ^~~~~~~ | |
122 get_color() | |
123 { dg-end-multiline-output "" } */ | |
124 } | |
125 | |
126 int test_deref_t1_shape (t1 *ptr) | |
127 { | |
128 return ptr->m_shape; // { dg-error ".int t1::m_shape. is protected within this context" } | |
129 /* { dg-begin-multiline-output "" } | |
130 return ptr->m_shape; | |
131 ^~~~~~~ | |
132 { dg-end-multiline-output "" } */ | |
133 | |
134 | |
135 /* { dg-begin-multiline-output "" } | |
136 int m_shape; | |
137 ^~~~~~~ | |
138 { dg-end-multiline-output "" } */ | |
139 | |
140 // { dg-message "field .int t1::m_shape. can be accessed via .int t1::get_shape\\(\\) const." "" { target *-*-* } .-12 } | |
141 /* { dg-begin-multiline-output "" } | |
142 return ptr->m_shape; | |
143 ^~~~~~~ | |
144 get_shape() | |
145 { dg-end-multiline-output "" } */ | |
146 } | |
147 | |
148 /* Example of public inheritance. */ | |
149 | |
150 class t2 : public t1 | |
151 { | |
152 }; | |
153 | |
154 int test_deref_t2_color (t2 *ptr) | |
155 { | |
156 return ptr->m_color; // { dg-error ".int t1::m_color. is private within this context" } | |
157 /* { dg-begin-multiline-output "" } | |
158 return ptr->m_color; | |
159 ^~~~~~~ | |
160 { dg-end-multiline-output "" } */ | |
161 | |
162 | |
163 /* { dg-begin-multiline-output "" } | |
164 int m_color; | |
165 ^~~~~~~ | |
166 { dg-end-multiline-output "" } */ | |
167 | |
168 // { dg-message "field .int t1::m_color. can be accessed via .int t1::get_color\\(\\) const." "" { target *-*-* } .-12 } | |
169 /* { dg-begin-multiline-output "" } | |
170 return ptr->m_color; | |
171 ^~~~~~~ | |
172 get_color() | |
173 { dg-end-multiline-output "" } */ | |
174 } | |
175 | |
176 /* Example of private inheritance. */ | |
177 | |
178 class t3 : private t1 | |
179 { | |
180 }; | |
181 | |
182 int test_deref_t3_color (t3 *ptr) | |
183 { | |
184 return ptr->m_color; // { dg-error ".int t1::m_color. is private within this context" } | |
185 /* { dg-begin-multiline-output "" } | |
186 return ptr->m_color; | |
187 ^~~~~~~ | |
188 { dg-end-multiline-output "" } */ | |
189 | |
190 /* { dg-begin-multiline-output "" } | |
191 int m_color; | |
192 ^~~~~~~ | |
193 { dg-end-multiline-output "" } */ | |
194 | |
195 /* We shouldn't provide a fix-it hint for this case due to the | |
196 private inheritance. */ | |
197 } | |
198 | |
199 /* Example of non-public "accessor". */ | |
200 | |
201 class t4 | |
202 { | |
203 int m_field; | |
204 int get_field () { return m_field; } | |
205 }; | |
206 | |
207 int test_deref_t4_field (t4 *ptr) | |
208 { | |
209 return ptr->m_field; // { dg-error ".int t4::m_field. is private within this context" } | |
210 /* { dg-begin-multiline-output "" } | |
211 return ptr->m_field; | |
212 ^~~~~~~ | |
213 { dg-end-multiline-output "" } */ | |
214 | |
215 /* { dg-begin-multiline-output "" } | |
216 int m_field; | |
217 ^~~~~~~ | |
218 { dg-end-multiline-output "" } */ | |
219 | |
220 /* We shouldn't provide a fix-it hint for this case, as the accessor is | |
221 itself private. */ | |
222 } |