Debian Codegraph @

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

raw
1 // { dg-options "-fdiagnostics-show-caret" }
2
3 class t1
4 {
5 public:
6 int& get_color () { return m_color; }
7 int& get_shape () { return m_shape; }
8
9 private:
10 int m_color; // { dg-line color_decl }
11 int m_shape; // { dg-line shape_decl }
12 };
13
14 int test_const_ptr (const t1 *ptr)
15 {
16 return ptr->m_color; // { dg-error ".int t1::m_color. is private within this context" }
17 /* { dg-begin-multiline-output "" }
18 return ptr->m_color;
19 ^~~~~~~
20 { dg-end-multiline-output "" } */
21
22 // { dg-message "declared private here" "" { target *-*-* } color_decl }
23 /* { dg-begin-multiline-output "" }
24 int m_color;
25 ^~~~~~~
26 { dg-end-multiline-output "" } */
27
28 /* We shouldn't issue a suggestion: the accessor is non-const, and we
29 only have a const ptr. */
30 }
31
32 int test_const_reference (const t1 &ref)
33 {
34 return ref.m_shape; // { dg-error ".int t1::m_shape. is private within this context" }
35 /* { dg-begin-multiline-output "" }
36 return ref.m_shape;
37 ^~~~~~~
38 { dg-end-multiline-output "" } */
39
40 // { dg-message "declared private here" "" { target *-*-* } shape_decl }
41 /* { dg-begin-multiline-output "" }
42 int m_shape;
43 ^~~~~~~
44 { dg-end-multiline-output "" } */
45
46 /* We shouldn't issue a suggestion: the accessor is non-const, and we
47 only have a const ptr. */
48 }