1 // { dg-options "-fdiagnostics-show-caret" }
6 int get_color () const { return m_color; }
7 int get_shape () const { return m_shape; }
16 int test_access_t1_color (t1 &ref)
18 return ref.m_color; // { dg-error ".int t1::m_color. is private within this context" }
19 /* { dg-begin-multiline-output "" }
22 { dg-end-multiline-output "" } */
24 // { dg-message "declared private here" "" { target *-*-* } 10 }
25 /* { dg-begin-multiline-output "" }
28 { dg-end-multiline-output "" } */
30 // { dg-message "field .int t1::m_color. can be accessed via .int t1::get_color\\(\\) const." "" { target *-*-* } .-12 }
31 /* { dg-begin-multiline-output "" }
35 { dg-end-multiline-output "" } */
38 int test_access_const_t1_color (const t1 &ref)
40 return ref.m_color; // { dg-error ".int t1::m_color. is private within this context" }
41 /* { dg-begin-multiline-output "" }
44 { dg-end-multiline-output "" } */
47 /* { dg-begin-multiline-output "" }
50 { dg-end-multiline-output "" } */
52 // { dg-message "field .int t1::m_color. can be accessed via .int t1::get_color\\(\\) const." "" { target *-*-* } .-12 }
53 /* { dg-begin-multiline-output "" }
57 { dg-end-multiline-output "" } */
60 int test_access_t1_shape (t1 &ref)
62 return ref.m_shape; // { dg-error ".int t1::m_shape. is protected within this context" }
63 /* { dg-begin-multiline-output "" }
66 { dg-end-multiline-output "" } */
68 // { dg-message "declared protected here" "" { target *-*-* } 13 }
69 /* { dg-begin-multiline-output "" }
72 { dg-end-multiline-output "" } */
74 // { dg-message "field .int t1::m_shape. can be accessed via .int t1::get_shape\\(\\) const." "" { target *-*-* } .-12 }
75 /* { dg-begin-multiline-output "" }
79 { dg-end-multiline-output "" } */
82 int test_deref_t1_color (t1 *ptr)
84 return ptr->m_color; // { dg-error ".int t1::m_color. is private within this context" }
85 /* { dg-begin-multiline-output "" }
88 { dg-end-multiline-output "" } */
91 /* { dg-begin-multiline-output "" }
94 { dg-end-multiline-output "" } */
96 // { dg-message "field .int t1::m_color. can be accessed via .int t1::get_color\\(\\) const." "" { target *-*-* } .-12 }
97 /* { dg-begin-multiline-output "" }
101 { dg-end-multiline-output "" } */
104 int test_deref_const_t1_color (const t1 *ptr)
106 return ptr->m_color; // { dg-error ".int t1::m_color. is private within this context" }
107 /* { dg-begin-multiline-output "" }
110 { dg-end-multiline-output "" } */
113 /* { dg-begin-multiline-output "" }
116 { dg-end-multiline-output "" } */
118 // { dg-message "field .int t1::m_color. can be accessed via .int t1::get_color\\(\\) const." "" { target *-*-* } .-12 }
119 /* { dg-begin-multiline-output "" }
123 { dg-end-multiline-output "" } */
126 int test_deref_t1_shape (t1 *ptr)
128 return ptr->m_shape; // { dg-error ".int t1::m_shape. is protected within this context" }
129 /* { dg-begin-multiline-output "" }
132 { dg-end-multiline-output "" } */
135 /* { dg-begin-multiline-output "" }
138 { dg-end-multiline-output "" } */
140 // { dg-message "field .int t1::m_shape. can be accessed via .int t1::get_shape\\(\\) const." "" { target *-*-* } .-12 }
141 /* { dg-begin-multiline-output "" }
145 { dg-end-multiline-output "" } */
148 /* Example of public inheritance. */
154 int test_deref_t2_color (t2 *ptr)
156 return ptr->m_color; // { dg-error ".int t1::m_color. is private within this context" }
157 /* { dg-begin-multiline-output "" }
160 { dg-end-multiline-output "" } */
163 /* { dg-begin-multiline-output "" }
166 { dg-end-multiline-output "" } */
168 // { dg-message "field .int t1::m_color. can be accessed via .int t1::get_color\\(\\) const." "" { target *-*-* } .-12 }
169 /* { dg-begin-multiline-output "" }
173 { dg-end-multiline-output "" } */
176 /* Example of private inheritance. */
178 class t3 : private t1
182 int test_deref_t3_color (t3 *ptr)
184 return ptr->m_color; // { dg-error ".int t1::m_color. is private within this context" }
185 /* { dg-begin-multiline-output "" }
188 { dg-end-multiline-output "" } */
190 /* { dg-begin-multiline-output "" }
193 { dg-end-multiline-output "" } */
195 /* We shouldn't provide a fix-it hint for this case due to the
196 private inheritance. */
199 /* Example of non-public "accessor". */
204 int get_field () { return m_field; }
207 int test_deref_t4_field (t4 *ptr)
209 return ptr->m_field; // { dg-error ".int t4::m_field. is private within this context" }
210 /* { dg-begin-multiline-output "" }
213 { dg-end-multiline-output "" } */
215 /* { dg-begin-multiline-output "" }
218 { dg-end-multiline-output "" } */
220 /* We shouldn't provide a fix-it hint for this case, as the accessor is