From patchwork Mon Jan 6 09:40:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 22453 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 283E4C0F1B for ; Mon, 6 Jan 2025 09:40:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3805E684E0; Mon, 6 Jan 2025 10:40:48 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="SH/eSOew"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 16B00608AB for ; Mon, 6 Jan 2025 10:40:46 +0100 (CET) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4361b6f9faeso85096775e9.1 for ; Mon, 06 Jan 2025 01:40:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1736156445; x=1736761245; darn=lists.libcamera.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=g1PTdY45k/ypKFsyG61d7M2fNgy60Em6q3HdZzClHOE=; b=SH/eSOew1yiU/DKZId3cZ4HUR04Yc/KDsEA6ec00g+OdmzyL96fRv4jeSC6esnDIHY /QE+xr24ydtH+CsVUi3lC3uu+2ffHfBJGTZ+pvpx1hRPmrqBYfXdvJPS1Bcjr9UBlvxk xM04GgJsvN2ipMHwqsS2V94ZJLNBWOEX8scGgxaiybrfvNygD2mqVpWpBxbxTmHovz0U 4wMk37nBlFeaaiIX4UULQ3aKE5b5I6Iz5gc2nLw2ezbx75L5/O/OWUt0zEO4Chwz6TDw 5wQ1stBj5uO56v8KgfobFiZlixtdv9+riVqgxBo6MkE6jnvEJtMsu5ylaNhWUl8LM/BH u9pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736156445; x=1736761245; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=g1PTdY45k/ypKFsyG61d7M2fNgy60Em6q3HdZzClHOE=; b=bY0NY4YNru83bK88SpBSiQ4mykRy5xCvBRSpirrJ/K9hJFYvU2v6DkOiT2tYIi41pc 9b+iSu6kT0oJ8pUZrPFKSsQma9iJO5cYkFmqGqVRsUK58F95m4pZRfBjuOPplVP5SkoD QC1EnaKumqITKUy+Zqx9+pTuuXDT0DPdwnpWmL7bI9XqX+Zpvb92htXLM6qeUMLe+y6C ++3IrT9R3KKfwqvGGO+EJBwpCNctC7PtintIvrXKnLTZd3JIAypdURrm3cqgwzbt0Qke y3rLHKHGNHuV691cZARMoFbH3D0Y0zrTgPIi67l5rCax8RKtWtOfA95iFidWG7cWPdLW eh1Q== X-Gm-Message-State: AOJu0YxM6KUg5npLUXnZIi/TkLDIo2fjG7MBNYMkZ6XNkbJxMxJEOw6D WtubNPcZYGxLa46D6zbQ1fAHM99Cx1ZdNIvz0ZMVp/IEQ4eE6L1ih44htvLSJOM= X-Gm-Gg: ASbGncvtu3jTDYieCMwzBOsYmWGNTc6M40GnLpsfw5k6m6ePnAH3EDOTr2XrmiWB3AG LNYTbeEAzgbOQkKz5s3HeDY/kVahfZChIhbyEPPUJfRazkjD6h014vvPi4jilC9Xf4TliLop46r 08EX8wGQR1UP6s6mheyuqJT1t/RqI4Ey8YuWY4qDFwL7pFIsuK49bIy2NzrwE7Qb2dOGtdSIoJT nnl2PhrAFLFGRjXzsEMCfzH/XoeUA/ppWJ7XVd7BdPqERLNqzZJJ1io7p9nTP1Mz2l1txgx X-Google-Smtp-Source: AGHT+IGhnDPDsWrs+/TZ3e32rrqgNYHT7mgCsKGgxbmz2/2TsrgH3wxPwh6GvgNfKbc68ESYPZ8X2Q== X-Received: by 2002:a05:600c:a296:b0:436:17a6:32ee with SMTP id 5b1f17b1804b1-4365c792931mr501136565e9.10.1736156445285; Mon, 06 Jan 2025 01:40:45 -0800 (PST) Received: from [192.168.1.20] ([2a01:cb19:95ba:5000:d6dd:417f:52ac:335b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a412f778esm33165305f8f.4.2025.01.06.01.40.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 01:40:44 -0800 (PST) From: Mattijs Korpershoek Date: Mon, 06 Jan 2025 10:40:41 +0100 Subject: [PATCH v2] libcamera: base: Remove custom __nodiscard attribute MIME-Version: 1.0 Message-Id: <20250106-nodiscard-redef-v2-1-e4a9afd04c7c@baylibre.com> X-B4-Tracking: v=1; b=H4sIABile2cC/3WNywrCMBBFf6XM2kgeBFNX/kfpIk0mdkAbmUixl Py7sXuX58A9d4eCTFjg2u3AuFKhvDTQpw7C7Jc7CoqNQUttpZJGLDlSCZ6jYIyYRK+sQ5diMMl CW70YE32O4jA2nqm8M2/Hwap+9n9rVUIJ7y/W9sHhhOY2+e1BE+M55CeMtdYviB1KobEAAAA= X-Change-ID: 20250103-nodiscard-redef-9158e8fdc3f5 To: libcamera-devel@lists.libcamera.org Cc: Guillaume La Roque , Mattijs Korpershoek X-Mailer: b4 0.14.3-dev-86319 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" __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 Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- Hi, it's been a while. I've found a (trivial) build issue when building against recent bionic versions. After discussion in v1, dropping compiler.h seemed the right choice. --- Changes in v2: - Drop support of __nodiscard instead of adding another #ifdef (Laurent) - Link to v1: https://lists.libcamera.org/pipermail/libcamera-devel/2025-January/047922.html --- include/libcamera/base/compiler.h | 14 -------------- include/libcamera/base/meson.build | 1 - include/libcamera/base/unique_fd.h | 3 +-- include/libcamera/geometry.h | 28 +++++++++++++--------------- 4 files changed, 14 insertions(+), 32 deletions(-) --- base-commit: 35ed4b91291d9f3d08e4b51acfb51163e65df8f8 change-id: 20250103-nodiscard-redef-9158e8fdc3f5 Best regards, diff --git a/include/libcamera/base/compiler.h b/include/libcamera/base/compiler.h deleted file mode 100644 index fda8fdfdc543f86c5554e38ef790c00d72d60389..0000000000000000000000000000000000000000 --- 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 2a0cee317204b0d6b44276703fac229bfd7973b9..f28ae4d42a69c755710b51ffc92976bb6fb6a0d8 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 c9a3b5d0e8628533bd18649e156ba78da40ca200..3066bf28f745df1d26a74c20d21b607dba3d41f4 100644 --- a/include/libcamera/base/unique_fd.h +++ b/include/libcamera/base/unique_fd.h @@ -10,7 +10,6 @@ #include #include -#include 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 e5f0a843d3144d2086c42c11ab40b0a98438a7e2..0a7133f24c78d4b70075fdd02eabfa52857937dc 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -11,8 +11,6 @@ #include #include -#include - namespace libcamera { class Rectangle; @@ -110,7 +108,7 @@ public: return *this; } - __nodiscard constexpr Size alignedDownTo(unsigned int hAlignment, + [[nodiscard]] constexpr Size alignedDownTo(unsigned int hAlignment, unsigned int vAlignment) const { return { @@ -119,7 +117,7 @@ public: }; } - __nodiscard constexpr Size alignedUpTo(unsigned int hAlignment, + [[nodiscard]] constexpr Size alignedUpTo(unsigned int hAlignment, unsigned int vAlignment) const { return { @@ -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 ¢er) const; + [[nodiscard]] Rectangle centeredTo(const Point ¢er) 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, + [[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 translatedBy(const Point &point) const; Rectangle transformedBetween(const Rectangle &source, const Rectangle &target) const;