summaryrefslogtreecommitdiff
path: root/include/libcamera/compiler.h
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-01-26 23:38:05 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-02-04 21:00:38 +0200
commit6dfa2040820d44584a1c5430f42dfc9b1ea56c9a (patch)
treedd29f820e15a14da112ce016411334238bef2765 /include/libcamera/compiler.h
parent9e807050be4c0b9c2b03fff8da4e994798971ff1 (diff)
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>
Diffstat (limited to 'include/libcamera/compiler.h')
-rw-r--r--include/libcamera/compiler.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/libcamera/compiler.h b/include/libcamera/compiler.h
new file mode 100644
index 00000000..dc56dbb8
--- /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__ */