From patchwork Tue Aug 6 12:28:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1142754 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-506313-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="kBrTQE4L"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="IMs2urJl"; 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 462v7w669Kz9sDB for ; Tue, 6 Aug 2019 22:28:58 +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=cIQlvrI2AryZLVns47+Eoj2A17CEOEL7ORvLOXASNcVi1oa6xF gVuVG1o69wBhblMvt3rkJapwUDy2hJFbxMi3o4nZs0tczp2WEVuaP39yeT0aUDyl jcZhpLEov4xGu6yICVu7KF73CImeey1fTuUsgg2FmjOVrhX1Z029AUyas= 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=t/1TtoKdFq6Wq9cUbe+f1WtJjhw=; b=kBrTQE4LpHPwGVn34/9D dBhMqbH1K94YQcGh7CYgYc3bGnYxIyGaznoO1NIvdkH0BHtbu4PIuj3jZffkwaq0 8b57kgJ8KOpzSyJ0bbu2JQKS3uF7IQF+aJN4oXVVpslcjTLGNme+T10ruR5ouH5f Kr0tOpAOmuoUn7Zv95kddLo= Received: (qmail 23959 invoked by alias); 6 Aug 2019 12:28:50 -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 23950 invoked by uid 89); 6 Aug 2019 12:28:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.4 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= 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; Tue, 06 Aug 2019 12:28:48 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x76CNjme021296; Tue, 6 Aug 2019 12:28:47 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=aB+2yOBUy+dP6lF7Qm8FHCbs7zXSWFXBl0DxfiAR7yk=; b=IMs2urJlwXr0Iwn0GAMKW4rzOCXU2L0PDD0aYYqcGtJTInveUPSxdjpd29MRziU+4g48 iWcY8L2lgj/owJdSkt10SpAzTSTDVgSfJa+WBbP7zvvBBHi4XAfsjPR2eQNnMZn60LS2 ZBGfqC3SEhqgEZ5NP+DaTRkXBCxu4z6Jl4gechF5S9o1XfN+PLiWsw+sBG8yApYPO89d D/voayNl87ahX9qpN5829j0FDXkOcRjDQPQmMQwWPcrFIr7ZJnQe6pwlWPoN3wofWgM8 j9Hf4Yspj+2Y6U33nEN8UCi+pknks381otAqGenqdpRWkQAfCxIr4j7nUR/Pu9JLUjl0 9A== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2u51ptww42-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 06 Aug 2019 12:28:46 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x76CSCUQ162846; Tue, 6 Aug 2019 12:28:46 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 2u7576y73a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 06 Aug 2019 12:28:46 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x76CSjen023426; Tue, 6 Aug 2019 12:28:45 GMT Received: from [192.168.1.4] (/95.247.231.7) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 06 Aug 2019 05:28:44 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Improve start_function and grokmethod locations Message-ID: Date: Tue, 6 Aug 2019 14:28:42 +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, apparently this is now easy to do, likely because a while ago I made sure that we consistently have meaningful locations for TYPE_DECLs too. (I went through grokdeclarator and confirmed that when the third argument is FUNCDEF or MEMFUNCDEF it cannot return NULL_TREE) Tested x86_64-linux. Thanks, Paolo. //////////////////////// /cp 2019-08-06 Paolo Carlini * decl.c (start_function): Use DECL_SOURCE_LOCATION. (grokmethod): Likewise. /testsuite 2019-08-06 Paolo Carlini * g++.dg/parse/typedef9.C: Test locations too. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 274141) +++ cp/decl.c (working copy) @@ -15774,9 +15774,10 @@ start_function (cp_decl_specifier_seq *declspecs, return false; /* If the declarator is not suitable for a function definition, cause a syntax error. */ - if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) + if (TREE_CODE (decl1) != FUNCTION_DECL) { - error ("invalid function declaration"); + error_at (DECL_SOURCE_LOCATION (decl1), + "invalid function declaration"); return false; } @@ -16433,9 +16434,10 @@ grokmethod (cp_decl_specifier_seq *declspecs, if (fndecl == error_mark_node) return error_mark_node; - if (fndecl == NULL || TREE_CODE (fndecl) != FUNCTION_DECL) + if (TREE_CODE (fndecl) != FUNCTION_DECL) { - error ("invalid member function declaration"); + error_at (DECL_SOURCE_LOCATION (fndecl), + "invalid member function declaration"); return error_mark_node; } Index: testsuite/g++.dg/parse/typedef9.C =================================================================== --- testsuite/g++.dg/parse/typedef9.C (revision 274140) +++ testsuite/g++.dg/parse/typedef9.C (working copy) @@ -1,8 +1,8 @@ // PR c++/38794 // { dg-do compile } -typedef void foo () {} // { dg-error "invalid function declaration" } +typedef void foo () {} // { dg-error "14:invalid function declaration" } struct S { - typedef int bar (void) { return 0; } // { dg-error "invalid member function declaration" } + typedef int bar (void) { return 0; } // { dg-error "15:invalid member function declaration" } };