From patchwork Wed Jul 10 10:51:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 258010 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id C579C2C02A9 for ; Wed, 10 Jul 2013 20:52:03 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=eO6reVMPkINB7/cU1 JRDNeGySM7W+mpYMUYabc5Ny7attB036k6jQnB91F3v1K/VFv5uYysyV87lPPZDw lm08ljjaLxf1tsXVzTYV/niH55yx97xZYrEB0bEpx9QYMYxJbO6AqSWm3321v7Go BLvvhyMhE6cKju1bNUeV56ZhtQ= 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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=FSphPoWBIV9z0wg78k5mjIh 9WTA=; b=yK43BuRZVATV5WKTIQEj4EID5CIj3hmEIIYJEbPK8y332o2LhyyE4Ut uxOFx2WQVXjg9Q6XzsI/xrnVpKFewUYCRtk5dfKfK+uJvp+BgNJeQTiKenzWHglM o30y/+VgDbruw/wP5RRN7eJ6GRVf3zXggoT8FxsPjIZLtSreESJM= Received: (qmail 1871 invoked by alias); 10 Jul 2013 10:51:54 -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 1861 invoked by uid 89); 10 Jul 2013 10:51:54 -0000 X-Spam-SWARE-Status: No, score=-6.1 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED, RCVD_IN_DNSWL_MED, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 10 Jul 2013 10:51:53 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r6AApo6W017438 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 10 Jul 2013 10:51:51 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r6AApn5P009139 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 10 Jul 2013 10:51:49 GMT Received: from abhmt109.oracle.com (abhmt109.oracle.com [141.146.116.61]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r6AApnSj002870; Wed, 10 Jul 2013 10:51:49 GMT Received: from poldo4.casa (/79.47.211.35) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 10 Jul 2013 03:51:48 -0700 Message-ID: <51DD3CC2.8000407@oracle.com> Date: Wed, 10 Jul 2013 12:51:46 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: Jason Merrill CC: "gcc-patches@gcc.gnu.org" Subject: Re: [C++ Patch] PR 57869 References: <51DCA0B8.9020502@oracle.com> <51DCAD60.4020901@redhat.com> In-Reply-To: <51DCAD60.4020901@redhat.com> X-Virus-Found: No Hi, On 07/10/2013 02:40 AM, Jason Merrill wrote: > On 07/09/2013 07:46 PM, Paolo Carlini wrote: >> Daniel noticed that, per to the resolution of DR195, we shouldn't warn >> in c++11 mode, not even with -pedantic, for this kind of >> reinterpret_cast (*). Straightforward change tested x86_64-linux, not >> sure if we want to do something slightly different for C++98, or >> something more. > > I think we should apply DR195 to C++98, too. We might add the warning > to a new -Wconditionally-supported flag that could later warn about > other conditionally-supported constructs as well. Ok. I prepared the below, tested x86_64-linux, the wording is quite terse. Thanks, Paolo. //////////////// /c-family 2013-07-10 Paolo Carlini PR c++/57869 * c.opt: Add Wconditionally-supported. /cp 2013-07-10 Paolo Carlini PR c++/57869 * typeck.c (build_reinterpret_cast_1): With -Wconditionally-supported warn about casting between pointer-to-function and pointer-to-object. /gcc 2013-07-10 Paolo Carlini PR c++/57869 * doc/invoke.texi: Document -Wconditionally-supported. /testsuite 2013-07-10 Paolo Carlini PR c++/57869 * g++.dg/cpp0x/reinterpret_cast1.C: New. * g++.dg/warn/Wconditionally-supported-1.C: Likewise. * g++.dg/conversion/dr195.C: Update. * g++.dg/expr/cast2.C: Likewise. Index: c-family/c.opt =================================================================== --- c-family/c.opt (revision 200867) +++ c-family/c.opt (working copy) @@ -319,6 +319,10 @@ Wcomments C ObjC C++ ObjC++ Warning Alias(Wcomment) Synonym for -Wcomment +Wconditionally-supported +C++ ObjC++ Var(warn_conditionally_supported) Warning +Warn for conditionally-supported constructs + Wconversion C ObjC C++ ObjC++ Var(warn_conversion) Warning Warn for implicit type conversions that may change a value Index: cp/typeck.c =================================================================== --- cp/typeck.c (revision 200867) +++ cp/typeck.c (working copy) @@ -6722,12 +6722,12 @@ build_reinterpret_cast_1 (tree type, tree expr, bo else if ((TYPE_PTRFN_P (type) && TYPE_PTROBV_P (intype)) || (TYPE_PTRFN_P (intype) && TYPE_PTROBV_P (type))) { - if (pedantic && (complain & tf_warning)) - /* Only issue a warning, as we have always supported this - where possible, and it is necessary in some cases. DR 195 - addresses this issue, but as of 2004/10/26 is still in - drafting. */ - warning (0, "ISO C++ forbids casting between pointer-to-function and pointer-to-object"); + if (complain & tf_warning) + /* C++11 5.2.10 p8 says that "Converting a function pointer to an " + object pointer type or vice versa is conditionally-supported." */ + warning (OPT_Wconditionally_supported, + "casting between pointer-to-function and pointer-to-object " + "is conditionally-supported"); return fold_if_not_in_template (build_nop (type, expr)); } else if (TREE_CODE (type) == VECTOR_TYPE) Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 200867) +++ doc/invoke.texi (working copy) @@ -237,7 +237,7 @@ Objective-C and Objective-C++ Dialects}. -Waggressive-loop-optimizations -Warray-bounds @gol -Wno-attributes -Wno-builtin-macro-redefined @gol -Wc++-compat -Wc++11-compat -Wcast-align -Wcast-qual @gol --Wchar-subscripts -Wclobbered -Wcomment @gol +-Wchar-subscripts -Wclobbered -Wcomment -Wconditionally-supported @gol -Wconversion -Wcoverage-mismatch -Wno-cpp -Wno-deprecated @gol -Wno-deprecated-declarations -Wdisabled-optimization @gol -Wno-div-by-zero -Wdouble-promotion -Wempty-body -Wenum-compare @gol @@ -4393,6 +4393,11 @@ programs. Warn for variables that might be changed by @samp{longjmp} or @samp{vfork}. This warning is also enabled by @option{-Wextra}. +@item -Wconditionally-supported @r{(C++ and Objective-C++ only)} +@opindex Wconditionally-supported +@opindex Wno-conditionally-supported +Warn for conditionally-supported (C++11 [intro.defs]) constructs. + @item -Wconversion @opindex Wconversion @opindex Wno-conversion Index: testsuite/g++.dg/conversion/dr195.C =================================================================== --- testsuite/g++.dg/conversion/dr195.C (revision 200867) +++ testsuite/g++.dg/conversion/dr195.C (working copy) @@ -1,11 +1,12 @@ // Copyright (C) 2004 Free Software Foundation, Inc. // Contributed by Nathan Sidwell 20 Oct 2004 -// DR 195 will allow conversions between function and object pointers -// under some circumstances. It is in drafting, so we don't implement -// it (yet). +// DR 195 was about allowing conversions between function and object +// pointers under some circumstances. The issue got resolved for C++11, +// which, in 5.2.10 p8 says that: "Converting a function pointer to an +// object pointer type or vice versa is conditionally-supported." */ -// This checks we warn when being pedantic. +// This checks we don't warn anymore with -pedantic. typedef void (*PF)(void); typedef void *PV; @@ -18,12 +19,12 @@ void foo () PO po; /* the following two will almost definitly be ok with 195. */ - pf = reinterpret_cast (pv); // { dg-warning "casting between" "" } - pv = reinterpret_cast (pf); // { dg-warning "casting between" "" } + pf = reinterpret_cast (pv); + pv = reinterpret_cast (pf); /* the following two might or might not be ok with 195. */ - pf = reinterpret_cast (po); // { dg-warning "casting between" "" } - po = reinterpret_cast (pf); // { dg-warning "casting between" "" } + pf = reinterpret_cast (po); + po = reinterpret_cast (pf); /* These will never be ok, as they are implicit. */ pv = pf; // { dg-error "invalid conversion" "" } Index: testsuite/g++.dg/cpp0x/reinterpret_cast1.C =================================================================== --- testsuite/g++.dg/cpp0x/reinterpret_cast1.C (revision 0) +++ testsuite/g++.dg/cpp0x/reinterpret_cast1.C (working copy) @@ -0,0 +1,6 @@ +// PR c++/57869 +// { dg-do compile { target c++11 } } + +void* po = 0; +void (*pf)() = reinterpret_cast(po); +static_assert(sizeof(po) >= sizeof(pf), "Conversion not supported"); Index: testsuite/g++.dg/expr/cast2.C =================================================================== --- testsuite/g++.dg/expr/cast2.C (revision 200867) +++ testsuite/g++.dg/expr/cast2.C (working copy) @@ -1,5 +1,5 @@ void (*p)(); void f() { - (void *)p; // { dg-warning "forbids cast" } + (void *)p; } Index: testsuite/g++.dg/warn/Wconditionally-supported-1.C =================================================================== --- testsuite/g++.dg/warn/Wconditionally-supported-1.C (revision 0) +++ testsuite/g++.dg/warn/Wconditionally-supported-1.C (working copy) @@ -0,0 +1,25 @@ +// { dg-options "-Wconditionally-supported" } + +// DR 195 was about allowing conversions between function and object +// pointers under some circumstances. The issue got resolved for C++11, +// which, in 5.2.10 p8 says that: "Converting a function pointer to an +// object pointer type or vice versa is conditionally-supported." */ + +// This checks we warn with -Wconditionally-supported. + +typedef void (*PF)(void); +typedef void *PV; +typedef int *PO; + +void foo () +{ + PF pf; + PV pv; + PO po; + + pf = reinterpret_cast (pv); // { dg-warning "conditionally-supported" } + pv = reinterpret_cast (pf); // { dg-warning "conditionally-supported" } + + pf = reinterpret_cast (po); // { dg-warning "conditionally-supported" } + po = reinterpret_cast (pf); // { dg-warning "conditionally-supported" } +}