111
|
1 // { dg-options "-fdiagnostics-show-caret" }
|
|
2
|
|
3 /* Test of accessors that return references. */
|
|
4
|
|
5 class t1
|
|
6 {
|
|
7 public:
|
|
8 int& get_color () { return m_color; }
|
|
9 int& get_shape () { return m_shape; }
|
|
10
|
|
11 private:
|
|
12 int m_color;
|
|
13
|
|
14 protected:
|
|
15 int m_shape;
|
|
16 };
|
|
17
|
|
18 int test_access_t1_color (t1 &ref)
|
|
19 {
|
|
20 return ref.m_color; // { dg-error ".int t1::m_color. is private within this context" }
|
|
21 /* { dg-begin-multiline-output "" }
|
|
22 return ref.m_color;
|
|
23 ^~~~~~~
|
|
24 { dg-end-multiline-output "" } */
|
|
25
|
|
26 // { dg-message "declared private here" "" { target *-*-* } 12 }
|
|
27 /* { dg-begin-multiline-output "" }
|
|
28 int m_color;
|
|
29 ^~~~~~~
|
|
30 { dg-end-multiline-output "" } */
|
|
31
|
|
32 // { dg-message "field .int t1::m_color. can be accessed via .int& t1::get_color\\(\\)." "" { target *-*-* } .-12 }
|
|
33 /* { dg-begin-multiline-output "" }
|
|
34 return ref.m_color;
|
|
35 ^~~~~~~
|
|
36 get_color()
|
|
37 { dg-end-multiline-output "" } */
|
|
38 }
|
|
39
|
|
40 int test_access_t1_shape (t1 &ref)
|
|
41 {
|
|
42 return ref.m_shape; // { dg-error ".int t1::m_shape. is protected within this context" }
|
|
43 /* { dg-begin-multiline-output "" }
|
|
44 return ref.m_shape;
|
|
45 ^~~~~~~
|
|
46 { dg-end-multiline-output "" } */
|
|
47
|
|
48 // { dg-message "declared protected here" "" { target *-*-* } 15 }
|
|
49 /* { dg-begin-multiline-output "" }
|
|
50 int m_shape;
|
|
51 ^~~~~~~
|
|
52 { dg-end-multiline-output "" } */
|
|
53
|
|
54 // { dg-message "field .int t1::m_shape. can be accessed via .int& t1::get_shape\\(\\)." "" { target *-*-* } .-12 }
|
|
55 /* { dg-begin-multiline-output "" }
|
|
56 return ref.m_shape;
|
|
57 ^~~~~~~
|
|
58 get_shape()
|
|
59 { dg-end-multiline-output "" } */
|
|
60 }
|
|
61
|
|
62 int test_deref_t1_color (t1 *ptr)
|
|
63 {
|
|
64 return ptr->m_color; // { dg-error ".int t1::m_color. is private within this context" }
|
|
65 /* { dg-begin-multiline-output "" }
|
|
66 return ptr->m_color;
|
|
67 ^~~~~~~
|
|
68 { dg-end-multiline-output "" } */
|
|
69
|
|
70
|
|
71 /* { dg-begin-multiline-output "" }
|
|
72 int m_color;
|
|
73 ^~~~~~~
|
|
74 { dg-end-multiline-output "" } */
|
|
75
|
|
76 // { dg-message "field .int t1::m_color. can be accessed via .int& t1::get_color\\(\\)." "" { target *-*-* } .-12 }
|
|
77 /* { dg-begin-multiline-output "" }
|
|
78 return ptr->m_color;
|
|
79 ^~~~~~~
|
|
80 get_color()
|
|
81 { dg-end-multiline-output "" } */
|
|
82 }
|
|
83
|
|
84 int test_deref_t1_shape (t1 *ptr)
|
|
85 {
|
|
86 return ptr->m_shape; // { dg-error ".int t1::m_shape. is protected within this context" }
|
|
87 /* { dg-begin-multiline-output "" }
|
|
88 return ptr->m_shape;
|
|
89 ^~~~~~~
|
|
90 { dg-end-multiline-output "" } */
|
|
91
|
|
92
|
|
93 /* { dg-begin-multiline-output "" }
|
|
94 int m_shape;
|
|
95 ^~~~~~~
|
|
96 { dg-end-multiline-output "" } */
|
|
97
|
|
98 // { dg-message "field .int t1::m_shape. can be accessed via .int& t1::get_shape\\(\\)." "" { target *-*-* } .-12 }
|
|
99 /* { dg-begin-multiline-output "" }
|
|
100 return ptr->m_shape;
|
|
101 ^~~~~~~
|
|
102 get_shape()
|
|
103 { dg-end-multiline-output "" } */
|
|
104 }
|