From patchwork Mon Oct 29 10:12:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 990116 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-488496-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="A/OMXiD7"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="2OqDtWAs"; 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 42k9Qf3mZwz9s8T for ; Mon, 29 Oct 2018 21:12:57 +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=Jo1VsEaLAXaIMB6fDzFWZWA1Twl8Ezzqu2ivkVhbbCUC72igIc 3k8rJDwmh9Ibm6VxuNNLU4Evxto/AbCBwSr0uwtTD0GdDDR+WumX6zgzFLMM1Rbs jz5X6igqkolG7BgV5HNLmELzgWbBU6gKCnBoj/MyuEL6m57b4EbxcuXuI= 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=aH2UUPgPL+O8YJuadWJk578I9hE=; b=A/OMXiD7FCpt1ojFBvxa pN/2TveCIuCwlnw4wS09967JjWm/trm0jQuT5UcC2Nqox+RD5fWWVE1fjxdCY6+i msqxTageHbJet4yS42lk/ls/tG/H58KPQzXDOxZP9qIkZZyTz7Hp+PhqPya3yvza Y4ZyMqJPcmsfxEsjH55mpYw= Received: (qmail 44016 invoked by alias); 29 Oct 2018 10:12:49 -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 43976 invoked by uid 89); 29 Oct 2018 10:12:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=old-deja, olddeja, assemble, sk:pointer X-HELO: userp2130.oracle.com Received: from userp2130.oracle.com (HELO userp2130.oracle.com) (156.151.31.86) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 29 Oct 2018 10:12:46 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9T9xMr2091067; Mon, 29 Oct 2018 10:12:44 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-2018-07-02; bh=+QutGm19XLriSrUGYVnYjfBIPOmnMUl2TbmNVcIr554=; b=2OqDtWAsH/DJCh47gPaf6SFQJS7xPROZPZGnDkDmFXaIwvETWYuabm0f2h0SS/YAc/kP +8voL3ZDC5NMzh04IhjM+tZilo0WxYPds+vwA/7cOtbf0cMbQ4rJTaB5eYdjz5ehpUe8 n5WUX/dIYHVOoHI6JX9v7i0pYF7DAE/5QeZltbt4w+Ey6KNEgpDQKf6xnso5lfUP3P/R 8Ch3Ee89ls2Aew1dYnH6otTWYdajctzXHQelNFnIwgwtEyU+HdhwLge3Ii9225Jfwte9 eis3xFITO4hGzqMjAlzJBV5iFQahjlpqx1jcVb4bJpwHpKnWx3A5sVWkP9CQf+JWt4Al xQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2nducksbyt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Oct 2018 10:12:44 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9TACcJw000763 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Oct 2018 10:12:38 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9TACcKQ007973; Mon, 29 Oct 2018 10:12:38 GMT Received: from [192.168.1.4] (/87.10.221.76) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 29 Oct 2018 03:12:37 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Improve create_array_type_for_decl locations Message-ID: <44aea7d3-6c72-15d9-3d39-0a11765c4527@oracle.com> Date: Mon, 29 Oct 2018 11:12:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi, while working on something else I noticed that by adding a location_t parameter we can improve the locations of those error messages. Tested x86_64-linux. Thanks, Paolo. ///////////////////// /cp 2018-10-29 Paolo Carlini * decl.c (create_array_type_for_decl): Add location_t parameter and use it. (grokdeclarator): Adjust call. /testsuite 2018-10-29 Paolo Carlini * g++.dg/cpp0x/auto24.C: Test location too. * g++.dg/cpp0x/auto3.C: Likewise. * g++.dg/cpp0x/auto42.C: Likewise. * g++.dg/cpp0x/initlist57.C: Likewise. * g++.dg/cpp0x/initlist75.C: Likewise. * g++.dg/cpp0x/initlist80.C: Likewise. * g++.dg/cpp0x/lambda/lambda-ice13.C: Likewise. * g++.old-deja/g++.brendan/array-refs.C: Likewise. * g++.old-deja/g++.bugs/900322_01.C: Likewise. * g++.old-deja/g++.bugs/900519_07.C: Likewise. * g++.old-deja/g++.other/typeck1.C: Likewise. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 265582) +++ cp/decl.c (working copy) @@ -88,7 +88,7 @@ static void finish_constructor_body (void); static void begin_destructor_body (void); static void finish_destructor_body (void); static void record_key_method_defined (tree); -static tree create_array_type_for_decl (tree, tree, tree); +static tree create_array_type_for_decl (tree, tree, tree, location_t); static tree get_atexit_node (void); static tree get_dso_handle_node (void); static tree start_cleanup_fn (void); @@ -9835,7 +9837,7 @@ get_scope_of_declarator (const cp_declarator *decl with this type. */ static tree -create_array_type_for_decl (tree name, tree type, tree size) +create_array_type_for_decl (tree name, tree type, tree size, location_t loc) { tree itype = NULL_TREE; @@ -9848,9 +9850,9 @@ static tree if (type_uses_auto (type)) { if (name) - error ("%qD declared as array of %qT", name, type); + error_at (loc, "%qD declared as array of %qT", name, type); else - error ("creating array of %qT", type); + error ("creating array of %qT", type); return error_mark_node; } @@ -9860,7 +9862,7 @@ static tree { case VOID_TYPE: if (name) - error ("declaration of %qD as array of void", name); + error_at (loc, "declaration of %qD as array of void", name); else error ("creating array of void"); return error_mark_node; @@ -9867,7 +9869,7 @@ static tree case FUNCTION_TYPE: if (name) - error ("declaration of %qD as array of functions", name); + error_at (loc, "declaration of %qD as array of functions", name); else error ("creating array of functions"); return error_mark_node; @@ -9874,7 +9876,7 @@ static tree case REFERENCE_TYPE: if (name) - error ("declaration of %qD as array of references", name); + error_at (loc, "declaration of %qD as array of references", name); else error ("creating array of references"); return error_mark_node; @@ -9881,7 +9883,8 @@ static tree case METHOD_TYPE: if (name) - error ("declaration of %qD as array of function members", name); + error_at (loc, "declaration of %qD as array of function members", + name); else error ("creating array of function members"); return error_mark_node; @@ -9897,9 +9900,9 @@ static tree if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)) { if (name) - error ("declaration of %qD as multidimensional array must " - "have bounds for all dimensions except the first", - name); + error_at (loc, "declaration of %qD as multidimensional array must " + "have bounds for all dimensions except the first", + name); else error ("multidimensional array must have bounds for all " "dimensions except the first"); @@ -11164,7 +11167,8 @@ grokdeclarator (const cp_declarator *declarator, { case cdk_array: type = create_array_type_for_decl (dname, type, - declarator->u.array.bounds); + declarator->u.array.bounds, + declarator->id_loc); if (!valid_array_size_p (input_location, type, dname)) type = error_mark_node; Index: testsuite/g++.dg/cpp0x/auto24.C =================================================================== --- testsuite/g++.dg/cpp0x/auto24.C (revision 265510) +++ testsuite/g++.dg/cpp0x/auto24.C (working copy) @@ -2,4 +2,4 @@ // { dg-do compile { target c++11 } } int v[1]; -auto (*p)[1] = &v; // { dg-error "array of .auto" } +auto (*p)[1] = &v; // { dg-error "8:.p. declared as array of .auto" } Index: testsuite/g++.dg/cpp0x/auto3.C =================================================================== --- testsuite/g++.dg/cpp0x/auto3.C (revision 265510) +++ testsuite/g++.dg/cpp0x/auto3.C (working copy) @@ -10,7 +10,7 @@ auto x; // { dg-error "auto" } auto i = 42, j = 42.0; // { dg-error "auto" } // New CWG issue -auto a[2] = { 1, 2 }; // { dg-error "auto|initializer_list" } +auto a[2] = { 1, 2 }; // { dg-error "6:.a. declared as array of .auto" } template struct A { }; Index: testsuite/g++.dg/cpp0x/auto42.C =================================================================== --- testsuite/g++.dg/cpp0x/auto42.C (revision 265510) +++ testsuite/g++.dg/cpp0x/auto42.C (working copy) @@ -5,5 +5,5 @@ void foo(int i) { - auto x[1] = { 0 }; // { dg-error "array of .auto" } + auto x[1] = { 0 }; // { dg-error "8:.x. declared as array of .auto" } } Index: testsuite/g++.dg/cpp0x/initlist57.C =================================================================== --- testsuite/g++.dg/cpp0x/initlist57.C (revision 265510) +++ testsuite/g++.dg/cpp0x/initlist57.C (working copy) @@ -1,7 +1,7 @@ // PR c++/50054 // { dg-do compile { target c++11 } } -void g( const int& (a)[1] ) {} // { dg-error "array of references" } +void g( const int& (a)[1] ) {} // { dg-error "21:declaration of .a. as array of references" } int main () { g( { 1, 2 } ); // { dg-error "initializer list" } Index: testsuite/g++.dg/cpp0x/initlist75.C =================================================================== --- testsuite/g++.dg/cpp0x/initlist75.C (revision 265510) +++ testsuite/g++.dg/cpp0x/initlist75.C (working copy) @@ -3,4 +3,4 @@ #include -auto foo[] = {}; // { dg-error "auto|unable to deduce" } +auto foo[] = {}; // { dg-error "6:.foo. declared as array of .auto" } Index: testsuite/g++.dg/cpp0x/initlist80.C =================================================================== --- testsuite/g++.dg/cpp0x/initlist80.C (revision 265510) +++ testsuite/g++.dg/cpp0x/initlist80.C (working copy) @@ -3,4 +3,4 @@ #include -auto x[2] = {}; // { dg-error "" } +auto x[2] = {}; // { dg-error "6:.x. declared as array of .auto" } Index: testsuite/g++.dg/cpp0x/lambda/lambda-ice13.C =================================================================== --- testsuite/g++.dg/cpp0x/lambda/lambda-ice13.C (revision 265510) +++ testsuite/g++.dg/cpp0x/lambda/lambda-ice13.C (working copy) @@ -10,5 +10,6 @@ void f() void g() { typedef void (X) (); - X x[] = { [x](){} }; // { dg-error "array of functions|not declared" } + X x[] = { [x](){} }; // { dg-error "5:declaration of .x. as array of functions" } + // { dg-error "not declared" "" { target *-*-* } .-1 } } Index: testsuite/g++.old-deja/g++.brendan/array-refs.C =================================================================== --- testsuite/g++.old-deja/g++.brendan/array-refs.C (revision 265510) +++ testsuite/g++.old-deja/g++.brendan/array-refs.C (working copy) @@ -3,4 +3,4 @@ int a, b; // declaring an array of references should be illegal -int & v[ 2] = { a, b};// { dg-error "" } .* +int & v[ 2] = { a, b}; // { dg-error "7:declaration of .v. as array of references" } Index: testsuite/g++.old-deja/g++.bugs/900322_01.C =================================================================== --- testsuite/g++.old-deja/g++.bugs/900322_01.C (revision 265510) +++ testsuite/g++.old-deja/g++.bugs/900322_01.C (working copy) @@ -33,24 +33,25 @@ // keywords: incomplete types, arrays, element types -extern int extern_two_d [] []; // { dg-error "" } invalid declaration -int tenative_two_d [] []; // { dg-error "" } caught by g++ -static int static_two_d [] []; // { dg-error "" } caught by g++ +extern int extern_two_d [] []; // { dg-error "12:declaration of .extern_two_d. as multidimensional" } invalid declaration +int tenative_two_d [] []; // { dg-error "5:declaration of .tenative_two_d. as multidimensional" } caught by g++ +static int static_two_d [] []; // { dg-error "12:declaration of .static_two_d. as multidimensional" } caught by g++ -int (*pointer_to_two_d)[][]; // { dg-error "" } invalid declaration +int (*pointer_to_two_d)[][]; // { dg-error "7:declaration of .pointer_to_two_d. as multidimensional" } invalid declaration -void function_0 (int arg [] []) { // { dg-error "" } invalid declaration +void function_0 (int arg [] []) { // { dg-error "22:declaration of .arg. as multidimensional" } invalid declaration } typedef int int_one_d_type []; -typedef int_one_d_type int_two_d_type[];// { dg-error "" } invalid declaration +typedef int_one_d_type int_two_d_type[];// { dg-error "24:declaration of .int_two_d_type. as multidimensional" } invalid declaration struct s; extern struct s extern_s_array [10]; // OK -struct s tenative_s_array [10]; // { dg-error "" } object with incomplete type -static struct s static_s_array [10]; // { dg-error "" } object with incomplete type - +struct s tenative_s_array [10]; // { dg-error "10:elements of array .s tenative_s_array \\\[10\\\]. have incomplete type" } object with incomplete type +// { dg-error "10:storage size" "" { target *-*-* } .-1 } +static struct s static_s_array [10]; // { dg-error "17:elements of array .s static_s_array \\\[10\\\]. have incomplete type" } object with incomplete type +// { dg-error "17:storage size" "" { target *-*-* } .-1 } struct s (*pointer_to_s_array) []; // OK void function_1 (struct s arg []) { // OK Index: testsuite/g++.old-deja/g++.bugs/900519_07.C =================================================================== --- testsuite/g++.old-deja/g++.bugs/900519_07.C (revision 265510) +++ testsuite/g++.old-deja/g++.bugs/900519_07.C (working copy) @@ -11,7 +11,7 @@ int i; int j; typedef int& int_ref; -typedef int_ref int_ref_array_type[2]; // { dg-error "" } missed +typedef int_ref int_ref_array_type[2]; // { dg-error "17:declaration of .int_ref_array_type. as array of references" } missed -int& int_ref_array_obj0[2] = { i, j }; // { dg-error "" } missed -int_ref int_ref_array_obj1[2] = { i, j }; // { dg-error "" } missed +int& int_ref_array_obj0[2] = { i, j }; // { dg-error "6:declaration of .int_ref_array_obj0. as array of references" } missed +int_ref int_ref_array_obj1[2] = { i, j }; // { dg-error "9:declaration of .int_ref_array_obj1. as array of references" } missed Index: testsuite/g++.old-deja/g++.other/typeck1.C =================================================================== --- testsuite/g++.old-deja/g++.other/typeck1.C (revision 265510) +++ testsuite/g++.old-deja/g++.other/typeck1.C (working copy) @@ -1,7 +1,7 @@ // { dg-do assemble } -extern int a[][]; // { dg-error "" } invalid multidimensional array -extern int b[7][]; // { dg-error "" } invalid multidimensional array +extern int a[][]; // { dg-error "12:declaration of .a. as multidimensional array" } invalid multidimensional array +extern int b[7][]; // { dg-error "12:declaration of .b. as multidimensional array" } invalid multidimensional array extern int c[][7]; // OK extern int (*i)[]; // { dg-message "" } previous declaration