From patchwork Tue Apr 10 18:57:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 896895 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-476165-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="PuUcOR7k"; 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 40LGdH38mQz9s0v for ; Wed, 11 Apr 2018 04:57:37 +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=bgn5tuSex5yCD8yklby5rUXYZPY+reOZC0sxEs0UK7XN0mk3lM AS8npDF6tVTIQfdJPdBq9wle++GZ3lOeimks1EAAMGATR1O2EJaloHBF3bJJQxLF BPv/de2xZ43RVW5UuUHaL9JOusgfc+czSAC41ej9uS23NTQZQTN9hmhVo= 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=+mMa+uxQB9vl0eD9+aCQHNSfF8w=; b=PuUcOR7kFe+KuzsXHTj5 c3FIoQ111p3uOgZt/Pg8ZLxYpdL7cbChMkBQZzvGkj5jg/crVHWCQSGUICDDOq/9 5ZiYv1Tobsu/pyOo2tcXcmCBGF+XdfnGTYtYpeeKW4dA9vQ2VLE9lfSEQ0RQkJFG i7rGhUF72ZZnheTJsR7QlNU= Received: (qmail 66132 invoked by alias); 10 Apr 2018 18:57:30 -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 66113 invoked by uid 89); 10 Apr 2018 18:57:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=sheer, letter, our 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, 10 Apr 2018 18:57:28 +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 w3AIuU8W106654; Tue, 10 Apr 2018 18:57:26 GMT Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2h6pn4kns2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Apr 2018 18:57:26 +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 w3AIvQlr023102 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Apr 2018 18:57:26 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w3AIvPH7030902; Tue, 10 Apr 2018 18:57:25 GMT Received: from [192.168.1.4] (/79.53.236.120) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 10 Apr 2018 11:57:25 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] PR 70808 ("Spurious -Wzero-as-null-pointer-constant for nullptr_t") Message-ID: Date: Tue, 10 Apr 2018 20:57:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8859 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=775 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804100180 X-IsSubscribed: yes Hi, this isn't a regression, but deciding what we want to do should be easy and quick enough. The issue is that "mysteriously" we warn -Wzero-as-null-pointer-constant for: decltype( nullptr ) warn = {}; and we don't for: int* no_warn = {}; That's easily explained given the code we have in build_zero_init_1 which handles types satisfying TYPE_PTR_OR_PTRMEM_P separately from all the other scalar types, std::nullptr_t included. I think we should resolve the inconsistency - the below does that without regressions - but frankly, at first, given the letter of the standard under 11.6/6 about zero-initialization I expected that we weren't handling types satisfying TYPE_PTR_OR_PTRMEM_P in a different way, thus something like a sheer integer_zero_node consistently for all the scalars (which would mean resolving the inconsistency precisely the other way round). Probably it's a tricky detail of our internal representations... Thanks, Paolo. /////////////////// /cp 2018-04-10 Paolo Carlini PR c++/70808 * init.c (build_zero_init_1): Handle NULLPTR_TYPE_P being true of the type like TYPE_PTR_OR_PTRMEM_P. /testsuite 2018-04-10 Paolo Carlini PR c++/70808 * g++.dg/warn/Wzero-as-null-pointer-constant-7.C: New. Index: cp/init.c =================================================================== --- cp/init.c (revision 259287) +++ cp/init.c (working copy) @@ -180,7 +180,7 @@ build_zero_init_1 (tree type, tree nelts, bool sta items with static storage duration that are not otherwise initialized are initialized to zero. */ ; - else if (TYPE_PTR_OR_PTRMEM_P (type)) + else if (TYPE_PTR_OR_PTRMEM_P (type) || NULLPTR_TYPE_P (type)) init = fold (convert (type, nullptr_node)); else if (SCALAR_TYPE_P (type)) init = fold (convert (type, integer_zero_node)); Index: testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-7.C =================================================================== --- testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-7.C (nonexistent) +++ testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-7.C (working copy) @@ -0,0 +1,5 @@ +// PR c++/70808 +// { dg-options "-Wzero-as-null-pointer-constant" } + +int* no_warn = {}; +decltype( nullptr ) warn = {};