From patchwork Fri Oct 21 16:01:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 6805 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp777094wrr; Fri, 21 Oct 2022 09:03:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4xa74YFy8qlKvkCONKc3PLx0ukPMsqYYDgsZuzmkIVWMqa2aSK5iiPiGVoAcpm5Cmq5b4m X-Received: by 2002:a17:907:7f91:b0:78e:2e30:9513 with SMTP id qk17-20020a1709077f9100b0078e2e309513mr16025975ejc.759.1666368208364; Fri, 21 Oct 2022 09:03:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666368208; cv=none; d=google.com; s=arc-20160816; b=VE2vh49nxtU5LyDrqUaPfxaz1kn8RRJnEtfn/vtHa70mhuX1YCF67N1Rizl1iPfbSq BDBuXrgdBLm2nXQk2jNtimXVBrmjj5zLwGKxnq2JK5Ru+5mHIS4gsj7trIE0v5gsP+wv OwjluDPeGQFf4pLqyavgoTEk51MyBl16kAGyuan8TLYNUNzcJXfYQxt/1+tg0dzOMFXh f2hocYIiTKVIg60ymQIlbgwX44VPyWPEhRN3FOwVsk839MEFi28KmOddr+nQOtB/BPTu v0By0efltrcbyatpsOvne7GgrWiOsFbnsjCR/prQ5CZRqgnEBIDHxYSHvwa9zauGjxzt /Wuw== 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 :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=QeHnMHPekE5zDChpUua4c1IK75HPHBaN0vl/ptuvk1M=; b=DayM2bld8gnfjQfAXjYZFcD6uMNxhzw+mWYy/LeuUlKJMbP6BFYrqnCSRN+gi0aJI4 5yDdJA6rXPH9dhIEgmDZeJn19DXbk7hyF077241vT5YKbDUfIZfT3eOH4DXzitTm4tmE fVhCxM3yAllmBVh/3QYt2xpvMX+14kGzhSyWl8diD833y6wLV00Q1ldxc7PV6wOgrKta fQp34S6jWeq5KnhdnyD9A2eP7SJnndNFBIhnNgsLwakRnbzqzKuheAhE0WeKpktTyZX8 llojy7zVW2Mn0IzpGfexLXgztzKvX4qBd6M8tNq+3Mjj7/mvfCnBDMDD61FFJ5vjBQsX YBZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RKE6YO+L; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hg5-20020a1709072cc500b00777581091d9si20471495ejc.634.2022.10.21.09.03.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 09:03:28 -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=RKE6YO+L; 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 1956F384B82B for ; Fri, 21 Oct 2022 16:02:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1956F384B82B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666368175; bh=QeHnMHPekE5zDChpUua4c1IK75HPHBaN0vl/ptuvk1M=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=RKE6YO+LnvUbzCWmOc/Y69mvCnq8iR3jHyreeWUFOicq0GeWWZjkAXcEDpbwocdac 9GZT7tRiByyRYjlvK0K35IytibKbv65EfAiTLA398mNPTI5JWEqZVsVslIEsQ1vtBm hGa7oDMyGek6U+KLnr+znKKO4Kdw+kioMdJvXIqk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 134323853809 for ; Fri, 21 Oct 2022 16:02:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 134323853809 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-486-Qp27wMDVPvqw47gQ8u4jqg-1; Fri, 21 Oct 2022 12:02:02 -0400 X-MC-Unique: Qp27wMDVPvqw47gQ8u4jqg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 407FD1C00158 for ; Fri, 21 Oct 2022 16:01:56 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1709F17585; Fri, 21 Oct 2022 16:01:56 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2] Add gcc/make-unique.h Date: Fri, 21 Oct 2022 12:01:49 -0400 Message-Id: <20221021160150.1600351-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747313709971607082?= X-GMAIL-MSGID: =?utf-8?q?1747313709971607082?= This patch adds gcc/make-unique.h, containing a minimal C++11 implementation of make_unique (std::make_unique is C++14). The followup patch uses this in dozens of places within the analyzer. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. OK for trunk? gcc/ChangeLog: * make-unique.h: New file. Signed-off-by: David Malcolm --- gcc/make-unique.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 gcc/make-unique.h diff --git a/gcc/make-unique.h b/gcc/make-unique.h new file mode 100644 index 00000000000..752a1d3dd30 --- /dev/null +++ b/gcc/make-unique.h @@ -0,0 +1,42 @@ +/* Minimal implementation of make_unique for C++11 compatibility. + Copyright (C) 2022 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef GCC_MAKE_UNIQUE +#define GCC_MAKE_UNIQUE + +/* This header uses std::unique_ptr, but can't be directly + included due to issues with macros. Hence must be included + from system.h by defining INCLUDE_MEMORY in any source file using + make-unique.h. */ + +#ifndef INCLUDE_MEMORY +# error "You must define INCLUDE_MEMORY before including system.h to use make-unique.h" +#endif + +/* Minimal implementation of make_unique for C++11 compatibility + (std::make_unique is C++14). */ + +template +inline typename std::enable_if::value, std::unique_ptr>::type +make_unique(Args&&... args) +{ + return std::unique_ptr (new T (std::forward (args)...)); +} + +#endif /* ! GCC_MAKE_UNIQUE */