1. 29
  1.  

  2. 7

    Ever so once in a while, I see stuff like this, remember my C++ days, and feel excited about trying to write more C++… and then I snap out of it, like remembering why you broke up with an ex-lover in the first place.

    No, but seriously, this is great stuff, and I am always happy to see gcc get better. The next time I write C++, which I’ll try to do for GNU Octave, I’ll be very grateful for better diagnostics. I already am, since gcc keeps getting better and better.

    1. 2

      A lot of good stuff, reading C++ errors is like learning an extra language on top of the C++ language, I can’t wait to try it out.

      How do I get at some private field?

      That one is interesting! 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 ?

      1. 2

        Hah, you’re also cross-posting to HN as I am.

        1. 1

          :) yes, the author was able to reply on HN and even took time to open a suggestion on GCC’s bugzilla

        2. 1

          According to godbolt’s trunk gcc, it is not smart enough:

          <source>: In function 'void test(foo*)':
          <source>:20:12: error: 'int foo::m_x' is private within this context
             if (ptr->m_x >= 3)
                      ^~~
          <source>:13:7: note: declared private here
             int m_x;
                 ^~~
          Compiler returned: 1
          
        3. 1

          The template type differences stuff looks great; those pages upon pages of template errors that you can get for a simple typo are so overwhelming.