From 90dd800735068bf851e9426fbc54ec7565db15eb Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Tue, 11 Nov 2025 13:26:04 +0000 Subject: [PATCH] libpisp: Switch to C++20 standard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switch the default build to use C++ 20 standard. There is a compile failure regarding and "ambiguous operator", fix this: In file included from /usr/include/boost/assert.hpp:64, from /usr/include/boost/log/detail/attachable_sstream_buf.hpp:24, from /usr/include/boost/log/utility/formatting_ostream.hpp:33, from /usr/include/boost/log/sources/record_ostream.hpp:36, from /usr/include/boost/log/trivial.hpp:24, from ../subprojects/libpisp/src/libpisp/common/logging.hpp:17, from ../subprojects/libpisp/src/libpisp/backend/tiling/input_stage.cpp:9: ../subprojects/libpisp/src/libpisp/backend/tiling/input_stage.cpp: In member function ‘virtual void tiling::InputStage::PushCropDown(tiling::Interval, tiling::Dir)’: ../subprojects/libpisp/src/libpisp/backend/tiling/input_stage.cpp:95:33: warning: C++20 says that these are ambiguous, even though the second is reversed: 95 | PISP_ASSERT(interval == input_interval_); | ^~~~~~~~~~~~~~~ ../subprojects/libpisp/src/libpisp/backend/tiling/input_stage.cpp:95:9: note: in expansion of macro ‘PISP_ASSERT’ 95 | PISP_ASSERT(interval == input_interval_); | ^~~~~~~~~~~ In file included from ../subprojects/libpisp/src/libpisp/backend/tiling/stages.hpp:11, from ../subprojects/libpisp/src/libpisp/backend/tiling/input_stage.hpp:9, from ../subprojects/libpisp/src/libpisp/backend/tiling/input_stage.cpp:7: ../subprojects/libpisp/src/libpisp/backend/tiling/types.hpp:64:14: note: candidate 1: ‘bool tiling::Interval::operator==(const tiling::Interval&)’ 64 | bool operator==(Interval const &other) { return offset == other.offset && length == other.length; } | ^~~~~~~~ ../subprojects/libpisp/src/libpisp/backend/tiling/types.hpp:64:14: note: candidate 2: ‘bool tiling::Interval::operator==(const tiling::Interval&)’ (reversed) ../subprojects/libpisp/src/libpisp/backend/tiling/types.hpp:64:14: note: try making the operator a ‘const’ member function Signed-off-by: Naushir Patuck --- meson.build | 2 +- src/libpisp/backend/tiling/types.hpp | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/meson.build b/meson.build index 3ac515c..9b78dd7 100644 --- a/meson.build +++ b/meson.build @@ -7,7 +7,7 @@ project('libpisp', 'c', 'cpp', default_options : [ 'werror=true', 'warning_level=2', - 'cpp_std=c++17', + 'cpp_std=c++20', 'buildtype=release', ], license : 'BSD-2-Clause') diff --git a/src/libpisp/backend/tiling/types.hpp b/src/libpisp/backend/tiling/types.hpp index 17ac840..0c60b7d 100644 --- a/src/libpisp/backend/tiling/types.hpp +++ b/src/libpisp/backend/tiling/types.hpp @@ -29,8 +29,8 @@ struct Length2 explicit Length2(int len) : Length2(len, len) {} int dx, dy; int operator[](Dir dir) const { return dir == Dir::Y ? dy : dx; } - Length2 operator-(Length2 const &other) { return Length2(dx - other.dx, dy - other.dy); } - Length2 operator/(int num) { return Length2(dx / num, dy / num); } + Length2 operator-(Length2 const &other) const { return Length2(dx - other.dx, dy - other.dy); } + Length2 operator/(int num) const { return Length2(dx / num, dy / num); } }; inline std::ostream &operator<<(std::ostream &os, Length2 const &l) @@ -44,7 +44,7 @@ struct Crop Crop(int _start, int _end) : start(_start), end(_end) {} explicit Crop(int crop) : Crop(crop, crop) {} int start, end; - Crop operator+(Crop const &other) { return Crop(start + other.start, end + other.end); } + Crop operator+(Crop const &other) const { return Crop(start + other.start, end + other.end); } }; inline std::ostream &operator<<(std::ostream &os, Crop const &c) @@ -61,11 +61,11 @@ struct Interval int End() const { return offset + length; } void SetStart(int start) { length += (offset - start), offset = start; } // leave End unchanged void SetEnd(int end) { length = end - offset; } - bool operator==(Interval const &other) { return offset == other.offset && length == other.length; } + bool operator==(Interval const &other) const { return offset == other.offset && length == other.length; } Interval operator-(Crop const &crop) const { return Interval(offset - crop.start, length - crop.start - crop.end); } - Crop operator-(Interval const &other) { return Crop(other.offset - offset, End() - other.End()); } - bool operator>(Interval const &other) { return offset <= other.offset && End() >= other.End(); } // contains - bool operator<(Interval const &other) { return offset >= other.offset && End() <= other.End(); } // is contained + Crop operator-(Interval const &other) const { return Crop(other.offset - offset, End() - other.End()); } + bool operator>(Interval const &other) const { return offset <= other.offset && End() >= other.End(); } // contains + bool operator<(Interval const &other) const { return offset >= other.offset && End() <= other.End(); } // is contained Interval &operator|=(int off) { if (off < offset) @@ -88,7 +88,7 @@ struct Crop2 Crop x, y; Crop operator[](Dir dir) const { return dir == Dir::Y ? y : x; } Crop &operator[](Dir dir) { return dir == Dir::Y ? y : x; } - Crop2 operator+(Crop2 const &other) { return Crop2(x + other.x, y + other.y); } + Crop2 operator+(Crop2 const &other) const { return Crop2(x + other.x, y + other.y); } }; inline std::ostream &operator<<(std::ostream &os, Crop2 const &c) @@ -104,8 +104,8 @@ struct Interval2 Interval x, y; Interval operator[](Dir dir) const { return dir == Dir::Y ? y : x; } Interval &operator[](Dir dir) { return dir == Dir::Y ? y : x; } - bool operator==(Interval2 const &other) { return x == other.x && y == other.y; } - bool operator!=(Interval2 const &other) { return !(*this == other); } + bool operator==(Interval2 const &other) const { return x == other.x && y == other.y; } + bool operator!=(Interval2 const &other) const { return !(*this == other); } }; inline std::ostream &operator<<(std::ostream &os, Interval2 const &i)