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

Fix #9386: use variant instead of unique_ptr to prevent compilers failing on the code generation #9391

Merged
merged 6 commits into from Jun 26, 2021

Conversation

@rubidium42
Copy link
Contributor

@rubidium42 rubidium42 commented Jun 21, 2021

Motivation / Problem

In the words of TB:

MacOS said: BOOOO
GCC said: fuck this shit

Description

Fixes #9386 by using std::variant to forego the need to generate code for a new and as such needing to bother with delete at a later stage.
The forwarding constructor of std::variant is quite picky (at least on MSVC). It does not like to resolve overloaded functions, so some functions needed to be renamed to be resolvable. Furthermore the 'naked' initializer for SaveLoad was causing issues at some places, so effectively 'name' it by adding SaveLoad to the SLE* macros.
Finally resolving from a variant to a type is not super trivial when you do not know the exact type, for this std::visit is used which helps but including that in a simple iterator is beyond my C++-foo, so fell back to a helper function to convert the type of the 'auto loop' to the needed/wanted const SettingDesc *.

Limitations

std::visit requires Mac OS 10.14 or higher which has been out-of-support for half a year... and that causes deprecations warnings that I can't solve.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')
@glx22
Copy link
Contributor

@glx22 glx22 commented Jun 21, 2021

Don't forget to update MACOSX_DEPLOYMENT_TARGET env variable in workflows too.

Loading

rubidium42 added 6 commits Jun 22, 2021
Rename the zero-parameter NetworkValidateClientName to NetworkValidateOurClientName to make it clearer it is performed on our client name, and to make it a non-overloaded function to aid with the variant being added a few commits later
One UpdateServiceInterval has two parameters to update the service interval for a vehicle type, the other for all vehicle types at once. Rename the latter to help with function resolution for the introduction of variants.
… the saveload macros

This to help variant's constructor to be able to resolve the constructor of the setting
…gDesc constructor

This as using std::string causes much more variables to be tracked, potentially causing problemes for certain compilers in certain situations
…ants instead of new + unique_ptr

With std::variant all memory can be figured out at compile time, so the compiler needs to keep track of fewer elements. It also saves out a unique_ptr and its memory management, over a slight impact for resolving a setting.
@TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Jun 22, 2021

Reminder we shouldn't forget to update https://github.com/OpenTTD/website/blob/master/_data/download-descriptions.yml if this lands.

Loading

@TrueBrain TrueBrain merged commit 98e653d into OpenTTD:master Jun 26, 2021
15 checks passed
Loading
@rubidium42 rubidium42 deleted the issue-9386 branch Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants