diff mbox series

[pushed] Objective-C/C++ : Improve '@' keyword locations.

Message ID 68FF194B-C5B9-48F5-9EBD-44741C7480C7@sandoe.co.uk
State New
Headers show
Series [pushed] Objective-C/C++ : Improve '@' keyword locations. | expand

Commit Message

Iain Sandoe Nov. 1, 2020, 8:28 p.m. UTC
Hi

When we are lexing tokens for Objective-C, we combine '@' tokens
with a following keyword (when that keyword is a valid Objective-C
one or, for Objective-C, one of the C++ keywords that can appear in
this position).  The responsibility is passed on to the parser to
validate the resulting combination.

The combination of tokens was being done without applying the rule
to their locations - so that we get:

@property
^

instead of what the user might expect:

@property
^~~~~~~~

This patch combines the source range of the keyword with that of the
'@' sign - which improves diagnostics (we now get the second rendering).

tested on x86_64-darwin, x86_64-linux-gnu
pushed
thanks
Iain

---

gcc/c-family/ChangeLog:

	* c-lex.c (c_lex_with_flags): When combining '@' with a
	keyword for Objective-C, combine the location ranges too.
---
 gcc/c-family/c-lex.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index b1cef2345f4..e81e16ddc26 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -550,7 +550,11 @@  c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags,
 		     returning a token of type CPP_AT_NAME and rid
 		     code RID_CLASS (not RID_AT_CLASS).  The language
 		     parser needs to convert that to RID_AT_CLASS.
+		     However, we've now spliced the '@' together with the
+		     keyword that follows; Adjust the location so that we
+		     get a source range covering the composite.
 		  */
+	         *loc = make_location (atloc, atloc, newloc);
 		  break;
 		}
 	      /* FALLTHROUGH */