From patchwork Fri Jul 5 14:43:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 257181 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 9D3EB2C0098 for ; Sat, 6 Jul 2013 00:43:37 +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=SxSYbzY5b7hATa1JWXds+reXgjYPG/hiNRbzqcvkZET 3NiFrhnky+n3Cq7ldlwLvhg0X+Ee9ouQolcqv66DKAIYuNXr+pv+PYIckOHGV1fH 3yi0LYT7RCRoIasyLHhG2Kks7iyhnCLZyMXNDSC8uss6PYIkwFqVCtid4CGF7mD8 = 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=wUNQAKLscUQit6koIa19CY8pO8A=; b=y0Pa+I3iQG32cAebM /vYHVsJm++CDFmYdviug222dN2O++uZLBTSxy1BUbZ+tiQrXMklGtMWaX6L/6b/8 IdN/L6YSChBFIu7A5NI6y8hhhg5UxSjPSNcJrkAsDeTd1VuROH042D5bAfBHKnsY lAL3QD/S03hGFAPN19Wr76chD0= Received: (qmail 8044 invoked by alias); 5 Jul 2013 14:43: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 8034 invoked by uid 89); 5 Jul 2013 14:43:30 -0000 X-Spam-SWARE-Status: No, score=-5.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_HOSTKARMA_NO, RP_MATCHES_RCVD, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 05 Jul 2013 14:43:29 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r65EhQnk013165 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Jul 2013 14:43:27 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r65EhPx9015211 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 5 Jul 2013 14:43:26 GMT Received: from abhmt119.oracle.com (abhmt119.oracle.com [141.146.116.71]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r65EhPTj023502; Fri, 5 Jul 2013 14:43:25 GMT Received: from poldo4.casa (/79.47.195.146) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 05 Jul 2013 07:43:25 -0700 Message-ID: <51D6DB8A.7030507@oracle.com> Date: Fri, 05 Jul 2013 16:43:22 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill , Gabriel Dos Reis Subject: [C++ Patch] PR 14263 X-Virus-Found: No Hi, this issue dates back to 2004 and got stalled pretty soon. Essentially Gaby wanted to see *dynamic_cast* explicitly mentioned in this kind of diagnostic (we used to explicitly talk about static_cast), whereas Mark found the current status an improvement over the past, proposed some further, minor, improvements (which I tried to implement in the below) Today I noticed that current ICC, clang, OracleStudio, all produce diagnostic quite similar, modulo the latter improvements, to GCC and decided to explore whether Gaby (and Jason) would like to reassess the bug, whether today we want to talk about dynamic_cast. Tested x86_64-linux. Thanks, Paolo. //////////////////////////// /cp 2013-07-05 Paolo Carlini PR c++/14263 * class.c (build_base_path): Improve diagnostic. /testsuite 2013-07-05 Paolo Carlini PR c++/14263 * g++.dg/inherit/virtual10.C: New. Index: cp/class.c =================================================================== --- cp/class.c (revision 200681) +++ cp/class.c (working copy) @@ -291,9 +291,31 @@ build_base_path (enum tree_code code, if (code == MINUS_EXPR && v_binfo) { if (complain & tf_error) - error ("cannot convert from base %qT to derived type %qT via " - "virtual base %qT", BINFO_TYPE (binfo), BINFO_TYPE (d_binfo), - BINFO_TYPE (v_binfo)); + { + if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (v_binfo))) + { + if (want_pointer) + error ("cannot convert from pointer to base %qT to pointer " + "to derived type %qT because the base is virtual", + BINFO_TYPE (binfo), BINFO_TYPE (d_binfo)); + else + error ("cannot convert from base %qT to derived type %qT " + "because the base is virtual", BINFO_TYPE (binfo), + BINFO_TYPE (d_binfo)); + } + else + { + if (want_pointer) + error ("cannot convert from pointer to base %qT to pointer " + "to derived type %qT via virtual base %qT", + BINFO_TYPE (binfo), BINFO_TYPE (d_binfo), + BINFO_TYPE (v_binfo)); + else + error ("cannot convert from base %qT to derived type %qT via " + "virtual base %qT", BINFO_TYPE (binfo), + BINFO_TYPE (d_binfo), BINFO_TYPE (v_binfo)); + } + } return error_mark_node; } Index: testsuite/g++.dg/inherit/virtual10.C =================================================================== --- testsuite/g++.dg/inherit/virtual10.C (revision 0) +++ testsuite/g++.dg/inherit/virtual10.C (working copy) @@ -0,0 +1,11 @@ +// PR c++/14263 + +struct A { }; + +struct B : virtual A { }; + +int main() +{ + A* p = new B; + B* q = static_cast(p); // { dg-error "cannot convert from pointer to base 'A' to pointer to derived type 'B' because the base is virtual" } +}