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

build: C++20 migration (again^3) #5514

Merged
merged 18 commits into from
Oct 8, 2024

Conversation

scarf005
Copy link
Member

@scarf005 scarf005 commented Oct 5, 2024

Checklist

Required

Optional

  • This is a PR that modifies build process or code organization.
    • Please document the changes in the appropriate location in the doc/ folder.
    • If documentation for this feature or process does not exist, please write it.
    • If the change alters versions of software required to build or work with the game, please document it.

Purpose of change

continuation of #1624 and #2003 and #2341

  • applied <=> operator and concepts to showcase new C++20 features
  • use sweet sweet ranges

Describe the solution

Describe alternatives you've considered

completely overhaul codebase to use std::filesystem? MSVC tests results are really weird, fails even on ascii filesystem tests and not sure why

Testing

intentionally ignoring clang-tidy failures because

  • the automated changes are too large
  • currently preparing for following PR that applies all available automated fixes

Additional context

@github-actions github-actions bot added docs PRs releated to docs page src changes related to source code. tests changes related to tests labels Oct 5, 2024
@scarf005 scarf005 marked this pull request as ready for review October 5, 2024 16:15
scarf005 and others added 13 commits October 6, 2024 12:24
also
1) fix incomplete achievement_requirement

2) remove user defined copy constructor: error: definition of implicit copy assignment operator for 'point_with_value' is deprecated because it has a user-declared copy constructor [-Werror,-Wdeprecated-copy]

Co-authored-by: AngelicosPhosphoros <angelicos.phosphoros@protonmail.com>
1. add `concepts_utility.h` for storing useful concepts related headers.
2. uses `Arithmatic` concepts to ensure they're numbers.
3. uses spaceship operator for comparison.
4. uses auto and arrow returns to make templates readable.
5. make fabs and fmod constexpr.

Co-authored-by: Coolthulhu <Coolthulhu@gmail.com>
it works as a false positive on spaceship operators `<=>`
Copy link
Collaborator

@OrenAudeles OrenAudeles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, just have some questions. The effect the Arithmetic concept has on the templates in units_def.h is crazy!

info += colorize( vgettext( "Maintainer", "Maintainers", mod->maintainers.size() ),
c_light_blue ) + u8":\u00a0"/*non-breaking space*/ + enumerate_as_string( mod->maintainers ) + "\n";
c_light_blue ) +
// HACK: Cannot fix that without switching whole project to std::u8string.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How painful would it be to change everything to u8strings?
Might not need to update everything to u8strings, but user-facing stuff might need to be. It's a shame that it "just worked"(tm) in pre-20 but is specialized to u8strings now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -137,7 +137,7 @@ void vehicle::add_toggle_to_opts( std::vector<uilist_entry> &options,
name );
options.emplace_back( -1, allow, key, msg );

actions.emplace_back( [ = ] {
actions.emplace_back( [ =, this ] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does adding this to the captures change anything about how the lambda functions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since c++20 implicit this caputure has been made error

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay coolie 👍

@OrenAudeles
Copy link
Collaborator

the Clang-tidy (tiles) / build (pull_request) failure is emitting this error. Not sure what to do about that one since it's in sol files.
Screenshot from 2024-10-06 02-12-25
and the Cataclysm Windows build (Cmake + MSVC) / Build (pull_request) failure is in tests/filesystem_test.cpp at the filesystem_utf8[_comp|_decomp] tests. filesystem_ascii passes just fine, so something is still weird about filesystem tests. The failure point is all on the same line checking for directory existence right after calling bool remove_tree( const std::string &path ) so it's likely failing there.

@scarf005 scarf005 force-pushed the build/c++20-again branch 3 times, most recently from d10a685 to d2c81eb Compare October 6, 2024 12:57
like what's the problem
rationale:
- spent past 6 hours trying to fix this and failed
- currently not worth the effort considering it's not used anywhere in-game
@chaosvolt
Copy link
Member

Oren asked me in the discord server to uncomment the lines that were causing problems and test if it works on mine or not, it indeed does fail as expected on windows for me:
image

Copy link
Collaborator

@OrenAudeles OrenAudeles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than clang-tidy whining about a static assertion error that doesn't come up while actually building, and claims of not being able to find <lua.h>, both involving sol I don't see anything else preventing merging. The clang-tidy errors are nonsense.

Will need to look at the filesystem_test issues revolving around remove_tree and dir_exists since they only show up as an issue on the windows build. Thankfully remove_tree is only used as part of this one test and not the game proper.

@@ -9,7 +9,6 @@
#include "character.h"
#include "color.h"
#include "debug.h"
#include "enums.h"
#include "event.h"
#include "event_statistics.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include "event_statistics.h" and #include "json.h" are no longer needed in this file since they've been added to achievement.h

struct object_names_collection;

struct extended_photo_def : public JsonDeserializer, public JsonSerializer {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the definition of extended_photo_def up to here isn't really relevant to the PR scope.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc it was somewhat related to build error but i forgot

info += colorize( vgettext( "Maintainer", "Maintainers", mod->maintainers.size() ),
c_light_blue ) + u8":\u00a0"/*non-breaking space*/ + enumerate_as_string( mod->maintainers ) + "\n";
c_light_blue ) +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extraneous + at the end of this line

Suggested change
c_light_blue ) +
c_light_blue )

@@ -34,7 +34,7 @@

// beginning of sol/version.hpp

#include <sol/config.hpp>
#include "./config.hpp"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than this line that clang-tidy was complaining about the only changes to this file are whitespace. Might be able to discard all changes to this file so clang-tidy skips it and doesn't get mad about something stupid.

Could probably keep it as <sol/config.hpp> in that case since it has no effect on compilation. Not entirely sure, though :/

@@ -38,7 +38,7 @@ static_assert(false, "sol.hpp must be included via catalua_sol.h");

// beginning of sol/version.hpp

#include <sol/config.hpp>
#include "./config.hpp"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly to forward.hpp the changes in this file are mostly cosmetic whitespace removals that don't change functionality. Could change back to #include <sol/config.hpp> while getting rid of all changes to this file and clang-tidy will probably shut up about it.

throw se;
}
}
System.loadLibrary(libraryName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is removing the try-catch block here safe to do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, because the original try-catch re-throws exceptions which means it essentially does nothing

Copy link
Member

@chaosvolt chaosvolt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Compiled and loaded a save.
  2. Saved game and deleted world without issue.
  3. Created a game without issue.
  4. Started new game in new world, chargen and entering game world also works fine.
  5. Saved this new game for good measure too.

@scarf005 scarf005 merged commit fd85e05 into cataclysmbnteam:main Oct 8, 2024
11 of 12 checks passed
@scarf005 scarf005 deleted the build/c++20-again branch October 8, 2024 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs PRs releated to docs page src changes related to source code. tests changes related to tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants