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

emucore.h: fix build error on VC++ #12383

Merged
merged 1 commit into from
Jun 3, 2024
Merged

Conversation

SpecLad
Copy link
Contributor

@SpecLad SpecLad commented May 17, 2024

This compiler requires exception classes to be copyable, because it copies the exception object as part of std::current_exception(). This means that code like the following has to work:

emu_fatalerror e1(...);
emu_fatalerror e2(e1);

However, it doesn't, because in this case the perfect-forwarding constructor is a better match than the copy constructor. So the compiler tries to instantiate the perfect-forwarding constructor with Format=emu_fatalerror &, which fails, since that's not a valid format string type.

To fix this, disable the perfect-forwarding constructor when Format is a subclass of emu_fatalerror.

Fixes #11316

This compiler requires exception classes to be copyable, because it copies
the exception object as part of `std::current_exception()`. This means that
code like the following has to work:

    emu_fatalerror e1(...);
    emu_fatalerror e2(e1);

However, it doesn't, because in this case the perfect-forwarding constructor
is a better match than the copy constructor. So the compiler tries to
instantiate the perfect-forwarding constructor with `Format`=`emu_fatalerror &`,
which fails, since that's not a valid format string type.

To fix this, disable the perfect-forwarding constructor when `Format` is a
subclass of `emu_fatalerror`.
@SpecLad SpecLad mentioned this pull request May 17, 2024
@SimonN
Copy link

SimonN commented May 17, 2024

Hi! I'm the co-author of #11853 who proposed to fix this by adding a copy constructor that takes by mutable reference.

I like the idea of your fix: The perfect-forwarding constructor should indeed never contain anything related to emu_fatalerror; it should contain formatting arguments. Your enable_if fixes the template constructor at the root, regardless of any overloads. You use heavier machinery (SFINAE instead of overload resolution), but your solution ends up more accurate semantically than my added overload.

@pmackinlay pmackinlay merged commit ee9c41d into mamedev:master Jun 3, 2024
5 checks passed
@SpecLad SpecLad deleted the emucore-vcpp branch June 3, 2024 09:07
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.

Visual Studio 2022 fails to compile MAMe due to broken overload resolution
3 participants