Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c++20 preparation workarounds #901

Merged
merged 5 commits into from Jul 28, 2020
Merged

c++20 preparation workarounds #901

merged 5 commits into from Jul 28, 2020

Conversation

JonnyH
Copy link
Collaborator

@JonnyH JonnyH commented Jun 20, 2020

This allows us to build with c++20 enabled - the biggest changes are the introduction of char8_t for utf8 character streams, and char32_t and similar no longer being implicitly cast-able to other integer types (As they're meant to be utf32 codepoints, not "numbers")

Note this is a /workaround/ - a long-term solution would be to replace the entire UString type with u8string (as they effectively mean the same thing - "utf8-encoded bytes" - and move the helpers we use to free functions (if they can't be replaced by standard library functions).

Unfortunately, pre-c++20 didn't define all the types (e.g. char8_t being distinct from 'char'), so until we move completely to only even newer c++ versions we probably need some level of hackery.

Though this is what we actually mean by UniChar, when we actually want
to output the numeric codepoint it means casts are necessary
As we already mean char8_t (that is utf8-encoded strings) we can just
reinterpret_cast this
@Atrosha
Copy link
Contributor

Atrosha commented Jun 20, 2020

When I set c++20 compiler options I get an errors on building with clang 10.0.0
gcc works fine.

/home/atrosha/OpenApoc/game/state/tilemap/collision.cpp:49:19: error: use of overloaded operator '!=' is ambiguous (with operand types 'OpenApoc::LineSegmentIterator<int, true>' and 'OpenApoc::LineSegmentIterator<int, true>')
        for (auto &point : line)
                         ^
/home/atrosha/OpenApoc/library/line.h:131:7: note: candidate function
        bool operator!=(const LineSegmentIterator &other) { return !(*this == other); }
             ^
/home/atrosha/OpenApoc/library/line.h:126:7: note: candidate function
        bool operator==(const LineSegmentIterator &other)
             ^
/home/atrosha/OpenApoc/library/line.h:126:7: note: candidate function (with reversed parameter order)
/home/atrosha/OpenApoc/game/state/tilemap/collision.cpp:49:21: note: in implicit call to 'operator!=' for iterator of type 'OpenApoc::LineSegment<int, true>'
        for (auto &point : line)
                           ^~~~
/home/atrosha/OpenApoc/library/line.h:27:39: note: selected 'begin' function with iterator type 'LineSegmentIterator<int, true>'
        LineSegmentIterator<T, conservative> begin() const;
                                             ^
1 warning and 1 error generated.
make[2]: *** [game/state/CMakeFiles/OpenApoc_GameState.dir/build.make:970: game/state/CMakeFiles/OpenApoc_GameState.dir/tilemap/collision.cpp.o] Error 1

This is technically correct anyway (as 'this' should be const), and
removes an ambiguity that clang doesn't like in it's current c++20 mode
@JonnyH JonnyH merged commit dcd10bb into OpenApoc:master Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants