Patch Detail
Show a patch.
GET /api/1.1/patches/10988/?format=api
{ "id": 10988, "url": "https://patchwork.libcamera.org/api/1.1/patches/10988/?format=api", "web_url": "https://patchwork.libcamera.org/patch/10988/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20210125172210.31681-1-laurent.pinchart@ideasonboard.com>", "date": "2021-01-25T17:22:10", "name": "[libcamera-devel,PATCH/RFC] libcamera: geometry: Mark const functions with [[nodiscard]]", "commit_ref": null, "pull_url": null, "state": "rfc", "archived": false, "hash": "e06279a41dffaefae740686248e25f88bee2fe87", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": { "id": 14, "url": "https://patchwork.libcamera.org/api/1.1/users/14/?format=api", "username": "pinchartl", "first_name": "Laurent", "last_name": "Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "mbox": "https://patchwork.libcamera.org/patch/10988/mbox/", "series": [ { "id": 1605, "url": "https://patchwork.libcamera.org/api/1.1/series/1605/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1605", "date": "2021-01-25T17:22:10", "name": "[libcamera-devel,PATCH/RFC] libcamera: geometry: Mark const functions with [[nodiscard]]", "version": 1, "mbox": "https://patchwork.libcamera.org/series/1605/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/10988/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/10988/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 1D0A1BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 25 Jan 2021 17:22:35 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8A937682D2;\n\tMon, 25 Jan 2021 18:22:34 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 44D5D682CB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 25 Jan 2021 18:22:33 +0100 (CET)", "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id AB9B0331\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 25 Jan 2021 18:22:32 +0100 (CET)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"GIk0LEhN\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1611595352;\n\tbh=+Qmrh31NsxTa8X3jWsgKQtfszaUOz8sDR4FfvAlCTys=;\n\th=From:To:Subject:Date:From;\n\tb=GIk0LEhN1iPtrCR9pEGRCKpzeveZBwN2dH7ExtQRoAOicCTT72rWZ4CJlLanysUWd\n\tdGNRYOPZd16H2L7sspGJRCxOghVpT/8c7FCNM0bLmrP8quq5bqQUUZPTM2mkuALdr0\n\t04QXsnfuqkNWyyPjhKRtoYniEvgQl9nXhodLyU8I=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 25 Jan 2021 19:22:10 +0200", "Message-Id": "<20210125172210.31681-1-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.28.0", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH/RFC] libcamera: geometry: Mark const\n\tfunctions with [[nodiscard]]", "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>", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Geometry classes generally have two sets of functions, one that operates\non the object and modifies it (e.g. Rectangle::scaleBy()), and one that\nperforms the same operations by instead return a modified copy of the\nobject, leaving the original untouched (e.g.Rectangle::scaledBy()). As\nthe names are close, they can easily be mistaken, with the const version\nused instead of the in-place version.\n\nTo catch these errors at compile time, mark the const versions with\n[[nodiscard]], as there is no use case for calling them without using\nthe result of the call.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/geometry.h | 27 ++++++++++++++-------------\n 1 file changed, 14 insertions(+), 13 deletions(-)\n\nThis patch came as a result of catching one of the issues described in\nthe commit message during review of another patch. [[nodiscard]] is only\navailable in C++17, which would make it impossible to use libcamera in\nC++14 code (this can for instance for a problem with Chromium - the web\nbrowser, not the OS). An alternative would be to define a custom\nattribute, for instance\n\n#define __nodiscard [[nodiscard]]\n\nin a public header (compile.h ? util.h ?), conditionally on the C++\nversion. The check would thus be disabled in application compiled with\nC++14, but would be enabled for the compilation of libcamera itself.\n\nIs this worth it ?", "diff": "diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\nindex 2f3a82e2afc3..0a9d61f45874 100644\n--- a/include/libcamera/geometry.h\n+++ b/include/libcamera/geometry.h\n@@ -92,8 +92,8 @@ public:\n \t\treturn *this;\n \t}\n \n-\tconstexpr Size alignedDownTo(unsigned int hAlignment,\n-\t\t\t\t unsigned int vAlignment) const\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 \t\t\twidth / hAlignment * hAlignment,\n@@ -101,8 +101,8 @@ public:\n \t\t};\n \t}\n \n-\tconstexpr Size alignedUpTo(unsigned int hAlignment,\n-\t\t\t\t unsigned int vAlignment) const\n+\t[[nodiscard]] constexpr Size alignedUpTo(unsigned int hAlignment,\n+\t\t\t\t\t\t unsigned int vAlignment) const\n \t{\n \t\treturn {\n \t\t\t(width + hAlignment - 1) / hAlignment * hAlignment,\n@@ -110,7 +110,7 @@ public:\n \t\t};\n \t}\n \n-\tconstexpr 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@@ -118,7 +118,7 @@ public:\n \t\t};\n \t}\n \n-\tconstexpr 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@@ -126,10 +126,10 @@ public:\n \t\t};\n \t}\n \n-\tSize boundedToAspectRatio(const Size &ratio) const;\n-\tSize 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-\tRectangle centeredTo(const Point ¢er) const;\n+\t[[nodiscard]] Rectangle centeredTo(const Point ¢er) const;\n \n \tSize operator*(float factor) const;\n \tSize operator/(float factor) const;\n@@ -247,10 +247,11 @@ public:\n \tRectangle &scaleBy(const Size &numerator, const Size &denominator);\n \tRectangle &translateBy(const Point &point);\n \n-\tRectangle boundedTo(const Rectangle &bound) const;\n-\tRectangle enclosedIn(const Rectangle &boundary) const;\n-\tRectangle scaledBy(const Size &numerator, const Size &denominator) const;\n-\tRectangle translatedBy(const Point &point) const;\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\t const Size &denominator) const;\n+\t[[nodiscard]] Rectangle translatedBy(const Point &point) const;\n };\n \n bool operator==(const Rectangle &lhs, const Rectangle &rhs);\n", "prefixes": [ "libcamera-devel", "PATCH/RFC" ] }