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',
