summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMattijs Korpershoek <mkorpershoek@baylibre.com>2025-01-06 10:40:41 +0100
committerKieran Bingham <kieran.bingham@ideasonboard.com>2025-01-08 15:26:30 +0000
commit5d444bbd51d0b11f85c2d28b426b9bcdce7cbed0 (patch)
tree9f003003b6516cb6d2a7025e6569cbb1a9e1002b /include
parent3feb4df755d5013c2e058370de7a074f5cc35b71 (diff)
libcamera: base: Remove custom __nodiscard attribute
__nodiscard was introduced for compatibility with C++14. In C++17, there is an official attribute: [[nodiscard]]. Moreover, some libc implementations (like bionic) already define the __nodiscard macro [1]. Since: - libcamera builds with cpp_std=c++17 - [[nodiscard]] is already used in the android HAL (exif) We should replace all usage __nodiscard of by [[nodiscard]] for consistency. Do the replacement and remove the no longer used compiler.h. [1] https://android-review.googlesource.com/c/platform/bionic/+/3254860 Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/base/compiler.h14
-rw-r--r--include/libcamera/base/meson.build1
-rw-r--r--include/libcamera/base/unique_fd.h3
-rw-r--r--include/libcamera/geometry.h34
4 files changed, 17 insertions, 35 deletions
diff --git a/include/libcamera/base/compiler.h b/include/libcamera/base/compiler.h
deleted file mode 100644
index fda8fdfd..00000000
--- a/include/libcamera/base/compiler.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-/*
- * Copyright (C) 2021, Google Inc.
- *
- * Compiler support
- */
-
-#pragma once
-
-#if __cplusplus >= 201703L
-#define __nodiscard [[nodiscard]]
-#else
-#define __nodiscard
-#endif
diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
index 2a0cee31..f28ae4d4 100644
--- a/include/libcamera/base/meson.build
+++ b/include/libcamera/base/meson.build
@@ -5,7 +5,6 @@ libcamera_base_include_dir = libcamera_include_dir / 'base'
libcamera_base_public_headers = files([
'bound_method.h',
'class.h',
- 'compiler.h',
'flags.h',
'object.h',
'shared_fd.h',
diff --git a/include/libcamera/base/unique_fd.h b/include/libcamera/base/unique_fd.h
index c9a3b5d0..3066bf28 100644
--- a/include/libcamera/base/unique_fd.h
+++ b/include/libcamera/base/unique_fd.h
@@ -10,7 +10,6 @@
#include <utility>
#include <libcamera/base/class.h>
-#include <libcamera/base/compiler.h>
namespace libcamera {
@@ -43,7 +42,7 @@ public:
return *this;
}
- __nodiscard int release()
+ [[nodiscard]] int release()
{
int fd = fd_;
fd_ = -1;
diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h
index e5f0a843..f322e3d5 100644
--- a/include/libcamera/geometry.h
+++ b/include/libcamera/geometry.h
@@ -11,8 +11,6 @@
#include <ostream>
#include <string>
-#include <libcamera/base/compiler.h>
-
namespace libcamera {
class Rectangle;
@@ -110,8 +108,8 @@ public:
return *this;
}
- __nodiscard constexpr Size alignedDownTo(unsigned int hAlignment,
- unsigned int vAlignment) const
+ [[nodiscard]] constexpr Size alignedDownTo(unsigned int hAlignment,
+ unsigned int vAlignment) const
{
return {
width / hAlignment * hAlignment,
@@ -119,8 +117,8 @@ public:
};
}
- __nodiscard constexpr Size alignedUpTo(unsigned int hAlignment,
- unsigned int vAlignment) const
+ [[nodiscard]] constexpr Size alignedUpTo(unsigned int hAlignment,
+ unsigned int vAlignment) const
{
return {
(width + hAlignment - 1) / hAlignment * hAlignment,
@@ -128,7 +126,7 @@ public:
};
}
- __nodiscard constexpr Size boundedTo(const Size &bound) const
+ [[nodiscard]] constexpr Size boundedTo(const Size &bound) const
{
return {
std::min(width, bound.width),
@@ -136,7 +134,7 @@ public:
};
}
- __nodiscard constexpr Size expandedTo(const Size &expand) const
+ [[nodiscard]] constexpr Size expandedTo(const Size &expand) const
{
return {
std::max(width, expand.width),
@@ -144,7 +142,7 @@ public:
};
}
- __nodiscard constexpr Size grownBy(const Size &margins) const
+ [[nodiscard]] constexpr Size grownBy(const Size &margins) const
{
return {
width + margins.width,
@@ -152,7 +150,7 @@ public:
};
}
- __nodiscard constexpr Size shrunkBy(const Size &margins) const
+ [[nodiscard]] constexpr Size shrunkBy(const Size &margins) const
{
return {
width > margins.width ? width - margins.width : 0,
@@ -160,10 +158,10 @@ public:
};
}
- __nodiscard Size boundedToAspectRatio(const Size &ratio) const;
- __nodiscard Size expandedToAspectRatio(const Size &ratio) const;
+ [[nodiscard]] Size boundedToAspectRatio(const Size &ratio) const;
+ [[nodiscard]] Size expandedToAspectRatio(const Size &ratio) const;
- __nodiscard Rectangle centeredTo(const Point &center) const;
+ [[nodiscard]] Rectangle centeredTo(const Point &center) const;
Size operator*(float factor) const;
Size operator/(float factor) const;
@@ -294,11 +292,11 @@ public:
Rectangle &scaleBy(const Size &numerator, const Size &denominator);
Rectangle &translateBy(const Point &point);
- __nodiscard Rectangle boundedTo(const Rectangle &bound) const;
- __nodiscard Rectangle enclosedIn(const Rectangle &boundary) const;
- __nodiscard Rectangle scaledBy(const Size &numerator,
- const Size &denominator) const;
- __nodiscard Rectangle translatedBy(const Point &point) const;
+ [[nodiscard]] Rectangle boundedTo(const Rectangle &bound) const;
+ [[nodiscard]] Rectangle enclosedIn(const Rectangle &boundary) const;
+ [[nodiscard]] Rectangle scaledBy(const Size &numerator,
+ const Size &denominator) const;
+ [[nodiscard]] Rectangle translatedBy(const Point &point) const;
Rectangle transformedBetween(const Rectangle &source,
const Rectangle &target) const;