{"id":11129,"url":"https://patchwork.libcamera.org/api/patches/11129/?format=json","web_url":"https://patchwork.libcamera.org/patch/11129/","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":"<20210204035951.23751-2-laurent.pinchart@ideasonboard.com>","date":"2021-02-04T03:59:51","name":"[libcamera-devel,2/2] libcamera: geometry: Mark const functions with __nodiscard","commit_ref":"515211e8efd1412c09ae0bd30b6382b27b85036f","pull_url":null,"state":"accepted","archived":false,"hash":"f196edcc596b8b11f3cb02eb92897969bc4f2878","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11129/mbox/","series":[{"id":1648,"url":"https://patchwork.libcamera.org/api/series/1648/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1648","date":"2021-02-04T03:59:50","name":"[libcamera-devel,1/2] libcamera: Add macro to conditionally use [[nodiscard]]","version":1,"mbox":"https://patchwork.libcamera.org/series/1648/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11129/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11129/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 B08EABD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Feb 2021 04:00:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0A624613FA;\n\tThu,  4 Feb 2021 05:00:19 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5FC66613F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Feb 2021 05:00:17 +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 EE623813\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Feb 2021 05:00:16 +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=\"Df3Jep0I\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1612411217;\n\tbh=Kehm5PjOVwnrdjAiLiVtzALkQ8lrlm1054uXr//PqQs=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=Df3Jep0IqL5nXHWJGNa9x+UfRAXSmuBFQDthB/NLz0p/CPXrOueIlk1qHK3kCSuwp\n\tW23JrdbOCeqrJCe4KlbTKWPy2T6ldPkMIEkAS/bjt6hqv8C6R02SBbF7RnXg97cUZJ\n\t7JIpiwb30+YJl1knOlZ0HZ8d8hSV6wb+RrH71sGs=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  4 Feb 2021 05:59:51 +0200","Message-Id":"<20210204035951.23751-2-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.28.0","In-Reply-To":"<20210204035951.23751-1-laurent.pinchart@ideasonboard.com>","References":"<20210204035951.23751-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH 2/2] 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 the\nresult of the call.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/geometry.h | 29 ++++++++++++++++-------------\n 1 file changed, 16 insertions(+), 13 deletions(-)","diff":"diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\nindex 2f3a82e2afc3..fdd1b4678074 100644\n--- a/include/libcamera/geometry.h\n+++ b/include/libcamera/geometry.h\n@@ -11,6 +11,8 @@\n #include <algorithm>\n #include <string>\n \n+#include <libcamera/compiler.h>\n+\n namespace libcamera {\n \n class Rectangle;\n@@ -92,8 +94,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 +103,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       unsigned int vAlignment) const\n \t{\n \t\treturn {\n \t\t\t(width + hAlignment - 1) / hAlignment * hAlignment,\n@@ -110,7 +112,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 +120,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 +128,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 &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@@ -247,10 +249,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       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","2/2"]}