From patchwork Sun Jan 13 23:21:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1024172 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-493969-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="TgTg1Uqk"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="3RfSYgbp"; 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 43dCKn63tZz9s3q for ; Mon, 14 Jan 2019 10:21:48 +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=QE4lOSF0OlZPnBRNhROFnSB2TgkAe43ZffDHdaM4S/zhayHP/R Cq6wu0ou3y9Q8Df71Krw4GQfKznbIPkmiawcAvyFfxn9rEo5+WXjawKm18yi+ib2 uCr3XKaihm99U1WV+Vc1/hF6DW/sUg5iUtcjz8uZuwvF6Ef2Sqd6BlGnY= 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=CJgt6lM1yUBB1cmQkgYttR0JktA=; b=TgTg1UqkQWwP/VO8nUnx va+W3Rz1nrH9m1z/bhhARkCoQqydXq5pKKdTufAvbAukiGwkMRnCaJhltHDm2HvQ 5AlG/YuOxetOamu9z/Q6+3pX4gDsuc8LPbfMpKu9zxwECmWOmgAuDyGAehL/Aqxc Mdx5cp2NZ/Ye5LI4859e0mE= Received: (qmail 75507 invoked by alias); 13 Jan 2019 23:21:40 -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 75498 invoked by uid 89); 13 Jan 2019 23:21:40 -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, SPF_PASS autolearn=ham version=3.3.2 spammy=realized, famous X-HELO: aserp2130.oracle.com Received: from aserp2130.oracle.com (HELO aserp2130.oracle.com) (141.146.126.79) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 13 Jan 2019 23:21:38 +0000 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0DNJ6HZ052984; Sun, 13 Jan 2019 23:21:36 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=Vh8VUtar1KH412UvSSD2iASHDxaCzN8i0qJlaoZRW+E=; b=3RfSYgbpTNNkKoVs3MNVzTttQfXQDEo/x5IIYjtDgLFM0neyHdHvw6gb1nEDtKQUqgee slBO+EDlnCAGjITcTOKmYuNeWQy6VeK/jwVQhk7QyyPdCIdJ3eqUbtWG5lX3I+xVXoiX QX7IfhBcCUkGc9JZ4iV8IQnwpzz3SiQbCk4O9P2qviYdMvgueJ/pko8zQLitSXcEMFT0 KVy+QwGRga+vuIE2fmWzu8nI0M8uus81casPYdo84ySnLoCJC0T1URW75tJvW68rrXyG oaXX6vsdEZyzMBoAViQSLf/mKbVJzvlZndG6PJRcjzwiViFUmPtR5z31ugx4+//jzTyC OQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2pybjnav9g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 13 Jan 2019 23:21:35 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x0DNLYju025955 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 13 Jan 2019 23:21:34 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x0DNLXeM013366; Sun, 13 Jan 2019 23:21:33 GMT Received: from [192.168.1.4] (/79.19.31.237) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 13 Jan 2019 15:21:32 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Improve grokbitfield location Message-ID: <539bc022-1091-48d9-1b0a-4c53f7c1891e@oracle.com> Date: Mon, 14 Jan 2019 00:21:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, today I realized that if we move further up the "famous" location_t loc declaration in grokdeclarator we can often pass a precise location when building TYPE_DECLs for typedef names too, thus, in particular, profitably use DECL_SOURCE_LOCATION in a grokbitfield error and also enabling further improvements. Tested x86_64-linux. Thanks, Paolo. /////////////////////// /cp 2019-01-13 Paolo Carlini * decl.c (grokdeclarator): Move further up the location_t loc declaration and use the location when building a TYPE_DECL for a typedef name. * decl2.c (grokbitfield): Use DECL_SOURCE_LOCATION in the error about an ill-formed typedef as bit-field. /testsuite 2019-01-13 Paolo Carlini * g++.dg/diagnostic/bitfld3.C: New. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 267903) +++ cp/decl.c (working copy) @@ -11933,6 +11934,8 @@ grokdeclarator (const cp_declarator *declarator, } } + location_t loc = declarator ? declarator->id_loc : input_location; + /* If this is declaring a typedef name, return a TYPE_DECL. */ if (typedef_p && decl_context != TYPENAME) { @@ -11978,9 +11981,9 @@ grokdeclarator (const cp_declarator *declarator, } if (decl_context == FIELD) - decl = build_lang_decl (TYPE_DECL, unqualified_id, type); + decl = build_lang_decl_loc (loc, TYPE_DECL, unqualified_id, type); else - decl = build_decl (input_location, TYPE_DECL, unqualified_id, type); + decl = build_decl (loc, TYPE_DECL, unqualified_id, type); if (decl_context != FIELD) { @@ -12221,7 +12224,6 @@ grokdeclarator (const cp_declarator *declarator, { tree decl = NULL_TREE; - location_t loc = declarator ? declarator->id_loc : input_location; if (decl_context == PARM) { Index: cp/decl2.c =================================================================== --- cp/decl2.c (revision 267903) +++ cp/decl2.c (working copy) @@ -1038,7 +1039,8 @@ grokbitfield (const cp_declarator *declarator, if (TREE_CODE (value) == TYPE_DECL) { - error ("cannot declare %qD to be a bit-field type", value); + error_at (DECL_SOURCE_LOCATION (value), + "cannot declare %qD to be a bit-field type", value); return NULL_TREE; } Index: testsuite/g++.dg/diagnostic/bitfld3.C =================================================================== --- testsuite/g++.dg/diagnostic/bitfld3.C (nonexistent) +++ testsuite/g++.dg/diagnostic/bitfld3.C (working copy) @@ -0,0 +1,5 @@ +struct S +{ + typedef int i : 3; // { dg-error "15:cannot declare .i." } + typedef int : 3; // { dg-error "cannot declare" } +};