2018-11-07 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / torture / accessor-fixits-9.C
blobd9e77ba2d3bd83992030271062088ce6bf49f50c
1 // PR c++/84993
2 // { dg-options "-fdiagnostics-show-caret" }
4 /* Misspelling (by omitting a leading "m_") of a private member for which
5    there's a public accessor.
7    We expect a fix-it hint suggesting the accessor.  */
9 class t1
11 public:
12   int get_ratio () const { return m_ratio; }
14 private:
15   int m_ratio;
18 int test (t1 *ptr_1)
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\\(\\) const'\\)" }
21   /* { dg-begin-multiline-output "" }
22    return ptr_1->ratio;
23                  ^~~~~
24                  get_ratio()
25      { dg-end-multiline-output "" } */
29 /* Misspelling of a private member for which there's a public accessor.
31    We expect a fix-it hint suggesting the accessor.  */
33 class t2
35 public:
36   int get_color () const { return m_color; }
38 private:
39   int m_color;
42 int test (t2 *ptr_2)
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\\(\\) const'\\)" }
45   /* { dg-begin-multiline-output "" }
46    return ptr_2->m_colour;
47                  ^~~~~~~~
48                  get_color()
49      { dg-end-multiline-output "" } */
53 /* Misspelling of a private member via a subclass pointer, for which there's
54    a public accessor in the base class.
56    We expect a fix-it hint suggesting the accessor.  */
58 class t3 : public t2 {};
60 int test (t3 *ptr_3)
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\\(\\) const'\\)" }
63   /* { dg-begin-multiline-output "" }
64    return ptr_3->m_colour;
65                  ^~~~~~~~
66                  get_color()
67      { dg-end-multiline-output "" } */
71 /* Misspelling of a protected member, for which there's isn't a public
72    accessor.
74    We expect no fix-it hint; instead a message identifying where the
75    data member was declared.  */
77 class t4
79 protected:
80   int m_color; // { dg-message "declared protected here" }
83 int test (t4 *ptr_4)
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 "" } */
97 /* Misspelling of a private member, for which the accessor is also private.
99    We expect no fix-it hint; instead a message identifying where the
100    data member was declared.  */
102 class t5
104   int get_color () const { return m_color; }
105   int m_color; // { dg-message "declared private here" }
108 int test (t5 *ptr_5)
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 "" } */