From patchwork Thu Dec 6 10:49:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1008696 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-491779-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="OVr7vKK2"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="XDRM7Alg"; 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 439Xg05rjZz9s6w for ; Thu, 6 Dec 2018 21:59:40 +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=lH6re2SGGoh6X8UjIDA5zKrqoXZ0bL8qYtXgghYHo9KAdxNu9p uCQ7iKiZyjnUXqciw1uoQQIcR/jjyCGj7ghvAk1y5ggbJJHuiCDa+rVmT2Ioe+Qe faMLqvQusQPuospu0baL+5VIJg36lmbHnRv0KFcY6K3x7ejmDrcfe6v5Q= 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=DpSvKODfTxs+e1Kn1Pt/rGsuZYU=; b=OVr7vKK23cYrY1wryTvZ iTkJxIYBIb7DpVEPBCZykmht1UXNKQksVcyg/TxGgynjZqz4Uln2AFDqFIAj80iM QNDO101ctSWBJkTy6PZsNtCUlmOXdLP48S+/yBkTqtuygHgIK+MtLG6EzLs70Gm+ Vahr1nktUGhwmZjB5Yr5tu8= Received: (qmail 54341 invoked by alias); 6 Dec 2018 10:52:01 -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 30781 invoked by uid 89); 6 Dec 2018 10:49:24 -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= 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; Thu, 06 Dec 2018 10:49:20 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wB6AhpOo011199; Thu, 6 Dec 2018 10:49:18 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=bHj8NYdFn98euqfU8AwWejNf8BRRAZbC9oY7ERp1/aI=; b=XDRM7AlgtZiLxPa9FCgAcIHt6hRODV8sm751aiiz6v/ZQNQPy3j8iW7G12jTupgv4YWo 6kCWp+Z8lz1m57WVRAIkuA+5BDdKj+kdfN4TXbYpvMUTzhun7PVgux8HUAMPPoccjJGz UOfKkXaddJmJ+YnY4nGyX6eS1CF4R1u7wT2bE6AjDOCMsk7XwsZfSUzmh3bHA8+jCjc3 pzhdIXPFlce3GHvf3iQPMK4LvLzjA3wdlUvXGbB3HwJM4tLvr45RVI3DWI/Y4iNtWoh7 zUr4WwtIM+ocniyMgljoOc5BaVI2zt4464dezwy3F/vD6PVdI/lzn2oA3B9aNXmH8JoK dg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2p3jxrqdgh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 06 Dec 2018 10:49:18 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wB6AnIxx008166 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Dec 2018 10:49:18 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wB6AnH6R012732; Thu, 6 Dec 2018 10:49:17 GMT Received: from [192.168.42.150] (/2.41.15.132) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 06 Dec 2018 02:49:17 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Three additional bitfield diagnostic tweaks (a regression fix included) Message-ID: Date: Thu, 6 Dec 2018 11:49:14 +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, I'm bundling together 3 more. In attachment order: 1- Since we decided to explicitly print the wrong type, I suppose we want to consistently do that in templates too. 2- Unfortunately I have to fix another buglet I recently introduced, completely similar to c++/88222 fixed by Marek. Well, at least we will not print anymore an empty '' when the unqualified_id is null because the field is unnamed. 3- In the non-static case too, when from grokdeclarator we are calling FIELD_DECL and passing the location as first argument, I think we want to likewise pass declarator->id_loc when available. The added/extended testcase exercise all of the above. Tested x86_64-linux. Thanks, Paolo. //////////////// /cp 2018-12-06 Paolo Carlini * class.c (check_bitfield_decl): In error message about non-integral type print the type itself too. * decl.c (grokdeclarator): Do not ICE on unnamed bit-fields declared friends; when calling build_decl for a FIELD_DECL possibly pass the declarator->id_loc. /testsuite 2018-12-06 Paolo Carlini * g++.dg/parse/bitfield7.C: New. * g++.dg/other/bitfield2.C: Check location and type. * g++.dg/parse/bitfield1.C: Likewise. * g++.dg/parse/bitfield2.C: Likewise. Index: cp/class.c =================================================================== --- cp/class.c (revision 266840) +++ cp/class.c (working copy) @@ -3218,7 +3218,8 @@ check_bitfield_decl (tree field) /* Detect invalid bit-field type. */ if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type)) { - error ("bit-field %q+#D with non-integral type", field); + error_at (DECL_SOURCE_LOCATION (field), + "bit-field %q#D with non-integral type %qT", field, type); w = error_mark_node; } else Index: cp/decl.c =================================================================== --- cp/decl.c (revision 266840) +++ cp/decl.c (working copy) @@ -12446,9 +12446,13 @@ grokdeclarator (const cp_declarator *declarator, { if (friendp) { - error_at (declarator->id_loc, - "%qE is neither function nor member function; " - "cannot be declared friend", unqualified_id); + if (unqualified_id && declarator) + error_at (declarator->id_loc, + "%qE is neither function nor member function; " + "cannot be declared friend", unqualified_id); + else + error ("unnamed field is neither function nor member " + "function; cannot be declared friend"); return error_mark_node; } decl = NULL_TREE; @@ -12536,7 +12540,9 @@ grokdeclarator (const cp_declarator *declarator, unqualified_id); constexpr_p = false; } - decl = build_decl (input_location, + decl = build_decl (declarator + ? declarator->id_loc + : input_location, FIELD_DECL, unqualified_id, type); DECL_NONADDRESSABLE_P (decl) = bitfield; if (bitfield && !unqualified_id) Index: testsuite/g++.dg/other/bitfield2.C =================================================================== --- testsuite/g++.dg/other/bitfield2.C (revision 266840) +++ testsuite/g++.dg/other/bitfield2.C (working copy) @@ -3,7 +3,7 @@ struct A { - double d : 2; // { dg-error "non-integral" } + double d : 2; // { dg-error "10:bit-field .d. with non-integral type .double." } A() {} ~A() {} }; Index: testsuite/g++.dg/parse/bitfield1.C =================================================================== --- testsuite/g++.dg/parse/bitfield1.C (revision 266840) +++ testsuite/g++.dg/parse/bitfield1.C (working copy) @@ -2,7 +2,7 @@ struct A { - double i : 8; // { dg-error "type" } + double i : 8; // { dg-error "10:bit-field .i. with non-integral type .double." } }; void foo(A& a) Index: testsuite/g++.dg/parse/bitfield2.C =================================================================== --- testsuite/g++.dg/parse/bitfield2.C (revision 266840) +++ testsuite/g++.dg/parse/bitfield2.C (working copy) @@ -4,7 +4,7 @@ struct X {}; struct A { - X x : 2; // { dg-error "non-integral type" } + X x : 2; // { dg-error "7:bit-field .x. with non-integral type .X." } }; struct B : A {}; @@ -19,7 +19,7 @@ C c; template struct D { - T t : 3; // { dg-error "non-integral type" } + T t : 3; // { dg-error "5:bit-field .double D\\::t. with non-integral type .double." } }; D d; // { dg-message "required" } @@ -28,7 +28,7 @@ template struct E { typedef T* U; - U t : 3; // { dg-error "non-integral type" } + U t : 3; // { dg-error "5:bit-field .t. with non-integral type .E\\::U." } }; E e; Index: testsuite/g++.dg/parse/bitfield7.C =================================================================== --- testsuite/g++.dg/parse/bitfield7.C (nonexistent) +++ testsuite/g++.dg/parse/bitfield7.C (working copy) @@ -0,0 +1,4 @@ +struct A +{ + friend int : 1; // { dg-error "unnamed field" } +};