From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 0C6F93858D34 for ; Wed, 21 Feb 2024 17:32:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C6F93858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0C6F93858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708536745; cv=none; b=LhbqUSpojExE0QNd45U9ewQkE44GV8KuGwX4DtFGO4+jA1WinLQE4mu+86NIXv3I0ySyLX8NVo3SmrARXIpO/l7Sqmwc77lYyCqKWRZK6gfLxHn/2WkXWFcsX85D54z7zxAYjP+zWRyHtx1Rh9k8NHnMozkk5CAmZkozj2WsWEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708536745; c=relaxed/simple; bh=Ut1t2ZjVwsv4BeFckVJknE1kvakFRThk2JMfzP4i3FM=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=L0GJbotVPPC13CriD5Rm+UZLmLrnro4ZASmcopBUr+orz1fqXmtuaqB38UbXxHfxuTXLWz7jyXoLm2qdH1sJGM909+ALEIBe1G4diUNY2aSwtXyxh70CHiEE5xDEC6PLNVMvpXN0FSS+M16cEAn2E/VYCYvhUqKMidBNS5IZtuY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1708536742; bh=Ut1t2ZjVwsv4BeFckVJknE1kvakFRThk2JMfzP4i3FM=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=jTcCcuZqrCRPyd0FGFnoZNFLF3093gDFLphQKCShasiWNp3xf4xdPuo0T9as/XBrU 818UgFlrHG/NPgEQCGVCLwbd0En2+63TgFHQbseSnMQmToqzK5qZ6H8nQrxuSP8W5b jua/9KUnmm3HVeQYw81dP3dB5y9gMmoiw11DWpvc= Received: from [10.0.0.170] (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id EDF7D1E030; Wed, 21 Feb 2024 12:32:21 -0500 (EST) Message-ID: <24af4ea8-5426-4ce4-b1c5-12858b38a952@simark.ca> Date: Wed, 21 Feb 2024 12:32:21 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] [gdb/tui] Factor out tui_noscroll_window et al Content-Language: fr To: Tom Tromey , Tom de Vries Cc: gdb-patches@sourceware.org References: <20231112150601.25484-1-tdevries@suse.de> <87r0kttwba.fsf@tromey.com> From: Simon Marchi In-Reply-To: <87r0kttwba.fsf@tromey.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_PASS,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: On 11/13/23 12:08, Tom Tromey wrote: >>>>>> "Tom" == Tom de Vries writes: > > Tom> +/* A TUI window that doesn't scroll. */ > Tom> + > Tom> +struct tui_noscroll_window : public virtual tui_win_info { > > The "{" should be on the next line. > > Tom> +/* A TUI window that occupies a single line. */ > Tom> + > Tom> +struct tui_oneline_window : public virtual tui_win_info { > > Some of these only have a single use. That seems like overkill to me, > unless we're introducing another use someday. > > Tom> +#define TUI_SRC_WIN \ > Tom> + (dynamic_cast (tui_win_list[SRC_WIN])) > Tom> +#define TUI_DISASM_WIN \ > Tom> + (dynamic_cast (tui_win_list[DISASSEM_WIN])) > > I think these should use gdb::checked_static_cast. Actually, since the base is virtual, dynamic_cast is needed. Try changing development to false in bfd/development.sh, you'll get: CXX tui/tui-layout.o In file included from /home/smarchi/src/binutils-gdb/gdb/tui/tui-data.h:31, from /home/smarchi/src/binutils-gdb/gdb/tui/tui-command.h:25, from /home/smarchi/src/binutils-gdb/gdb/tui/tui-layout.c:31: /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/gdb-checked-static-cast.h: In instantiation of ‘T gdb::checked_static_cast(V*) [with T = tui_cmd_window*; V = tui_win_info]’: /home/smarchi/src/binutils-gdb/gdb/tui/tui-layout.c:79:3: required from here /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/gdb-checked-static-cast.h:64:14: error: cannot convert from pointer to base class ‘tui_win_info’ to pointer to derived class ‘tui_cmd_window’ because the base is virtual 64 | T result = static_cast (v); | ^~~~~~~~~~~~~~~~~~ It might be a good idea to add a static_cast in the DEVELOPMENT branch of checked_static_cast to catch this kind of mistake. I think it could be written this way to be succinct (but untested): T result = static_cast (v); #ifdef DEVELOPMENT gdb_assert (result == dynamic_cast (v)); #endif return result; IOW, this patch: diff --git a/gdbsupport/gdb-checked-static-cast.h b/gdbsupport/gdb-checked-static-cast.h index b6ce8c8bb04..e935bb359f0 100644 --- a/gdbsupport/gdb-checked-static-cast.h +++ b/gdbsupport/gdb-checked-static-cast.h @@ -54,14 +54,9 @@ checked_static_cast (V *v) || std::is_base_of::value, "types must be related"); -#ifdef DEVELOPMENT - if (v == nullptr) - return nullptr; - - T result = dynamic_cast (v); - gdb_assert (result != nullptr); -#else T result = static_cast (v); +#ifdef DEVELOPMENT + gdb_assert (result == dynamic_cast (v)); #endif return result; Simon