From patchwork Sun Nov 10 20:29:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1192668 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-512904-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="dY5pGA/t"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="Jm46xlJC"; 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 47B5Gn0S1cz9sNx for ; Mon, 11 Nov 2019 07:30:06 +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:from :to:subject:date:message-id:content-type :content-transfer-encoding; q=dns; s=default; b=kjO390TWVEMOOWvn UCDP2xppl09Vex195CQqa70j1v+GGWtEyM/bAxN9VVR50QFzgsqRtXehNbToz45Z d+XnpE8yOfm2Hjr/C/zokmurKd5GNFiTr9UfdHyyw3JHDgf7HF+dPXSmVvzKp8ry H1CC/upEqhorXd8tDL4CVHEm8rc= 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:from :to:subject:date:message-id:content-type :content-transfer-encoding; s=default; bh=+z6UyPhD/FiV/J23eQNvWa e0eAI=; b=dY5pGA/tVKeRYkS6I7l2Cappf+lASQGy+fj0oX7rMm2eloHZYImQ2f fvF5A7uK14FNT9olGW78UTbrrpZvplwniELscpUDVjZvNpWdBwxUvHlXnnDwIwVt bTuAqibcw9ufAB5wx4+pHJeZ0JIZYzHrHNVJm46ZXo31eeMMapMnk= Received: (qmail 42777 invoked by alias); 10 Nov 2019 20:29:58 -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 42764 invoked by uid 89); 10 Nov 2019 20:29:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=hasnt, hasn't, H*RU:sk:relay.m, HX-Spam-Relays-External:sk:relay.m X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 10 Nov 2019 20:29:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573417794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PZxFlKyx7F1sVO6rdnfgK1YwH0AglycQOjl3PxUCnMc=; b=Jm46xlJCCfYc6assIqoqua7hrIEg6jT3hM6GdPEhjCgoxkXzNO22guNKTWr/pHrx4LiFyj uoYY+mIfaiU//BOQwGII3HwT7PGsrUVyMPEU3xhHamIaXIECck9Qy/6V96NwdUUMnylsR3 hV1VFS/fmzlZUdAMf3h3P6RwfNLo7yM= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-25-kk86vrgcPAyLqD1KI19ljA-1; Sun, 10 Nov 2019 15:29:53 -0500 Received: by mail-qv1-f69.google.com with SMTP id b6so4956004qvo.4 for ; Sun, 10 Nov 2019 12:29:53 -0800 (PST) Received: from barrymore.cygnus.csb (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id j71sm7439163qke.90.2019.11.10.12.29.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2019 12:29:51 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [C++] Implement D1957R0, T* to bool should be considered narrowing. Date: Sun, 10 Nov 2019 15:29:49 -0500 Message-Id: <20191110202949.11362-1-jason@redhat.com> X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes This paper was delayed until the February meeting in Prague so that we could get a better idea of what the impact on existing code would actually be. To that end, I'm implementing it now. Tested x86_64-pc-linux-gnu, applying to trunk. * typeck2.c (check_narrowing): Treat pointer->bool as a narrowing conversion with -std=c++2a. --- gcc/cp/typeck2.c | 5 +++ gcc/testsuite/g++.dg/cpp0x/initlist92.C | 51 +++++++------------------ 2 files changed, 18 insertions(+), 38 deletions(-) base-commit: 9b0807d9fe86b69112c4b1b65a923d685640b094 diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 7884d423a59..9fb36fd1ed3 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1018,6 +1018,11 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain, ok = true; } } + else if (TREE_CODE (type) == BOOLEAN_TYPE + && (TYPE_PTR_P (ftype) || TYPE_PTRMEM_P (ftype))) + /* This hasn't actually made it into C++20 yet, but let's add it now to get + an idea of the impact. */ + ok = (cxx_dialect < cxx2a); bool almost_ok = ok; if (!ok && !CONSTANT_CLASS_P (init) && (complain & tf_warning_or_error)) diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist92.C b/gcc/testsuite/g++.dg/cpp0x/initlist92.C index 81a63182f0e..319264ae274 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist92.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist92.C @@ -1,26 +1,13 @@ // PR c++/64665, DR 1467 -// { dg-do run { target c++11 } } +// { dg-do compile { target c++11 } } #include -#include -bool Test1(bool) -{ - return true; -} -bool Test1(std::string) -{ - return false; -} +bool Test1(bool); +bool Test1(std::string) = delete; -bool Test2(int) -{ - return false; -} -bool Test2(std::initializer_list) -{ - return true; -} +bool Test2(int) = delete; +bool Test2(std::initializer_list); struct S { @@ -28,28 +15,16 @@ struct S private: int a; }; -bool Test3(int) -{ - return true; -} -bool Test3(S) -{ - return false; -} +bool Test3(int); +bool Test3(S) = delete; -bool Test4(bool) -{ - return false; -} -bool Test4(std::initializer_list) -{ - return true; -} +bool Test4(bool) = delete; +bool Test4(std::initializer_list); int main () { - assert ( Test1({"false"}) ); - assert ( Test2({123}) ); - assert ( Test3({456}) ); - assert ( Test4({"false"}) ); + ( Test1({"false"}) ); // { dg-error "narrowing" "" { target c++2a } } + ( Test2({123}) ); + ( Test3({456}) ); + ( Test4({"false"}) ); }