libcamera: Add macro to conditionally use [[nodiscard]]

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 <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Laurent Pinchart
2021-01-26 23:38:05 +02:00
parent 9e807050be
commit 6dfa204082
2 changed files with 17 additions and 0 deletions
+16
View File
@@ -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__ */
+1
View File
@@ -5,6 +5,7 @@ libcamera_public_headers = files([
'buffer.h',
'camera.h',
'camera_manager.h',
'compiler.h',
'controls.h',
'extensible.h',
'file_descriptor.h',