From patchwork Fri Dec 7 10:39:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1009327 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-491865-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="Ybu/yWlY"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="fgaiPZlJ"; 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 43B89b2p0Sz9s55 for ; Fri, 7 Dec 2018 21:39:46 +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=Hqdl/VOpVU/fYtCNVlnJ4O1SZQmCgjIEP/uB5J1JHRl3i3c8+2 RS9QQy5Q9vKO8o5307rfBHVDfZF647hsnRbLPrJIX6vnHYIeoNsHBrft8Iw5HLV5 9RJnD8Vi719EuJ9aFReMmhBtoZp3UFk7VCF1Vjj5sI5fet+c1dbIofwsk= 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=kKNt6bqkaJRz6pyOFlLp6XNxeZ4=; b=Ybu/yWlYNdiWGDa8TdlD x71DZdkvnIAwJ6XD/iITa9ASwlxLcNoiYC3Vape9dk1LYBamw/fbvRgxLlKAdWwY gq2bbhrhWaBokkVP/khFUsiL8F3DComDGVLXYvZE6CTBna8+7u/5YxKpyKt1EAX+ OjNQTizvs+ig61sABilwuW0= Received: (qmail 39664 invoked by alias); 7 Dec 2018 10:39:39 -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 39633 invoked by uid 89); 7 Dec 2018 10:39:37 -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=tree_static, TREE_STATIC, sk:TYPE_WA, sk:type_wa 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; Fri, 07 Dec 2018 10:39:34 +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 wB7AYLRZ150739; Fri, 7 Dec 2018 10:39:32 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=N/Or+4vXWVn5ULBfscCeDQJtSTm576qOxO756rH55nQ=; b=fgaiPZlJV3sa0H5l0NkMSyK6IWiQvxjrptIh0oZD+T92CLinvsr5tLMKBAUHYiPBGL+2 n0AkSSo2nofNsevP3qMrHRyZ6AIBbJhRf1Nr6XmuoWeKPt16D0LU5ySNG1JHdfiw0jRr fuB+16lrDFiftcq0IcMaLKp8UBgmTp9uBX7uDaPzsGYbvDach931CAec6R19odgqAqwQ Hu0IUdceS946KkKi6PNQmKFrfP23gKiV1dN5EDPP9Hu3tAQUZA4IHOwCh1zVJECbWE2T JuEE1zvdYSvIEwvy0U2kYprWJxKekyHRgVr/Ukb2s2JknG2gY1uCiGyqXrKnubOHCm2x QQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2p3hqud8xv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 Dec 2018 10:39:32 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wB7AdWF9022501 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 7 Dec 2018 10:39:32 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wB7AdVQW025461; Fri, 7 Dec 2018 10:39:31 GMT Received: from [192.168.1.4] (/80.181.224.14) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 Dec 2018 02:39:30 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Fixes for three grokbitfield diagnostics Message-ID: <03bbe624-10b0-cace-3770-f1d8e2f4bb44@oracle.com> Date: Fri, 7 Dec 2018 11:39:28 +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, these should be more or less straightforward (now that DECL_SOURCE_LOCATION often extracts a proper location ;). In the case of warn_if_not_aligned I also removed the redundant width check (it's never null, double checked by running the instrumented testsuite too) and I also removed the DECL_NAME use, which definitely doesn't play well with unnamed declarations (other/bitfield7.C exercises that too). Tested x86_64-linux, as usual. Thanks, Paolo. ////////////////////// /cp 2018-12-07 Paolo Carlini * decl2.c (grokbitfield): Use DECL_SOURCE_LOCATION in error messages about bit-fields with function type, warn_if_not_aligned type, and static bit-fields; avoid DECL_NAME for unnamed declarations. /testsuite 2018-12-07 Paolo Carlini * g++.dg/other/bitfield7.C: New. * g++.dg/parse/bitfield8.C: Likewise. * g++.dg/parse/bitfield9.C: Likewise. * g++.dg/pr53037-4.C: Test the locations too. Index: cp/decl2.c =================================================================== --- cp/decl2.c (revision 266884) +++ cp/decl2.c (working copy) @@ -1046,15 +1046,15 @@ grokbitfield (const cp_declarator *declarator, check here. */ if (TREE_CODE (value) == FUNCTION_DECL) { - error ("cannot declare bit-field %qD with function type", - DECL_NAME (value)); + error_at (DECL_SOURCE_LOCATION (value), + "cannot declare bit-field %qD with function type", value); return NULL_TREE; } - if (width && TYPE_WARN_IF_NOT_ALIGN (type)) + if (TYPE_WARN_IF_NOT_ALIGN (type)) { - error ("cannot declare bit-field %qD with % type", - DECL_NAME (value)); + error_at (DECL_SOURCE_LOCATION (value), "cannot declare bit-field " + "%qD with % type", value); return NULL_TREE; } @@ -1067,7 +1067,8 @@ grokbitfield (const cp_declarator *declarator, if (TREE_STATIC (value)) { - error ("static member %qD cannot be a bit-field", value); + error_at (DECL_SOURCE_LOCATION (value), + "static member %qD cannot be a bit-field", value); return NULL_TREE; } Index: testsuite/g++.dg/other/bitfield7.C =================================================================== --- testsuite/g++.dg/other/bitfield7.C (nonexistent) +++ testsuite/g++.dg/other/bitfield7.C (working copy) @@ -0,0 +1,7 @@ +typedef int __attribute__((warn_if_not_aligned(8))) intwna; + +struct S +{ + intwna : 2; // { dg-error "cannot declare bit-field" } + intwna i : 2; // { dg-error "10:cannot declare bit-field .i." } +}; Index: testsuite/g++.dg/parse/bitfield8.C =================================================================== --- testsuite/g++.dg/parse/bitfield8.C (nonexistent) +++ testsuite/g++.dg/parse/bitfield8.C (working copy) @@ -0,0 +1,4 @@ +struct A +{ + static int a : 1; // { dg-error "14:static member .a. cannot be a bit-field" } +}; Index: testsuite/g++.dg/parse/bitfield9.C =================================================================== --- testsuite/g++.dg/parse/bitfield9.C (nonexistent) +++ testsuite/g++.dg/parse/bitfield9.C (working copy) @@ -0,0 +1,6 @@ +template +struct A +{ + typedef T type(); + type i : 2; // { dg-error "8:cannot declare bit-field" } +}; Index: testsuite/g++.dg/pr53037-4.C =================================================================== --- testsuite/g++.dg/pr53037-4.C (revision 266884) +++ testsuite/g++.dg/pr53037-4.C (working copy) @@ -12,7 +12,7 @@ foo2 (void) /* { dg-error "'warn_if_not_aligned' m struct foo3 { - int i : 2 __attribute__((warn_if_not_aligned(8))); /* { dg-error "'warn_if_not_aligned' may not be specified for 'i'" } */ + int i : 2 __attribute__((warn_if_not_aligned(8))); /* { dg-error "7:'warn_if_not_aligned' may not be specified for 'i'" } */ }; typedef unsigned int __u32 @@ -20,5 +20,5 @@ typedef unsigned int __u32 struct foo4 { - __u32 i : 2; /* { dg-error "cannot declare bit-field 'i' with 'warn_if_not_aligned' type" } */ + __u32 i : 2; /* { dg-error "9:cannot declare bit-field 'i' with 'warn_if_not_aligned' type" } */ };