@@ -2336,6 +2336,21 @@ build_component_ref (location_t loc, tree datum, tree component)
return ref;
}
+ else if (code == POINTER_TYPE && !c_dialect_objc ())
+ {
+ /* Special-case the error message for "ptr.field" for the case
+ where the user has confused "." vs "->".
+ We don't do it for Objective-C, since Objective-C 2.0 dot-syntax
+ allows "." for ptrs; we could be handling a failed attempt
+ to access a property. */
+ rich_location richloc (line_table, loc);
+ /* "loc" should be the "." token. */
+ richloc.add_fixit_replace (source_range::from_location (loc), "->");
+ error_at_rich_loc (&richloc,
+ "%qE is a pointer; did you mean to use %<->%>?",
+ datum);
+ return error_mark_node;
+ }
else if (code != ERROR_MARK)
error_at (loc,
"request for member %qE in something not a structure or union",
new file mode 100644
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-fdiagnostics-show-caret" } */
+
+struct foo { int x; };
+
+int test (struct foo *ptr)
+{
+ return ptr.x; /* { dg-error "'ptr' is a pointer; did you mean to use '->'?" } */
+/* { dg-begin-multiline-output "" }
+ return ptr.x;
+ ^
+ ->
+ { dg-end-multiline-output "" } */
+}