Skip to content

Commit c585ab0

Browse files
committed
libpisp: Switch to C++20 standard
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 <naush@raspberrypi.com>
1 parent cc4b18f commit c585ab0

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ project('libpisp', 'c', 'cpp',
77
default_options : [
88
'werror=true',
99
'warning_level=2',
10-
'cpp_std=c++17',
10+
'cpp_std=c++20',
1111
'buildtype=release',
1212
],
1313
license : 'BSD-2-Clause')

src/libpisp/backend/tiling/types.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ struct Length2
2929
explicit Length2(int len) : Length2(len, len) {}
3030
int dx, dy;
3131
int operator[](Dir dir) const { return dir == Dir::Y ? dy : dx; }
32-
Length2 operator-(Length2 const &other) { return Length2(dx - other.dx, dy - other.dy); }
33-
Length2 operator/(int num) { return Length2(dx / num, dy / num); }
32+
Length2 operator-(Length2 const &other) const { return Length2(dx - other.dx, dy - other.dy); }
33+
Length2 operator/(int num) const { return Length2(dx / num, dy / num); }
3434
};
3535

3636
inline std::ostream &operator<<(std::ostream &os, Length2 const &l)
@@ -44,7 +44,7 @@ struct Crop
4444
Crop(int _start, int _end) : start(_start), end(_end) {}
4545
explicit Crop(int crop) : Crop(crop, crop) {}
4646
int start, end;
47-
Crop operator+(Crop const &other) { return Crop(start + other.start, end + other.end); }
47+
Crop operator+(Crop const &other) const { return Crop(start + other.start, end + other.end); }
4848
};
4949

5050
inline std::ostream &operator<<(std::ostream &os, Crop const &c)
@@ -61,11 +61,11 @@ struct Interval
6161
int End() const { return offset + length; }
6262
void SetStart(int start) { length += (offset - start), offset = start; } // leave End unchanged
6363
void SetEnd(int end) { length = end - offset; }
64-
bool operator==(Interval const &other) { return offset == other.offset && length == other.length; }
64+
bool operator==(Interval const &other) const { return offset == other.offset && length == other.length; }
6565
Interval operator-(Crop const &crop) const { return Interval(offset - crop.start, length - crop.start - crop.end); }
66-
Crop operator-(Interval const &other) { return Crop(other.offset - offset, End() - other.End()); }
67-
bool operator>(Interval const &other) { return offset <= other.offset && End() >= other.End(); } // contains
68-
bool operator<(Interval const &other) { return offset >= other.offset && End() <= other.End(); } // is contained
66+
Crop operator-(Interval const &other) const { return Crop(other.offset - offset, End() - other.End()); }
67+
bool operator>(Interval const &other) const { return offset <= other.offset && End() >= other.End(); } // contains
68+
bool operator<(Interval const &other) const { return offset >= other.offset && End() <= other.End(); } // is contained
6969
Interval &operator|=(int off)
7070
{
7171
if (off < offset)
@@ -88,7 +88,7 @@ struct Crop2
8888
Crop x, y;
8989
Crop operator[](Dir dir) const { return dir == Dir::Y ? y : x; }
9090
Crop &operator[](Dir dir) { return dir == Dir::Y ? y : x; }
91-
Crop2 operator+(Crop2 const &other) { return Crop2(x + other.x, y + other.y); }
91+
Crop2 operator+(Crop2 const &other) const { return Crop2(x + other.x, y + other.y); }
9292
};
9393

9494
inline std::ostream &operator<<(std::ostream &os, Crop2 const &c)
@@ -104,8 +104,8 @@ struct Interval2
104104
Interval x, y;
105105
Interval operator[](Dir dir) const { return dir == Dir::Y ? y : x; }
106106
Interval &operator[](Dir dir) { return dir == Dir::Y ? y : x; }
107-
bool operator==(Interval2 const &other) { return x == other.x && y == other.y; }
108-
bool operator!=(Interval2 const &other) { return !(*this == other); }
107+
bool operator==(Interval2 const &other) const { return x == other.x && y == other.y; }
108+
bool operator!=(Interval2 const &other) const { return !(*this == other); }
109109
};
110110

111111
inline std::ostream &operator<<(std::ostream &os, Interval2 const &i)

0 commit comments

Comments
 (0)