From patchwork Mon Oct 7 12:35:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1172747 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-510395-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="U1ruQKHL"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="P3uS5lih"; dkim-atps=neutral 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 46n0MD0Vjzz9sPJ for ; Mon, 7 Oct 2019 23:35:50 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=Ztj19jBUwp6EzU78EtgG3W2lHHDLRRSdhZEOViURsPSEtCm065 oeLFhXaPKCnFmnv7gaxiNHId/DpgSf5inOL+7HPXSQBy1wltLvUb8qnZmQjdtdkO upWOrC2mDDpaHIj+Cr9G5vng4//vhkGL3yJ0jQo6gNFJ7kgHz0wFKcqF0= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=tJzS3dauUZqNQxhHcTSU/md1ty0=; b=U1ruQKHL5htvgRKWoZnD 3JLWcT9jXYdjZ0AeEEVw/D7PR1YUzdiHi1HBHTIGCQWPCvW3MpOYop/0uNTWYE8x ji/ct0MLd/W46fS7nDp1QZorA4FjPbinPSGznjNIGpw8dQ3UeK4pA5fVQuOzm538 JOKUwclmTuicV9Iyv4rq7q4= Received: (qmail 59972 invoked by alias); 7 Oct 2019 12:35:43 -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 59792 invoked by uid 89); 7 Oct 2019 12:35:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=55, sk:build_a, paolo X-HELO: userp2120.oracle.com Received: from userp2120.oracle.com (HELO userp2120.oracle.com) (156.151.31.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 07 Oct 2019 12:35:40 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x97CY8Ps191062; Mon, 7 Oct 2019 12:35:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : cc : from : subject : message-id : date : mime-version : content-type; s=corp-2019-08-05; bh=Y2IPrrBLU0hJm1qnnRqFaKigLvYHSn0DU6u0tH1fjUY=; b=P3uS5lihYuEMzqNhhjVoex6jamdmZESjGMMRh/ILOL2MzR3JSa/gtvlDip2ecn/rwW9d xb8kih5z1QiCXEHH/xpEPCDQPKw22Go/jLDD6LjzhGszVRReBhibjeF807DF7O5sxEb9 yeu+iKXb7L5cjQNf8Kkns1c/bVTylL+ln8T2GUiOomaCuij+TKeNuIfJEzs9atR+o9uy Ne4zRVK7XmkXVsGAlDqy32hadzZ+U42gmGQKW5mgfeZ8AiaQciN7kYdZzi4bLeh76bH2 DP5wJKWxkjDD926jFAqipz/miTVApUdDr/cJ3kTgcqGUZRXjxfl4nyoQ64m/8qbvf/0Y ZA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2vektr672q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Oct 2019 12:35:37 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x97CY3G9135915; Mon, 7 Oct 2019 12:35:37 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2vf4n94119-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Oct 2019 12:35:36 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x97CZZQf020051; Mon, 7 Oct 2019 12:35:35 GMT Received: from [192.168.1.4] (/79.18.213.139) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 Oct 2019 05:35:34 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Fix cp_parser_delete_expression and cp_parser_throw_expression locations and more Message-ID: Date: Mon, 7 Oct 2019 14:35:32 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi, the below fixes those two functions consistently with cp_parser_new_expression. Additionally, a few rather straightforward tweaks along the usual lines, more DECL_SOURCE_LOCATION and id_loc. Tested x86_64-linux. Thanks, Paolo. ///////////////////// /cp 2019-10-07 Paolo Carlini * call.c (resolve_args): Use cp_expr_loc_or_input_loc in one place. * decl.c (grokdeclarator): Use id_loc in one place. * decl2.c (build_anon_union_vars): Use DECL_SOURCE_LOCATION. * parser.c (cp_parser_delete_expression): Fix the location of the returned expression. (cp_parser_throw_expression): Likewise. * pt.c (determine_specialization): Use DECL_SOURCE_LOCATION. /testsuite 2019-10-07 Paolo Carlini * g++.dg/diagnostic/not-a-function-template-1.C: New. * g++.dg/template/crash107.C: Adjust expected location. * g++.dg/template/dependent-expr1.C: Check locations. * g++.dg/template/error17.C: Check location. Index: cp/call.c =================================================================== --- cp/call.c (revision 276646) +++ cp/call.c (working copy) @@ -4381,7 +4381,8 @@ resolve_args (vec *args, tsubst_flags else if (VOID_TYPE_P (TREE_TYPE (arg))) { if (complain & tf_error) - error ("invalid use of void expression"); + error_at (cp_expr_loc_or_input_loc (arg), + "invalid use of void expression"); return NULL; } else if (invalid_nonstatic_memfn_p (EXPR_LOCATION (arg), arg, complain)) Index: cp/decl.c =================================================================== --- cp/decl.c (revision 276646) +++ cp/decl.c (working copy) @@ -12754,8 +12754,8 @@ grokdeclarator (const cp_declarator *declarator, tree tmpl = TREE_OPERAND (unqualified_id, 0); if (variable_template_p (tmpl)) { - error ("specialization of variable template %qD " - "declared as function", tmpl); + error_at (id_loc, "specialization of variable template " + "%qD declared as function", tmpl); inform (DECL_SOURCE_LOCATION (tmpl), "variable template declared here"); return error_mark_node; Index: cp/decl2.c =================================================================== --- cp/decl2.c (revision 276646) +++ cp/decl2.c (working copy) @@ -1608,7 +1608,8 @@ build_anon_union_vars (tree type, tree object) just give an error. */ if (TREE_CODE (type) != UNION_TYPE) { - error ("anonymous struct not inside named type"); + error_at (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)), + "anonymous struct not inside named type"); return error_mark_node; } Index: cp/parser.c =================================================================== --- cp/parser.c (revision 276646) +++ cp/parser.c (working copy) @@ -9014,6 +9014,7 @@ cp_parser_delete_expression (cp_parser* parser) bool global_scope_p; bool array_p; tree expression; + location_t start_loc = cp_lexer_peek_token (parser->lexer)->location; /* Look for the optional `::' operator. */ global_scope_p @@ -9043,8 +9044,18 @@ cp_parser_delete_expression (cp_parser* parser) if (cp_parser_non_integral_constant_expression (parser, NIC_DEL)) return error_mark_node; - return delete_sanity (expression, NULL_TREE, array_p, global_scope_p, - tf_warning_or_error); + /* Construct a location e.g.: + delete [ ] ptr + ^~~~~~~~~~~~~~ + with caret == start at the start of the "delete" token, and + the end at the end of the final token we consumed. */ + location_t combined_loc = make_location (start_loc, start_loc, + parser->lexer); + expression = delete_sanity (expression, NULL_TREE, array_p, + global_scope_p, tf_warning_or_error); + protected_set_expr_location (expression, combined_loc); + + return expression; } /* Returns 1 if TOKEN may start a cast-expression and isn't '++', '--', @@ -25827,6 +25838,7 @@ cp_parser_throw_expression (cp_parser* parser) { tree expression; cp_token* token; + location_t start_loc = cp_lexer_peek_token (parser->lexer)->location; cp_parser_require_keyword (parser, RID_THROW, RT_THROW); token = cp_lexer_peek_token (parser->lexer); @@ -25842,7 +25854,17 @@ cp_parser_throw_expression (cp_parser* parser) else expression = cp_parser_assignment_expression (parser); - return build_throw (expression); + /* Construct a location e.g.: + throw x + ^~~~~~~ + with caret == start at the start of the "throw" token, and + the end at the end of the final token we consumed. */ + location_t combined_loc = make_location (start_loc, start_loc, + parser->lexer); + expression = build_throw (expression); + protected_set_expr_location (expression, combined_loc); + + return expression; } /* GNU Extensions */ Index: cp/pt.c =================================================================== --- cp/pt.c (revision 276646) +++ cp/pt.c (working copy) @@ -2137,7 +2137,8 @@ determine_specialization (tree template_id, if (TREE_CODE (decl) == FUNCTION_DECL && !is_overloaded_fn (fns)) { - error ("%qD is not a function template", fns); + error_at (DECL_SOURCE_LOCATION (decl), + "%qD is not a function template", fns); return error_mark_node; } else if (VAR_P (decl) && !variable_template_p (fns)) @@ -2416,7 +2417,8 @@ determine_specialization (tree template_id, error ("template-id %qD for %q+D does not match any template " "declaration", template_id, decl); if (header_count && header_count != template_count + 1) - inform (input_location, "saw %d %%>, need %d for " + inform (DECL_SOURCE_LOCATION (decl), + "saw %d %%>, need %d for " "specializing a member function template", header_count, template_count + 1); else Index: testsuite/g++.dg/diagnostic/not-a-function-template-1.C =================================================================== --- testsuite/g++.dg/diagnostic/not-a-function-template-1.C (nonexistent) +++ testsuite/g++.dg/diagnostic/not-a-function-template-1.C (working copy) @@ -0,0 +1,9 @@ +// { dg-do compile { target c++14 } } + +template int A; // { dg-message "24:variable template" } + +template int A<>(); // { dg-error "14:template" } + +struct B { + friend int A<>(); // { dg-error "14:specialization" } +}; Index: testsuite/g++.dg/template/crash107.C =================================================================== --- testsuite/g++.dg/template/crash107.C (revision 276646) +++ testsuite/g++.dg/template/crash107.C (working copy) @@ -6,8 +6,8 @@ template struct Vec { // { dg-message "note" } Vec& operator^=(Vec& rhs) { union { - struct {FP_ x,y,z;}; - }; // { dg-error "anonymous struct" } + struct {FP_ x,y,z;}; // { dg-error "20:anonymous struct" } + }; X = y*rhs.z() - z*rhs.y(); // { dg-error "not declared|no member" } } Vec& operator^(Vec& rhs) { Index: testsuite/g++.dg/template/dependent-expr1.C =================================================================== --- testsuite/g++.dg/template/dependent-expr1.C (revision 276646) +++ testsuite/g++.dg/template/dependent-expr1.C (working copy) @@ -19,11 +19,11 @@ namespace std Foo (sizeof (x)); Foo (__alignof__ (I)); Foo (__alignof__ (x)); - Foo (x->~I ()); // { dg-error "" } + Foo (x->~I ()); // { dg-error "16:invalid" } // Foo (typeid (I)); - Foo (delete x); // { dg-error "" } - Foo (delete[] x); // { dg-error "" } - Foo (throw x); // { dg-error "" } + Foo (delete x); // { dg-error "10:invalid" } + Foo (delete[] x); // { dg-error "10:invalid" } + Foo (throw x); // { dg-error "10:invalid" } } } Index: testsuite/g++.dg/template/error17.C =================================================================== --- testsuite/g++.dg/template/error17.C (revision 276646) +++ testsuite/g++.dg/template/error17.C (working copy) @@ -5,5 +5,5 @@ void foo() { union { struct { }; }; // { dg-error "prohibits anonymous struct" "anon" } - // { dg-error "not inside" "not inside" { target *-*-* } .-1 } + // { dg-error "18:anonymous struct not inside" "not inside" { target *-*-* } .-1 } }