[gjs/msvc.partial.fix: 4/4] enum-utils.h: Fix type ambiguity on Visual Studio
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/msvc.partial.fix: 4/4] enum-utils.h: Fix type ambiguity on Visual Studio
- Date: Thu, 11 Mar 2021 19:33:56 +0000 (UTC)
commit 59c873fe7fd1287d37f2649bf89ce88eba41dc11
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Mon Mar 8 16:56:12 2021 +0800
enum-utils.h: Fix type ambiguity on Visual Studio
Make the wrapper use the underlying type on Visual Studio builds, so
that we can pinpoint on the "right" bitwise operator to use on Visual
Studio builds, for the class enumeration(s) we may use.
Also, on the same token, define casts for Visual Studio for the wrapped
types for use on the '|=' and '&=' operators, as well as the '&' and '|'
operators that will be used in value assignments so that the compiler
does not get upset when converting between the underlying type and the
class enumeration type.
gi/arg-cache.cpp | 13 +++++++------
gi/arg-cache.h | 2 +-
gjs/enum-utils.h | 11 +++++++++--
3 files changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/gi/arg-cache.cpp b/gi/arg-cache.cpp
index 937f1ade..1598dd02 100644
--- a/gi/arg-cache.cpp
+++ b/gi/arg-cache.cpp
@@ -1249,7 +1249,8 @@ static const GjsArgumentMarshallers caller_allocates_out_marshallers = {
static inline void gjs_arg_cache_set_skip_all(GjsArgumentCache* self) {
self->marshallers = &skip_all_marshallers;
- self->flags = (GjsArgumentFlags::SKIP_IN | GjsArgumentFlags::SKIP_OUT);
+ self->flags =
+ static_cast<GjsArgumentFlags>(GjsArgumentFlags::SKIP_IN | GjsArgumentFlags::SKIP_OUT);
}
bool gjs_arg_cache_build_return(JSContext*, GjsArgumentCache* self,
@@ -1296,7 +1297,7 @@ bool gjs_arg_cache_build_return(JSContext*, GjsArgumentCache* self,
// marshal_in is ignored for the return value, but skip_in is not (it is
// used in the failure release path)
- self->flags = (self->flags | GjsArgumentFlags::SKIP_IN);
+ self->flags = static_cast<GjsArgumentFlags>(self->flags | GjsArgumentFlags::SKIP_IN);
self->marshallers = &return_value_marshallers;
return true;
@@ -1326,9 +1327,9 @@ static void gjs_arg_cache_build_enum_bounds(GjsArgumentCache* self,
self->contents.enum_type.enum_max = static_cast<uint32_t>(max);
if (min >= 0 && max > std::numeric_limits<int32_t>::max())
- self->flags = (self->flags | GjsArgumentFlags::UNSIGNED);
+ self->flags = static_cast<GjsArgumentFlags>(self->flags | GjsArgumentFlags::UNSIGNED);
else
- self->flags = (self->flags & ~GjsArgumentFlags::UNSIGNED);
+ self->flags = static_cast<GjsArgumentFlags>(self->flags & ~GjsArgumentFlags::UNSIGNED);
}
static void gjs_arg_cache_build_flags_mask(GjsArgumentCache* self,
@@ -1547,7 +1548,7 @@ static bool gjs_arg_cache_build_normal_in_arg(JSContext* cx,
self->marshallers = &string_in_transfer_none_marshallers;
else
self->marshallers = &string_in_marshallers;
- self->flags = (self->flags | GjsArgumentFlags::FILENAME);
+ self->flags = static_cast<GjsArgumentFlags>(self->flags | GjsArgumentFlags::FILENAME);
break;
case GI_TYPE_TAG_UTF8:
@@ -1555,7 +1556,7 @@ static bool gjs_arg_cache_build_normal_in_arg(JSContext* cx,
self->marshallers = &string_in_transfer_none_marshallers;
else
self->marshallers = &string_in_marshallers;
- self->flags = (self->flags & ~GjsArgumentFlags::FILENAME);
+ self->flags = static_cast<GjsArgumentFlags>(self->flags & ~GjsArgumentFlags::FILENAME);
break;
case GI_TYPE_TAG_INTERFACE: {
diff --git a/gi/arg-cache.h b/gi/arg-cache.h
index 54159df9..97648577 100644
--- a/gi/arg-cache.h
+++ b/gi/arg-cache.h
@@ -122,7 +122,7 @@ struct GjsArgumentCache {
arg_name = "instance parameter";
// Some calls accept null for the instance, but generally in an object
// oriented language it's wrong to call a method on null
- flags = GjsArgumentFlags::NONE | GjsArgumentFlags::SKIP_OUT;
+ flags = static_cast<GjsArgumentFlags>(GjsArgumentFlags::NONE | GjsArgumentFlags::SKIP_OUT);
}
void set_return_value() {
diff --git a/gjs/enum-utils.h b/gjs/enum-utils.h
index 80044b6d..2fc4524e 100644
--- a/gjs/enum-utils.h
+++ b/gjs/enum-utils.h
@@ -30,9 +30,16 @@ struct WrapperImpl {
}
};
+
+#if defined (__clang__) || defined (__GNUC__)
template <class EnumType>
using Wrapper =
std::conditional_t<is_class<EnumType>(), WrapperImpl<EnumType>, void>;
+#else
+template <class EnumType>
+using Wrapper =
+ std::conditional_t<is_class<EnumType>(), std::underlying_type_t<EnumType>, void>;
+#endif
} // namespace GjsEnum
template <class EnumType, class Wrapped = GjsEnum::Wrapper<EnumType>>
@@ -60,7 +67,7 @@ template <class EnumType, class Wrapped = GjsEnum::Wrapper<EnumType>>
constexpr std::enable_if_t<GjsEnum::is_class<EnumType>(), Wrapped&> operator|=(
EnumType& first, // NOLINT(runtime/references)
EnumType const& second) {
- first = (first | second);
+ first = static_cast<EnumType>(first | second);
return reinterpret_cast<Wrapped&>(first);
}
@@ -68,7 +75,7 @@ template <class EnumType, class Wrapped = GjsEnum::Wrapper<EnumType>>
constexpr std::enable_if_t<GjsEnum::is_class<EnumType>(), Wrapped&> operator&=(
EnumType& first, // NOLINT(runtime/references)
EnumType const& second) {
- first = (first & second);
+ first = static_cast<EnumType>(first & second);
return reinterpret_cast<Wrapped&>(first);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]