From patchwork Tue Jul 9 23:46:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 257912 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 E5D922C0174 for ; Wed, 10 Jul 2013 09:46:15 +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:content-type; q=dns; s=default; b=B/z2bh7fKDbThSaM/pq5IswyM0LWrqVqOoIGlKiMl43 h2YHV+yQXWt4TS2iWaTdboX7OZcUCokNDgmZ/X0n2C5QOQCopkD/JPc7FiN4GtCn RlcxatPmawqYYj2jGuh7FyR7qDTRUY10YERN/9P5zUl2AfxXxYQkWXtqFLW/F+Rg = 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:content-type; s=default; bh=dzwPW0tE9g+xLN+br1tLUweWgDI=; b=fZhFANu9ANuEvO/JG nAb5SaAOc7vkNeo/KTY+WYL7E4yUVgpBt6oQnNjC0bRWHTUv+Ixl1tok/ohyW69S 1potgFmcaH2rdn8axHAkvptxL7/ZmKLPORVyBd9IDk1ldhzdCL5PUV6+OOn2l4gR QERIfvon30cDowLVmOdWVmefN4= Received: (qmail 24524 invoked by alias); 9 Jul 2013 23:46:10 -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 24515 invoked by uid 89); 9 Jul 2013 23:46:09 -0000 X-Spam-SWARE-Status: No, score=-5.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, SPF_PASS, TW_CX, 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; Tue, 09 Jul 2013 23:46:08 +0000 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r69Nk5e1030989 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 9 Jul 2013 23:46:05 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r69Nk3Z4023316 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 9 Jul 2013 23:46:04 GMT Received: from abhmt103.oracle.com (abhmt103.oracle.com [141.146.116.55]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r69Nk3J4028999; Tue, 9 Jul 2013 23:46:03 GMT Received: from poldo4.casa (/79.52.192.193) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 09 Jul 2013 16:46:03 -0700 Message-ID: <51DCA0B8.9020502@oracle.com> Date: Wed, 10 Jul 2013 01:46:00 +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: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 57869 X-Virus-Found: No Hi, 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. Thanks, Paolo. (*) Current clang++ concurs. /////////////////////////// /cp 2013-07-10 Paolo Carlini PR c++/57869 * typeck.c (build_reinterpret_cast_1): In c++11 mode even with -pedantic don't warn about casting between pointer-to-function and pointer-to-object. /testsuite 2013-07-10 Paolo Carlini PR c++/57869 * g++.dg/cpp0x/reinterpret_cast1.C: New. * g++.dg/conversion/dr195.C: Update. * g++.dg/expr/cast2.C: Likewise. Index: cp/typeck.c =================================================================== --- cp/typeck.c (revision 200852) +++ cp/typeck.c (working copy) @@ -6722,12 +6722,15 @@ 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)) + if (cxx_dialect == cxx98 + && 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"); + addressed this issue, and C++11 5.2.10 p8 now says that + "Converting a function pointer to an object pointer type + or vice versa is conditionally-supported." */ + warning (0, "ISO C++ 1998 forbids casting between pointer-to-function " + "and pointer-to-object"); return fold_if_not_in_template (build_nop (type, expr)); } else if (TREE_CODE (type) == VECTOR_TYPE) Index: testsuite/g++.dg/conversion/dr195.C =================================================================== --- testsuite/g++.dg/conversion/dr195.C (revision 200852) +++ testsuite/g++.dg/conversion/dr195.C (working copy) @@ -2,10 +2,11 @@ // 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). +// 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 warn when being pedantic in c++98 mode. 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); // { dg-warning "casting between" "" { target c++98 } } + pv = reinterpret_cast (pf); // { dg-warning "casting between" "" { target c++98 } } /* 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); // { dg-warning "casting between" "" { target c++98 } } + po = reinterpret_cast (pf); // { dg-warning "casting between" "" { target c++98 } } /* 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 200852) +++ testsuite/g++.dg/expr/cast2.C (working copy) @@ -1,5 +1,5 @@ void (*p)(); void f() { - (void *)p; // { dg-warning "forbids cast" } + (void *)p; // { dg-warning "forbids cast" "" { target c++98 } } }