From patchwork Tue Aug 27 11:09:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1153762 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-507770-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="O5ieacWx"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="oEfGiLnN"; 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 46HmNL3LFmz9s00 for ; Tue, 27 Aug 2019 21:09:22 +1000 (AEST) 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=bp7olXAAt9sEKHt2HLqq3d0+rYiB4p60m2iibztlc/zBNroLwM 4aqH3KD1OqwUJUiKwIouySbydYESo4rzrplkQeGHTbWhX11pEzR3fleOOf0i6EFZ 92SQqUow2sIoOgihLorL6CG05GKtIt+zcWlDrH/MFqgqvjOwfNSRBiU10= 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=GnfyrIaE9eIBP2gzswdhJ+DoM0Q=; b=O5ieacWxAHkUJGY0xngn 0RNGoQkqx016F9Vx9o8LSEnynhEg9/E3vnZKHE3+tbmzv7sKFFpM2AOC4ZaygslO IZjxHCkXrexM0pBJl0uBLmZkLP7UNkFqvkVZn0JNDDi7Mwb79DG3N7/HFxYLo9qc 9e2YbqNpJAadLnIdNKeW9Ss= Received: (qmail 44122 invoked by alias); 27 Aug 2019 11:09:15 -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 44109 invoked by uid 89); 27 Aug 2019 11:09:15 -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 autolearn=ham version=3.3.1 spammy=rarely 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; Tue, 27 Aug 2019 11:09:13 +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 x7RB4OX8083494; Tue, 27 Aug 2019 11:09:09 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=Mg65XfjMCWDqTVh8GAoBXqSCtmDdfeWsocNlt4tdiXQ=; b=oEfGiLnNzyVR/gxjasMc848eExdFhC/H4JV4Hl8AK5H1TS5QGmL56jRSvVY2X31vs69I uJzyJ+ELGXXawPBEfjgrzdiPQ05RP2fcgiPvqeL61u/KXfe0fDV8P/1X87Wl+dR1LY3W F0AQAyYBOHi2LbQlkwEKn6LaVSWCmi6kTazgY6K1ccLU+ANhSH8VdqfMuS6ojR1IW0gr nGn6RNGqsttB1EM8gDdwAgdD8/KfCe08V4XAEimKeqlRY7V79U7qJ+85F6wWLm6yG3y1 Jk9/nI9RVmDRYZg38kY2xf0zwBLbtb5mAEBJldJWKzmHUvod3ymO5E19bet+MykhQYHj dA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2un2y6g68u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Aug 2019 11:09:09 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7RB8Lk0168584; Tue, 27 Aug 2019 11:09:09 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2umj287sq3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Aug 2019 11:09:09 +0000 Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x7RB97Xm028448; Tue, 27 Aug 2019 11:09:08 GMT Received: from [192.168.1.4] (/79.19.31.88) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 27 Aug 2019 04:09:07 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Improve check_var_type locations Message-ID: Date: Tue, 27 Aug 2019 13:09:04 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, by adding a location_t parameter we can improve the locations of the error messages. At the moment the locations of the first and third message end up being input_location anyway, but we can imagine improving those later (this a much more general issue, the locations we use when unnamed entities are involved, see for example all the 'if (name)' in grokdeclarator and elsewhere: input_location is very rarely the best location). Testex x86_64-linux. Thanks, Paolo. ///////////////////////////////// /cp 2019-08-27 Paolo Carlini * decl.c (check_var_type): Add location_t parameter and use it. (grokdeclarator): Adjust call. * pt.c (tsubst_decl): Likewise. * cp-tree.h: Adjust declaration. /testsuite 2019-08-27 Paolo Carlini * g++.dg/spellcheck-typenames.C: Adjust expected locations. * g++.dg/cpp0x/pr84676.C: Check locations. * g++.dg/other/pr88187.C: Likewise. * g++.dg/parse/crash13.C: Likewise. * g++.dg/parse/crash46.C: Likewise. * g++.dg/parse/template28.C: Likewise. * g++.dg/parse/typename4.C: Likewise. Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 274945) +++ cp/cp-tree.h (working copy) @@ -6469,7 +6469,7 @@ extern tree cxx_comdat_group (tree); extern bool cp_missing_noreturn_ok_p (tree); extern bool is_direct_enum_init (tree, tree); extern void initialize_artificial_var (tree, vec *); -extern tree check_var_type (tree, tree); +extern tree check_var_type (tree, tree, location_t); extern tree reshape_init (tree, tree, tsubst_flags_t); extern tree next_initializable_field (tree); extern tree fndecl_declared_return_type (tree); Index: cp/decl.c =================================================================== --- cp/decl.c (revision 274945) +++ cp/decl.c (working copy) @@ -10278,19 +10278,20 @@ check_special_function_return_type (special_functi error-recovery purposes. */ tree -check_var_type (tree identifier, tree type) +check_var_type (tree identifier, tree type, location_t loc) { if (VOID_TYPE_P (type)) { if (!identifier) - error ("unnamed variable or field declared void"); + error_at (loc, "unnamed variable or field declared void"); else if (identifier_p (identifier)) { gcc_assert (!IDENTIFIER_ANY_OP_P (identifier)); - error ("variable or field %qE declared void", identifier); + error_at (loc, "variable or field %qE declared void", + identifier); } else - error ("variable or field declared void"); + error_at (loc, "variable or field declared void"); type = error_mark_node; } @@ -12407,7 +12408,7 @@ grokdeclarator (const cp_declarator *declarator, error message later. */ if (decl_context != PARM) { - type = check_var_type (unqualified_id, type); + type = check_var_type (unqualified_id, type, id_loc); if (type == error_mark_node) return error_mark_node; } Index: cp/pt.c =================================================================== --- cp/pt.c (revision 274945) +++ cp/pt.c (working copy) @@ -13894,7 +13895,8 @@ tsubst_decl (tree t, tree args, tsubst_flags_t com /* Wait until cp_finish_decl to set this again, to handle circular dependency (template/instantiate6.C). */ DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (r) = 0; - type = check_var_type (DECL_NAME (r), type); + type = check_var_type (DECL_NAME (r), type, + DECL_SOURCE_LOCATION (r)); if (DECL_HAS_VALUE_EXPR_P (t)) { Index: testsuite/g++.dg/cpp0x/pr84676.C =================================================================== --- testsuite/g++.dg/cpp0x/pr84676.C (revision 274945) +++ testsuite/g++.dg/cpp0x/pr84676.C (working copy) @@ -1,4 +1,5 @@ // { dg-do compile { target c++11 } } int a; -void b(__attribute__((c([](int *) {} (a == (0 = auto)))))); // { dg-error "" } +void b(__attribute__((c([](int *) {} (a == (0 = auto)))))); // { dg-error "6:variable or field .b. declared void" } +// { dg-error "expected" "" { target c++11 } .-1 } Index: testsuite/g++.dg/other/pr88187.C =================================================================== --- testsuite/g++.dg/other/pr88187.C (revision 274945) +++ testsuite/g++.dg/other/pr88187.C (working copy) @@ -2,6 +2,6 @@ // { dg-do compile } template struct A; -void f (A ()); // { dg-error "variable or field 'f' declared void" "" { target c++14_down } } +void f (A ()); // { dg-error "6:variable or field 'f' declared void" "" { target c++14_down } } // { dg-error "missing template arguments before '\\(' token" "" { target c++14_down } .-1 } // { dg-error "'auto' parameter not permitted in this context" "" { target c++17 } .-2 } Index: testsuite/g++.dg/parse/crash13.C =================================================================== --- testsuite/g++.dg/parse/crash13.C (revision 274945) +++ testsuite/g++.dg/parse/crash13.C (working copy) @@ -12,7 +12,8 @@ struct A }; template -void func(A::B* ) // { dg-error "variable|template|expression" } +void func(A::B* ) // { dg-error "6:variable or field .func. declared void" } +// { dg-error "expected" "" { target *-*-* } .-1 } { } Index: testsuite/g++.dg/parse/crash46.C =================================================================== --- testsuite/g++.dg/parse/crash46.C (revision 274945) +++ testsuite/g++.dg/parse/crash46.C (working copy) @@ -2,17 +2,17 @@ // { dg-do compile } void -foo (_Decimal32) // { dg-error "declared void" "declared" } +foo (_Decimal32) // { dg-error "1:variable or field .foo. declared void" "declared" } { } // { dg-error "was not declared" "not" { target *-*-* } 5 } void -bar (_Bool) // { dg-error "declared void" "declared" } +bar (_Bool) // { dg-error "1:variable or field .bar. declared void" "declared" } { } // { dg-error "was not declared" "not" { target *-*-* } 10 } void -baz (_Fract) // { dg-error "declared void" "declared" } +baz (_Fract) // { dg-error "1:variable or field .baz. declared void" "declared" } { } // { dg-error "was not declared" "not" { target *-*-* } 15 } Index: testsuite/g++.dg/parse/template28.C =================================================================== --- testsuite/g++.dg/parse/template28.C (revision 274945) +++ testsuite/g++.dg/parse/template28.C (working copy) @@ -2,7 +2,8 @@ template struct A {}; -template void foo(A=A()) {} // { dg-error "" } +template void foo(A=A()) {} // { dg-error "24:variable or field .foo. declared void" } +// { dg-error "template" "" { target *-*-* } .-1 } void bar() { Index: testsuite/g++.dg/parse/typename4.C =================================================================== --- testsuite/g++.dg/parse/typename4.C (revision 274945) +++ testsuite/g++.dg/parse/typename4.C (working copy) @@ -4,4 +4,5 @@ // PR c++/9364: ICE processing typename with name error. -void find(typename int&); // { dg-error "typename|void|expected" } +void find(typename int&); // { dg-error "6:variable or field .find. declared void" } +// { dg-error "expected" "" { target *-*-* } .-1 } Index: testsuite/g++.dg/spellcheck-typenames.C =================================================================== --- testsuite/g++.dg/spellcheck-typenames.C (revision 274945) +++ testsuite/g++.dg/spellcheck-typenames.C (working copy) @@ -4,10 +4,10 @@ void test_1 (signed char e); /* PR c/70339. */ -void test_2 (singed char e); // { dg-error "21: variable or field 'test_2' declared void" } +void test_2 (singed char e); // { dg-error "6: variable or field 'test_2' declared void" } /* { dg-begin-multiline-output "" } void test_2 (singed char e); - ^~~~ + ^~~~~~ { dg-end-multiline-output "" } */ // { dg-message "14: 'singed' was not declared in this scope; did you mean 'signed'\\?" "" { target *-*-* } 7 } /* { dg-begin-multiline-output "" } @@ -16,10 +16,10 @@ void test_1 (signed char e); signed { dg-end-multiline-output "" } */ -void test_3 (car e); // { dg-error "14: variable or field 'test_3' declared void" } +void test_3 (car e); // { dg-error "6: variable or field 'test_3' declared void" } /* { dg-begin-multiline-output "" } void test_3 (car e); - ^~~ + ^~~~~~ { dg-end-multiline-output "" } */ // { dg-message "14: 'car' was not declared in this scope; did you mean 'char'\\?" "" { target *-*-* } 19 } /* { dg-begin-multiline-output "" }