https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84898
Bug ID: 84898
Summary: Fix-it hints for '.' vs '->'
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: ---
Reddit user "Boojum" suggested:
> [...] Clang offers fix-its for both errors and gets the symmetry correct:
% cat deref.cpp
struct foo { float x; };
float bar(foo f) {
return f->x;
}
float baz(foo* f) {
return f.x;
}
% g++72 deref.cpp
deref.cpp: In function ‘float bar(foo)’:
deref.cpp:3:13: error: base operand of ‘->’ has non-pointer type ‘foo’
return f->x;
^~
deref.cpp: In function ‘float baz(foo*)’:
deref.cpp:6:14: error: request for member ‘x’ in ‘f’, which is of pointer type
‘foo*’ (maybe you meant to use ‘->’ ?)
return f.x;
^
% clang-6.0 deref.cpp
deref.cpp:3:13: error: member reference type 'foo' is not a pointer; did you
mean to use '.'?
return f->x;
~^~
.
deref.cpp:6:13: error: member reference type 'foo *' is a pointer; did you mean
to use '->'?
return f.x;
~^
->
2 errors generated.