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 MSVC Variant Workaround #100904

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 1 addition & 32 deletions core/object/make_virtuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def generate_version(argcount, const=False, returns=False, required=False):
callptrargsptr += ", "
argtext += f"m_type{i + 1}"
callargtext += f"m_type{i + 1} arg{i + 1}"
callsiargs += f"_to_variant(arg{i + 1})"
callsiargs += f"arg{i + 1}"
callsiargptrs += f"&vargs[{i}]"
callptrargs += (
f"PtrToArg<m_type{i + 1}>::EncodeT argval{i + 1} = (PtrToArg<m_type{i + 1}>::EncodeT)arg{i + 1};\\\n"
Expand Down Expand Up @@ -200,37 +200,6 @@ def run(target, source, env):
#define GDVIRTUAL_TRACK(m_virtual, m_initialized)
#endif

// MSVC WORKAROUND START
// FIXME The below helper functions are needed to work around an MSVC bug.
// They should be removed (by modifying core/object/make_virtuals.py) once the bug ceases to be triggered.
// The bug is triggered by the following code:
// `Variant(arg)`
// Through the introduction of the move constructor, MSVC forgets that `operator Variant()`
// is also a valid way to resolve this call. So for some argument types, it fails the call because
// it cannot convert to `Variant`.
// The function `_to_variant` helps the compiler select `.operator Variant()` for appropriate arguments using SFINAE.

template <typename T, typename = void>
struct has_variant_operator : std::false_type {};

template <typename T>
struct has_variant_operator<T, std::void_t<decltype(std::declval<T>().operator Variant())>> : std::true_type {};

// Function that is enabled if T has `.operator Variant()`.
template <typename T>
_ALWAYS_INLINE_ typename std::enable_if<has_variant_operator<T>::value, Variant>::type
_to_variant(T&& t) {
return std::forward<T>(t).operator Variant();
}

// Function that is enabled if T does not have `.operator Variant()`.
template <typename T>
_ALWAYS_INLINE_ typename std::enable_if<!has_variant_operator<T>::value, Variant>::type
_to_variant(T&& t) {
return Variant(std::forward<T>(t));
}
// MSVC WORKAROUND END

"""

for i in range(max_versions + 1):
Expand Down