From patchwork Sat Aug 4 22:55:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 175146 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]) by ozlabs.org (Postfix) with SMTP id 616A92C0084 for ; Sun, 5 Aug 2012 08:56:00 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1344725761; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Message-ID:Date:From:User-Agent:MIME-Version: To:CC:Subject:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=eSVQqod5ScF8OlTRANr7H1LqCRk=; b=MvoaLfA3s97rr+z p90bjVQKArHTx39csKS27Viai28zxj9ESvUEeXpPSnGiJZEHI17rhmHdc0FX5W+F n6bIn5XW+4vX7Lio7gf999wHaO2QzlXfHd5+3y7Sxiw8TOi+qoT0JxrMnYjbSfI9 ZJfH0N+jRaaQ/bt6Et3+KTw6sxRY= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=K1stUhdTwKjxIXBcPuMsyja6CHSEn7W/DmwNaKHSbMRC9FFkp2wLQmGZcbiLwM wUkyVN9ebDFX+g2a71Yb0Jrzsk07YCs9jC7CpWQc473WhPsaCnkA1BBzekWv7jIZ 6d7NIALYnCSp4bxnK3o+yk9emMlijOYrmkbp8m2P57ekE=; Received: (qmail 11554 invoked by alias); 4 Aug 2012 22:55:56 -0000 Received: (qmail 11542 invoked by uid 22791); 4 Aug 2012 22:55:55 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rcsinet15.oracle.com (HELO rcsinet15.oracle.com) (148.87.113.117) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 04 Aug 2012 22:55:42 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by rcsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q74Mtfwr010612 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 4 Aug 2012 22:55:41 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q74Mteu2021026 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 4 Aug 2012 22:55:40 GMT Received: from abhmt119.oracle.com (abhmt119.oracle.com [141.146.116.71]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q74MtenW031117; Sat, 4 Aug 2012 17:55:40 -0500 Received: from [192.168.1.4] (/79.33.217.9) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 04 Aug 2012 15:55:40 -0700 Message-ID: <501DA869.6090004@oracle.com> Date: Sun, 05 Aug 2012 00:55:37 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 54165 X-IsSubscribed: yes 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 Hi, Marc noticed that this issue, where we are using an available templated conversion function for a cast to void, apparently can be rather easily attacked by moving the convert_to_void case a bit earlier in build_static_cast_1, that is before the perform_direct_initialization_if_possible call. I had a cursory look to other uses of convert_to_void elsewhere, actually moved the code, booted and tested successfully on x86_64-linux. Makes sense? Thanks, Paolo. /////////////////////////////// /cp 2012-08-05 Marc Glisse Paolo Carlini PR c++/54165 * typeck.c (build_static_cast_1): Move the conversion to void case before the perform_direct_initialization_if_possible call. /testsuite 2012-08-05 Marc Glisse Paolo Carlini PR c++/54165 * g++.dg/conversion/void2.C: New. Index: testsuite/g++.dg/conversion/void2.C =================================================================== --- testsuite/g++.dg/conversion/void2.C (revision 0) +++ testsuite/g++.dg/conversion/void2.C (revision 0) @@ -0,0 +1,16 @@ +// PR c++/54165 + +struct A +{ + template + operator T() + { + T l[]; + } +}; + +int main() +{ + A a; + (void)a; +} Index: cp/typeck.c =================================================================== --- cp/typeck.c (revision 190144) +++ cp/typeck.c (working copy) @@ -6053,6 +6053,12 @@ build_static_cast_1 (tree type, tree expr, bool c_ /* [expr.static.cast] + Any expression can be explicitly converted to type cv void. */ + if (TREE_CODE (type) == VOID_TYPE) + return convert_to_void (expr, ICV_CAST, complain); + + /* [expr.static.cast] + An expression e can be explicitly converted to a type T using a static_cast of the form static_cast(e) if the declaration T t(e);" is well-formed, for some invented temporary variable @@ -6074,12 +6080,6 @@ build_static_cast_1 (tree type, tree expr, bool c_ /* [expr.static.cast] - Any expression can be explicitly converted to type cv void. */ - if (TREE_CODE (type) == VOID_TYPE) - return convert_to_void (expr, ICV_CAST, complain); - - /* [expr.static.cast] - The inverse of any standard conversion sequence (clause _conv_), other than the lvalue-to-rvalue (_conv.lval_), array-to-pointer (_conv.array_), function-to-pointer (_conv.func_), and boolean