https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84895

            Bug ID: 84895
           Summary: Smarter suggestions for "private" accessor hints
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: dmalcolm at gcc dot gnu.org
  Target Milestone: ---

In a discussion about g++ 8's ability to suggest accessor fix-it hints for
erroneous uses of private fields, Hacker News user "vmarsy" commented:

> I wonder how smart it is.
> For instance in the following example:

    class foo
    {
    public:
      std::pair<int, int> get_coordinates() const
      {
        return std::make_pair(m_x, m_y);
      }

    private:
      int m_x;
      int m_y;
    };


    void test(foo *ptr)
    {
      if (ptr->m_x >= 3)
        ;// etc
    }

> I wonder if the compiler would be able to figure out that m_x is
> accessible via `ptr->get_coordinates().first` ?

It isn't yet, but that's probably implementable (hence this bug), though I
wonder how much we want to do so, and if it would all be special-cases for
idiomatic C++ constructions?  Are there other examples?

Reply via email to