From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta034.useast.a.cloudfilter.net (omta034.useast.a.cloudfilter.net [44.202.169.33]) by sourceware.org (Postfix) with ESMTPS id 18DF63858D38 for ; Fri, 8 Mar 2024 16:18:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 18DF63858D38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 18DF63858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709914726; cv=none; b=S4RAEyWa0RPl5j4kTBxaW7cvyqLGSBWghnRBnNLlDUR353MEhC0NVjcBuOsw57F3suUl7lc6zovIcW6D9S16ht6XizW1CdzqbLODod7XOrGMXGka4Z0MtuxXG9RqAkoCJvEkk3VsN4i3YNxJ12pk0LslGkJM+Ku52zurF5cDCds= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709914726; c=relaxed/simple; bh=qSYFNsaOAiqCob8vjuxbQeQypuR2ITKpTndH1f+9yIM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=v77ygS+D4FJGF/u2p82l26Uzfj9h0vI0B44LFCKeqikndSS6RvaV3eSVLvLUIm4dNceuFN2OeuRlqN9s82SPVTIvUBT5lSyRJJK2gRzWEbMDu7tLhKBGjE1oL0/TMpVxKW/NlEnUNUsdiEytCdCxPm0eS5XYBQp1J2/6V/CVhdk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6006a.ext.cloudfilter.net ([10.0.30.182]) by cmsmtp with ESMTPS id ibGarm1Ois4yTicvir34FQ; Fri, 08 Mar 2024 16:18:42 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id icvhriKzHdeujicvhrbcWf; Fri, 08 Mar 2024 16:18:41 +0000 X-Authority-Analysis: v=2.4 cv=IuQYcq/g c=1 sm=1 tr=0 ts=65eb3a61 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=K6JAEmCyrfEA:10 a=Qbun_eYptAEA:10 a=_ZhYKdCeAAAA:8 a=CCpqsmhAAAAA:8 a=dzWzf_mpAAAA:8 a=E9CcK4nxz_h2l2T5MwUA:9 a=uqOk3ZSnBfCTOznnrPA1:22 a=ul9cdbp4aOFLsgKbc677:22 a=b4DR9a7p2ZdsqdHBznES:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References :Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=6qN11yRG78hLO6yHqn0Xtol99mspmvzUCY+uc6tXqgY=; b=B0edr4XPCERn7qJIP/q2e/2Xsu 5hWT+IlJ6V4iP49c5g6tLFa9IWUaUvOPTgpGfNYdO+ihoAAjE/IBKfhZM0iev07hSWOv7sPwTv3bw qQe958CfMM0Hp8omt6wEvhzvv; Received: from 97-122-82-115.hlrn.qwest.net ([97.122.82.115]:48384 helo=murgatroyd) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1ricvg-003cxB-2D; Fri, 08 Mar 2024 09:18:40 -0700 From: Tom Tromey To: Simon Marchi Cc: Andrew Burgess , Tom de Vries , gdb-patches@sourceware.org Subject: Re: [PATCH] [gdb/build] Fix static cast of virtual base References: <20240222161804.1134-1-tdevries@suse.de> <87frx39s43.fsf@redhat.com> <1e54180b-6665-43c7-9c3c-fdf72bd29a07@polymtl.ca> X-Attribution: Tom Date: Fri, 08 Mar 2024 09:18:39 -0700 In-Reply-To: <1e54180b-6665-43c7-9c3c-fdf72bd29a07@polymtl.ca> (Simon Marchi's message of "Wed, 6 Mar 2024 13:27:50 -0500") Message-ID: <87msr8snmo.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.82.115 X-Source-L: No X-Exim-ID: 1ricvg-003cxB-2D X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-82-115.hlrn.qwest.net (murgatroyd) [97.122.82.115]:48384 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfMfkZwd8Am8w7IDFcctiTq09kag4MWZaLdf5bRtXg3y13QfDbLQtmfAWGweoTI2cTus/JZpgoEdrXE3Er0cLQYS3J/hqYfykR8EC9oKMbVv81vwkWE9x mg/NGbQjdasTwmgSmHePrYyXHR51LWSApPyv0h4DpQRoy4eRxz1VK3RbxBfNwH5XRnlTcEmb1j67ahtcBhLexfiqlTH7z1mGRrI= X-Spam-Status: No, score=-3016.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: >>>>> "Simon" == Simon Marchi writes: >> - T result = dynamic_cast (v); >> - gdb_assert (result != nullptr); >> + gdb_assert (dynamic_cast (v) != nullptr); >> + >> + /* If a base class of V is virtual then the dynamic_cast will succeed, >> + but the production mode static_cast will fail. So having checked with >> + the dynamic_cast that we didn't get nullptr, now use static_cast to >> + catch the virtual base case. This has the side effect of guaranteeing >> + that GDB will compile in production mode. */ >> + T result = static_cast (v); >> #else >> T result = static_cast (v); >> #endif >> Simon> This is similar to what I proposed here: Simon> https://inbox.sourceware.org/gdb-patches/24af4ea8-5426-4ce4-b1c5-12858b38a952@simark.ca/ Simon> The idea is the same, to have a static_cast in the DEVELOPMENT branch. Simon> I kinda like my version better, as it factors out the static cast Simon> (notice that both branches have identical static_cast lines after your Simon> patch) and the ifdef is just around a single assert. Also, I'm pretty Simon> sure the nullptr check is not necessary, as both dynamic_cast and Simon> static_cast can handle it. I think either of these would be fine. Tom