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

            Bug ID: 89854
           Summary: diagnostic differences between misuse of "." and "->"
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tromey at gcc dot gnu.org
  Target Milestone: ---

I'm using the system gcc on Fedora 29:

gcc (GCC) 8.2.1 20180801 (Red Hat 8.2.1-2)


Consider this source:

struct s {
  int f;
};

int x(struct s s) {
  return s->f;
}

int x(struct s *s) {
  return s.f;
}


Compiling it with g++:

murgatroyd. g++ --syntax-only b.cc 
b.cc: In function ‘int x(s)’:
b.cc:6:11: error: base operand of ‘->’ has non-pointer type ‘s’
   return s->f;
           ^~
b.cc: In function ‘int x(s*)’:
b.cc:10:12: error: request for member ‘f’ in ‘s’, which is of pointer type ‘s*’
(maybe you meant to use ‘->’ ?)
   return s.f;
            ^


Notice that the "->" message underlines the operator (which seems best
to me), whereas the "." message underlines the member.

Also notice that the "." message suggests using "->" (which seems best
to me), whereas the "->" message does not.

Finally, it seems to me that both of these could provide fixits.

Reply via email to