https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84993
Bug ID: 84993 Summary: Combination of fieldnames and accessor suggestions for misspelled private fields Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: dmalcolm at gcc dot gnu.org Reporter: dmalcolm at gcc dot gnu.org Target Milestone: --- Consider: class foo { public: double get_ratio() const { return m_ratio; } private: double m_ratio; }; void test(foo *ptr) { if (ptr->ratio >= 0.5) ;// etc } Currently we emit this suggestion: <source>: In function 'void test(foo*)': <source>:12:12: error: 'class foo' has no member named 'ratio'; did you mean 'm_ratio'? if (ptr->ratio >= 0.5) ^~~~~ m_ratio ...but if the user follows this suggestion, they get: <source>: In function 'void test(foo*)': <source>:12:12: error: 'double foo::m_ratio' is private within this context if (ptr->m_ratio >= 0.5) ^~~~~~~ <source>:7:10: note: declared private here double m_ratio; ^~~~~~~ <source>:12:12: note: field 'double foo::m_ratio' can be accessed via 'double foo::get_ratio() const' if (ptr->m_ratio >= 0.5) ^~~~~~~ get_ratio() It feels wrong to be emitting a fix-it hint that doesn't compile; we ought to offer the accessor directly; something like: <source>: In function 'void test(foo*)': <source>:12:12: error: 'class foo' has no member named 'ratio'; did you mean 'private' field 'double foo::m_ratio', accessed by 'double foo::get_ratio() const'? if (ptr->ratio >= 0.5) ^~~~~ get_ratio () or somesuch.