From patchwork Tue Dec 15 16:52:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 557007 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CA7831402D9 for ; Wed, 16 Dec 2015 03:32:45 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=F9QOcuX9; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=An0IiNeoh12r JjsOB9IY6cFouqPJB0p8UzO9NvH5ESujYwAX/ChmrMc/uUVfPUz0OoGpD0UI0cF+ mdzDTMyVn2Lb+G8UtlDdjN6L3mcO4DgWJdbgZ73L3J9Y+gZnEQEZH0uR5kttLWIS RcQCVfuD6yXPq6yS1SOE3epMCoiROO0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=q6lZHIybuNMc5GiL9i S6lPU9Yug=; b=F9QOcuX9vt661O9RW3ZbBNYttFQeejVhPOvCoNg5cjW4aGn8XN 6CRD8+yFQUAdgfdlkC4NMpFvyHOwXo3sJKpGmH3YA6gV7CsLLyGTxvQMyuJ5p4ei 4qamoBlE01S1NEtDo3CewQCoBmDy4PuHVfCUyvozXKpcyG5dL9ocoT/AM= Received: (qmail 112754 invoked by alias); 15 Dec 2015 16:32:33 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 112668 invoked by uid 89); 15 Dec 2015 16:32:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 15 Dec 2015 16:32:29 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 2B3E3A2A03 for ; Tue, 15 Dec 2015 16:32:28 +0000 (UTC) Received: from c64.redhat.com (vpn-237-199.phx2.redhat.com [10.3.237.199]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tBFGWRU4031573; Tue, 15 Dec 2015 11:32:27 -0500 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH] C++ FE: Show both locations in string literal concatenation error Date: Tue, 15 Dec 2015 11:52:01 -0500 Message-Id: <1450198321-5367-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes We can use rich_location and the new diagnostic_show_locus to print *both* locations when complaining about a bogus string concatenation in the C++ FE, giving e.g.: test.C:3:24: error: unsupported non-standard concatenation of string literals const void *s = u8"a" u"b"; ~~~~~ ^~~~ Successfully bootstrapped®rtested on x86_64-pc-linux-gnu OK for trunk for gcc 6? (an earlier version of this was posted as part of: "[PATCH 10/22] C++ FE: Use token ranges for various diagnostics" https://gcc.gnu.org/ml/gcc-patches/2015-09/msg00730.html though the implementation has changed slightly) gcc/cp/ChangeLog: * parser.c (cp_parser_string_literal): Convert non-standard concatenation error to directly use a rich_location, and use that to add the location of the first literal to the diagnostic. gcc/testsuite/ChangeLog: * g++.dg/diagnostic/string-literal-concat.C: New test case. --- gcc/cp/parser.c | 16 +++++++++++----- gcc/testsuite/g++.dg/diagnostic/string-literal-concat.C | 13 +++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/diagnostic/string-literal-concat.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index a420cf1..5247a5e 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -3815,13 +3815,12 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok, } else { - location_t last_tok_loc; + location_t last_tok_loc = tok->location; gcc_obstack_init (&str_ob); count = 0; do { - last_tok_loc = tok->location; cp_lexer_consume_token (parser->lexer); count++; str.text = (const unsigned char *)TREE_STRING_POINTER (string_tree); @@ -3853,13 +3852,20 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok, if (type == CPP_STRING) type = curr_type; else if (curr_type != CPP_STRING) - error_at (tok->location, - "unsupported non-standard concatenation " - "of string literals"); + { + rich_location rich_loc (line_table, tok->location); + rich_loc.add_range (last_tok_loc, get_finish (last_tok_loc), + false); + error_at_rich_loc (&rich_loc, + "unsupported non-standard concatenation " + "of string literals"); + } } obstack_grow (&str_ob, &str, sizeof (cpp_string)); + last_tok_loc = tok->location; + tok = cp_lexer_peek_token (parser->lexer); if (cpp_userdef_string_p (tok->type)) { diff --git a/gcc/testsuite/g++.dg/diagnostic/string-literal-concat.C b/gcc/testsuite/g++.dg/diagnostic/string-literal-concat.C new file mode 100644 index 0000000..2819b25 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/string-literal-concat.C @@ -0,0 +1,13 @@ +/* { dg-options "-fdiagnostics-show-caret -std=c++11" } */ + +const void *s = u8"a" u"b"; // { dg-error "non-standard concatenation" } +/* { dg-begin-multiline-output "" } + const void *s = u8"a" u"b"; + ~~~~~ ^~~~ + { dg-end-multiline-output "" } */ + +const void *s2 = u"a" u"b" u8"c"; // { dg-error "non-standard concatenation" } +/* { dg-begin-multiline-output "" } + const void *s2 = u"a" u"b" u8"c"; + ~~~~ ^~~~~ + { dg-end-multiline-output "" } */