From patchwork Thu Feb 4 03:59:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 11128 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 2C054BD160 for ; Thu, 4 Feb 2021 04:00:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9D866613F8; Thu, 4 Feb 2021 05:00:18 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nRHx/Xuv"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 23A5E613DA for ; Thu, 4 Feb 2021 05:00:17 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9B1155A5 for ; Thu, 4 Feb 2021 05:00:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1612411216; bh=JKkU5tDdpjA+IoDcO3tP0tc2j9O4b4X99oYhJ30Vyf4=; h=From:To:Subject:Date:From; b=nRHx/XuvRiGWAMNon9oTbbkZq3BsVF50H9iw0NAZhwO6Lam+/UFtoLbTJ3EpAkh2C PwLgshv+wCVkZSRDJCfANyMw9kRlKj3W07lZurP0UeQlIDZejMjqc38muzaM4e9Py+ fnfkcezZC5DrjbQZssroDIO3g3b0ITVa+9UrvkR8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 4 Feb 2021 05:59:50 +0200 Message-Id: <20210204035951.23751-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] libcamera: Add macro to conditionally use [[nodiscard]] X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The [[nodiscard]] attribute has been added to C++17. It can thus be used inside libcamera, but would prevent applications compiled for C++14 to use libcamera if the attribute was used in public headers. To offer this feature when the application is compiled with a recent-enough C++ version, as well as for compiling libcamera itself, add a __nodiscard macro that expands as [[nodiscard]] when using C++17 or newer. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- include/libcamera/compiler.h | 16 ++++++++++++++++ include/libcamera/meson.build | 1 + 2 files changed, 17 insertions(+) create mode 100644 include/libcamera/compiler.h diff --git a/include/libcamera/compiler.h b/include/libcamera/compiler.h new file mode 100644 index 000000000000..dc56dbb8b792 --- /dev/null +++ b/include/libcamera/compiler.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * compiler.h - Compiler support + */ +#ifndef __LIBCAMERA_COMPILER_H__ +#define __LIBCAMERA_COMPILER_H__ + +#if __cplusplus >= 201703L +#define __nodiscard [[nodiscard]] +#else +#define __nodiscard +#endif + +#endif /* __LIBCAMERA_COMPILER_H__ */ diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index cf2935f1ee95..13e9eeb6d6ad 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -5,6 +5,7 @@ libcamera_public_headers = files([ 'buffer.h', 'camera.h', 'camera_manager.h', + 'compiler.h', 'controls.h', 'extensible.h', 'file_descriptor.h',