{"id":22453,"url":"https://patchwork.libcamera.org/api/patches/22453/?format=json","web_url":"https://patchwork.libcamera.org/patch/22453/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20250106-nodiscard-redef-v2-1-e4a9afd04c7c@baylibre.com>","date":"2025-01-06T09:40:41","name":"[v2] libcamera: base: Remove custom __nodiscard attribute","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"875592af482621f40f5aa4708633be78d901816c","submitter":{"id":153,"url":"https://patchwork.libcamera.org/api/people/153/?format=json","name":"Mattijs Korpershoek","email":"mkorpershoek@baylibre.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/22453/mbox/","series":[{"id":4929,"url":"https://patchwork.libcamera.org/api/series/4929/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4929","date":"2025-01-06T09:40:41","name":"[v2] libcamera: base: Remove custom __nodiscard attribute","version":2,"mbox":"https://patchwork.libcamera.org/series/4929/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22453/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22453/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 283E4C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  6 Jan 2025 09:40:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3805E684E0;\n\tMon,  6 Jan 2025 10:40:48 +0100 (CET)","from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com\n\t[IPv6:2a00:1450:4864:20::32f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 16B00608AB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  6 Jan 2025 10:40:46 +0100 (CET)","by mail-wm1-x32f.google.com with SMTP id\n\t5b1f17b1804b1-4361b6f9faeso85096775e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 06 Jan 2025 01:40:46 -0800 (PST)","from [192.168.1.20] ([2a01:cb19:95ba:5000:d6dd:417f:52ac:335b])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-38a412f778esm33165305f8f.4.2025.01.06.01.40.44\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 06 Jan 2025 01:40:44 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=baylibre-com.20230601.gappssmtp.com\n\theader.i=@baylibre-com.20230601.gappssmtp.com\n\theader.b=\"SH/eSOew\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1736156445;\n\tx=1736761245; darn=lists.libcamera.org; \n\th=cc:to:message-id:content-transfer-encoding:mime-version:subject\n\t:date:from:from:to:cc:subject:date:message-id:reply-to;\n\tbh=g1PTdY45k/ypKFsyG61d7M2fNgy60Em6q3HdZzClHOE=;\n\tb=SH/eSOew1yiU/DKZId3cZ4HUR04Yc/KDsEA6ec00g+OdmzyL96fRv4jeSC6esnDIHY\n\t/QE+xr24ydtH+CsVUi3lC3uu+2ffHfBJGTZ+pvpx1hRPmrqBYfXdvJPS1Bcjr9UBlvxk\n\txM04GgJsvN2ipMHwqsS2V94ZJLNBWOEX8scGgxaiybrfvNygD2mqVpWpBxbxTmHovz0U\n\t4wMk37nBlFeaaiIX4UULQ3aKE5b5I6Iz5gc2nLw2ezbx75L5/O/OWUt0zEO4Chwz6TDw\n\t5wQ1stBj5uO56v8KgfobFiZlixtdv9+riVqgxBo6MkE6jnvEJtMsu5ylaNhWUl8LM/BH\n\tu9pg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1736156445; x=1736761245;\n\th=cc:to:message-id:content-transfer-encoding:mime-version:subject\n\t:date:from:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=g1PTdY45k/ypKFsyG61d7M2fNgy60Em6q3HdZzClHOE=;\n\tb=bY0NY4YNru83bK88SpBSiQ4mykRy5xCvBRSpirrJ/K9hJFYvU2v6DkOiT2tYIi41pc\n\t9b+iSu6kT0oJ8pUZrPFKSsQma9iJO5cYkFmqGqVRsUK58F95m4pZRfBjuOPplVP5SkoD\n\tQC1EnaKumqITKUy+Zqx9+pTuuXDT0DPdwnpWmL7bI9XqX+Zpvb92htXLM6qeUMLe+y6C\n\t++3IrT9R3KKfwqvGGO+EJBwpCNctC7PtintIvrXKnLTZd3JIAypdURrm3cqgwzbt0Qke\n\ty3rLHKHGNHuV691cZARMoFbH3D0Y0zrTgPIi67l5rCax8RKtWtOfA95iFidWG7cWPdLW\n\teh1Q==","X-Gm-Message-State":"AOJu0YxM6KUg5npLUXnZIi/TkLDIo2fjG7MBNYMkZ6XNkbJxMxJEOw6D\n\tWtubNPcZYGxLa46D6zbQ1fAHM99Cx1ZdNIvz0ZMVp/IEQ4eE6L1ih44htvLSJOM=","X-Gm-Gg":"ASbGncvtu3jTDYieCMwzBOsYmWGNTc6M40GnLpsfw5k6m6ePnAH3EDOTr2XrmiWB3AG\n\tLNYTbeEAzgbOQkKz5s3HeDY/kVahfZChIhbyEPPUJfRazkjD6h014vvPi4jilC9Xf4TliLop46r\n\t08EX8wGQR1UP6s6mheyuqJT1t/RqI4Ey8YuWY4qDFwL7pFIsuK49bIy2NzrwE7Qb2dOGtdSIoJT\n\tnnl2PhrAFLFGRjXzsEMCfzH/XoeUA/ppWJ7XVd7BdPqERLNqzZJJ1io7p9nTP1Mz2l1txgx","X-Google-Smtp-Source":"AGHT+IGhnDPDsWrs+/TZ3e32rrqgNYHT7mgCsKGgxbmz2/2TsrgH3wxPwh6GvgNfKbc68ESYPZ8X2Q==","X-Received":"by 2002:a05:600c:a296:b0:436:17a6:32ee with SMTP id\n\t5b1f17b1804b1-4365c792931mr501136565e9.10.1736156445285; \n\tMon, 06 Jan 2025 01:40:45 -0800 (PST)","From":"Mattijs Korpershoek <mkorpershoek@baylibre.com>","Date":"Mon, 06 Jan 2025 10:40:41 +0100","Subject":"[PATCH v2] libcamera: base: Remove custom __nodiscard attribute","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","Message-Id":"<20250106-nodiscard-redef-v2-1-e4a9afd04c7c@baylibre.com>","X-B4-Tracking":"v=1; b=H4sIABile2cC/3WNywrCMBBFf6XM2kgeBFNX/kfpIk0mdkAbmUixl\n\tPy7sXuX58A9d4eCTFjg2u3AuFKhvDTQpw7C7Jc7CoqNQUttpZJGLDlSCZ6jYIyYRK+sQ5diMMl\n\tCW70YE32O4jA2nqm8M2/Hwap+9n9rVUIJ7y/W9sHhhOY2+e1BE+M55CeMtdYviB1KobEAAAA=","X-Change-ID":"20250103-nodiscard-redef-9158e8fdc3f5","To":"libcamera-devel@lists.libcamera.org","Cc":"Guillaume La Roque <glaroque@baylibre.com>, \n\tMattijs Korpershoek <mkorpershoek@baylibre.com>","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":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"__nodiscard was introduced for compatibility with C++14.\nIn C++17, there is an official attribute: [[nodiscard]].\nMoreover, some libc implementations (like bionic) already define the\n__nodiscard macro [1].\n\nSince:\n- libcamera builds with cpp_std=c++17\n- [[nodiscard]] is already used in the android HAL (exif)\n\nWe should replace all usage __nodiscard of by [[nodiscard]] for\nconsistency.\n\nDo the replacement and remove the no longer used compiler.h.\n\n[1] https://android-review.googlesource.com/c/platform/bionic/+/3254860\n\nSigned-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>\n---\nHi, it's been a while. I've found a (trivial) build issue when\nbuilding against recent bionic versions.\n\nAfter discussion in v1, dropping compiler.h seemed the right choice.\n---\nChanges in v2:\n- Drop support of __nodiscard instead of adding another #ifdef (Laurent)\n- Link to v1: https://lists.libcamera.org/pipermail/libcamera-devel/2025-January/047922.html\n---\n include/libcamera/base/compiler.h  | 14 --------------\n include/libcamera/base/meson.build |  1 -\n include/libcamera/base/unique_fd.h |  3 +--\n include/libcamera/geometry.h       | 28 +++++++++++++---------------\n 4 files changed, 14 insertions(+), 32 deletions(-)\n\n\n---\nbase-commit: 35ed4b91291d9f3d08e4b51acfb51163e65df8f8\nchange-id: 20250103-nodiscard-redef-9158e8fdc3f5\n\nBest regards,","diff":"diff --git a/include/libcamera/base/compiler.h b/include/libcamera/base/compiler.h\ndeleted file mode 100644\nindex fda8fdfdc543f86c5554e38ef790c00d72d60389..0000000000000000000000000000000000000000\n--- a/include/libcamera/base/compiler.h\n+++ /dev/null\n@@ -1,14 +0,0 @@\n-/* SPDX-License-Identifier: LGPL-2.1-or-later */\n-/*\n- * Copyright (C) 2021, Google Inc.\n- *\n- * Compiler support\n- */\n-\n-#pragma once\n-\n-#if __cplusplus >= 201703L\n-#define __nodiscard\t\t[[nodiscard]]\n-#else\n-#define __nodiscard\n-#endif\ndiff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build\nindex 2a0cee317204b0d6b44276703fac229bfd7973b9..f28ae4d42a69c755710b51ffc92976bb6fb6a0d8 100644\n--- a/include/libcamera/base/meson.build\n+++ b/include/libcamera/base/meson.build\n@@ -5,7 +5,6 @@ libcamera_base_include_dir = libcamera_include_dir / 'base'\n libcamera_base_public_headers = files([\n     'bound_method.h',\n     'class.h',\n-    'compiler.h',\n     'flags.h',\n     'object.h',\n     'shared_fd.h',\ndiff --git a/include/libcamera/base/unique_fd.h b/include/libcamera/base/unique_fd.h\nindex c9a3b5d0e8628533bd18649e156ba78da40ca200..3066bf28f745df1d26a74c20d21b607dba3d41f4 100644\n--- a/include/libcamera/base/unique_fd.h\n+++ b/include/libcamera/base/unique_fd.h\n@@ -10,7 +10,6 @@\n #include <utility>\n \n #include <libcamera/base/class.h>\n-#include <libcamera/base/compiler.h>\n \n namespace libcamera {\n \n@@ -43,7 +42,7 @@ public:\n \t\treturn *this;\n \t}\n \n-\t__nodiscard int release()\n+\t[[nodiscard]] int release()\n \t{\n \t\tint fd = fd_;\n \t\tfd_ = -1;\ndiff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\nindex e5f0a843d3144d2086c42c11ab40b0a98438a7e2..0a7133f24c78d4b70075fdd02eabfa52857937dc 100644\n--- a/include/libcamera/geometry.h\n+++ b/include/libcamera/geometry.h\n@@ -11,8 +11,6 @@\n #include <ostream>\n #include <string>\n \n-#include <libcamera/base/compiler.h>\n-\n namespace libcamera {\n \n class Rectangle;\n@@ -110,7 +108,7 @@ public:\n \t\treturn *this;\n \t}\n \n-\t__nodiscard constexpr Size alignedDownTo(unsigned int hAlignment,\n+\t[[nodiscard]] constexpr Size alignedDownTo(unsigned int hAlignment,\n \t\t\t\t\t\t unsigned int vAlignment) const\n \t{\n \t\treturn {\n@@ -119,7 +117,7 @@ public:\n \t\t};\n \t}\n \n-\t__nodiscard constexpr Size alignedUpTo(unsigned int hAlignment,\n+\t[[nodiscard]] constexpr Size alignedUpTo(unsigned int hAlignment,\n \t\t\t\t\t       unsigned int vAlignment) const\n \t{\n \t\treturn {\n@@ -128,7 +126,7 @@ public:\n \t\t};\n \t}\n \n-\t__nodiscard constexpr Size boundedTo(const Size &bound) const\n+\t[[nodiscard]] constexpr Size boundedTo(const Size &bound) const\n \t{\n \t\treturn {\n \t\t\tstd::min(width, bound.width),\n@@ -136,7 +134,7 @@ public:\n \t\t};\n \t}\n \n-\t__nodiscard constexpr Size expandedTo(const Size &expand) const\n+\t[[nodiscard]] constexpr Size expandedTo(const Size &expand) const\n \t{\n \t\treturn {\n \t\t\tstd::max(width, expand.width),\n@@ -144,7 +142,7 @@ public:\n \t\t};\n \t}\n \n-\t__nodiscard constexpr Size grownBy(const Size &margins) const\n+\t[[nodiscard]] constexpr Size grownBy(const Size &margins) const\n \t{\n \t\treturn {\n \t\t\twidth + margins.width,\n@@ -152,7 +150,7 @@ public:\n \t\t};\n \t}\n \n-\t__nodiscard constexpr Size shrunkBy(const Size &margins) const\n+\t[[nodiscard]] constexpr Size shrunkBy(const Size &margins) const\n \t{\n \t\treturn {\n \t\t\twidth > margins.width ? width - margins.width : 0,\n@@ -160,10 +158,10 @@ public:\n \t\t};\n \t}\n \n-\t__nodiscard Size boundedToAspectRatio(const Size &ratio) const;\n-\t__nodiscard Size expandedToAspectRatio(const Size &ratio) const;\n+\t[[nodiscard]] Size boundedToAspectRatio(const Size &ratio) const;\n+\t[[nodiscard]] Size expandedToAspectRatio(const Size &ratio) const;\n \n-\t__nodiscard Rectangle centeredTo(const Point &center) const;\n+\t[[nodiscard]] Rectangle centeredTo(const Point &center) const;\n \n \tSize operator*(float factor) const;\n \tSize operator/(float factor) const;\n@@ -294,11 +292,11 @@ public:\n \tRectangle &scaleBy(const Size &numerator, const Size &denominator);\n \tRectangle &translateBy(const Point &point);\n \n-\t__nodiscard Rectangle boundedTo(const Rectangle &bound) const;\n-\t__nodiscard Rectangle enclosedIn(const Rectangle &boundary) const;\n-\t__nodiscard Rectangle scaledBy(const Size &numerator,\n+\t[[nodiscard]] Rectangle boundedTo(const Rectangle &bound) const;\n+\t[[nodiscard]] Rectangle enclosedIn(const Rectangle &boundary) const;\n+\t[[nodiscard]] Rectangle scaledBy(const Size &numerator,\n \t\t\t\t       const Size &denominator) const;\n-\t__nodiscard Rectangle translatedBy(const Point &point) const;\n+\t[[nodiscard]] Rectangle translatedBy(const Point &point) const;\n \n \tRectangle transformedBetween(const Rectangle &source,\n \t\t\t\t     const Rectangle &target) const;\n","prefixes":["v2"]}