Message ID | 20230421135135.B805413456@imap2.suse-dmz.suse.de |
---|---|
State | Repeat Merge |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1082182vqo; Fri, 21 Apr 2023 06:52:30 -0700 (PDT) X-Google-Smtp-Source: AKy350ZOFrD+JRFr0bcCSCsAZZa2JFK0btK5LpRibainSXnN0r3qkB9JMnYucYgvOxGSSfB9gVLX X-Received: by 2002:a17:906:888:b0:94f:96d0:46f8 with SMTP id n8-20020a170906088800b0094f96d046f8mr2349368eje.53.1682085150405; Fri, 21 Apr 2023 06:52:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682085150; cv=none; d=google.com; s=arc-20160816; b=Hbiac1q/uYerhcoUQmawV6xy0UmJN7udNEB/v1Mr/whNdAt41UvOfWbXH5FSj6NPGS dDM4iftN9d66qcyLW+8IYBZRagW8B8pfsMGGvUbxRCFTAZ1QU1crKpS5v7LT8in4nnme I0uV7WMPApLDdU7w+quy2qBwdZcM07J1swfkqXjn9NJrW1nxCguJ5TfcWClGNAB3r26X avSi8qq29Vc9EXEoQYhsnoet0QWkddopP/NtLRfrHYxztHEevxQoNE5J5kdpYgjH64uJ ZtjYDABvFIh/14Z49YQ2Vao9xkHEuuP3Pimr9bHO8R6fIScKBxfEUoj5hBJtT5CI8lhQ hJnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=FNQ8daF/oE+VFLinrjl0GH+9MoVOgxGVdN/TkGKc4AM=; b=QuCJhywhfOIMlxaocRKSaYGVylvYy8+x4p7bGk/5pj7QaWR+n9+68haQZ81m3ZCTEL tO1WwIxc7HtNwoTq2amSuDl57i7MjojDgT45UM3U3frFX0GZ3z7X33a0JMH6oovmFV7E K/bBMBSfzcwoXMV93fJvyh86n6Fukd/p0sMxwpqRyHSDbTWT+jYvcEoNw9/QoO/oSoFI curMtNlS30LGWfvjfq9E0OBMFckU0u//dCEjz1QywGLfUvQJVZFr8eg0naSBTvmVPH4F Zo8QGRSls8S/iRdtuAEeA+gdYLyN4A8GKhdcXZ14cKyUKD6OuPwz+KooPFZytuH3PD5C CJYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bRsXarH2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id kb23-20020a1709070f9700b009531dd675fcsi3693103ejc.932.2023.04.21.06.52.30 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Apr 2023 06:52:30 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bRsXarH2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 591343856DDE for <ouuuleilei@gmail.com>; Fri, 21 Apr 2023 13:52:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 591343856DDE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682085140; bh=FNQ8daF/oE+VFLinrjl0GH+9MoVOgxGVdN/TkGKc4AM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=bRsXarH2ZNYgtfE+onnA63WOnCHSKCl5jebk2tsL2gQKdJ8qqvIjmWCV8jET/6TMA HlEPb51wQdOIm8DzySxeYwrvVOzTKHh7HPG0fLmqsB2Rm7sRYXoaiWlORbzpsqG0pv efhaLEUuL7m04A3FONMz4C+0akk1SJVBPt2V3Lvk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id B00B83858401 for <gcc-patches@gcc.gnu.org>; Fri, 21 Apr 2023 13:51:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B00B83858401 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E16B71FDDD for <gcc-patches@gcc.gnu.org>; Fri, 21 Apr 2023 13:51:35 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B805413456 for <gcc-patches@gcc.gnu.org>; Fri, 21 Apr 2023 13:51:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id on3UK+eUQmRjZgAAMHmgww (envelope-from <rguenther@suse.de>) for <gcc-patches@gcc.gnu.org>; Fri, 21 Apr 2023 13:51:35 +0000 Date: Fri, 21 Apr 2023 15:51:35 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Add safe_is_a MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20230421135135.B805413456@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Richard Biener <rguenther@suse.de> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763794118747445424?= X-GMAIL-MSGID: =?utf-8?q?1763794118747445424?= |
Series |
Add safe_is_a
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Richard Biener
April 21, 2023, 1:51 p.m. UTC
The following adds safe_is_a, an is_a check handling nullptr gracefully. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. * is-a.h (safe_is_a): New. --- gcc/is-a.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
diff --git a/gcc/is-a.h b/gcc/is-a.h index b5355242655..0a697cf002a 100644 --- a/gcc/is-a.h +++ b/gcc/is-a.h @@ -232,6 +232,19 @@ is_a (U *p) return is_a_helper<T>::test (p); } +/* Similar to is_a<>, but where the pointer can be NULL, even if + is_a_helper<T> doesn't check for NULL. */ + +template <typename T, typename U> +inline bool +safe_is_a (U *p) +{ + if (p) + return is_a_helper <T>::test (p); + else + return false; +} + /* A generic conversion from a base type U to a derived type T. See the discussion above for when to use this function. */