From patchwork Sun Nov 1 20:28:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 1391829 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CPSLT2GYSz9sVK for ; Mon, 2 Nov 2020 07:28:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 27B4E3851C06; Sun, 1 Nov 2020 20:28:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp1.wavenetuk.net (smtp.wavenetuk.net [195.26.36.10]) by sourceware.org (Postfix) with ESMTP id 049323858D37 for ; Sun, 1 Nov 2020 20:28:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 049323858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=iain@sandoe.co.uk Received: from [192.168.1.212] (host81-138-1-83.in-addr.btopenworld.com [81.138.1.83]) by smtp1.wavenetuk.net (Postfix) with ESMTPA id 564F21204F3D; Sun, 1 Nov 2020 20:28:37 +0000 (GMT) From: Iain Sandoe Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [pushed] Objective-C/C++ : Improve '@' keyword locations. Message-Id: <68FF194B-C5B9-48F5-9EBD-44741C7480C7@sandoe.co.uk> Date: Sun, 1 Nov 2020 20:28:18 +0000 To: GCC Patches X-Mailer: Apple Mail (2.3273) X-Spam-Status: No, score=-16.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_COUK, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nathan Sidwell Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 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 --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 */