Skip to content

Commit

Permalink
Fix -Wuseless-cast
Browse files Browse the repository at this point in the history
  • Loading branch information
SoapGentoo committed Nov 13, 2023
1 parent 6909df2 commit 0d7affb
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/pugixml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
# pragma option push
# pragma warn -8008 // condition is always false
# pragma warn -8066 // unreachable code
# define PUGI_IMPL_BORLANDC_CONST_CAST(to, from) const_cast<to>(from)
#else
# define PUGI_IMPL_BORLANDC_CONST_CAST(to, from) from
#endif

#ifdef __SNC__
Expand Down Expand Up @@ -183,6 +186,12 @@ using std::free;
# define PUGI_IMPL_FN_NO_INLINE PUGI_IMPL_NO_INLINE
#endif

#ifdef PUGIXML_WCHAR_MODE
# define PUGI_IMPL_REINTERPRET_CAST_CHAR(ptr) reinterpret_cast<char*>(ptr)
#else
# define PUGI_IMPL_REINTERPRET_CAST_CHAR(ptr) ptr
#endif

// uintptr_t
#if (defined(_MSC_VER) && _MSC_VER < 1600) || (defined(__BORLANDC__) && __BORLANDC__ < 0x561)
namespace pugi
Expand Down Expand Up @@ -1574,8 +1583,8 @@ PUGI_IMPL_NS_BEGIN

static value_type high(value_type result, uint32_t ch)
{
uint32_t msh = static_cast<uint32_t>(ch - 0x10000) >> 10;
uint32_t lsh = static_cast<uint32_t>(ch - 0x10000) & 0x3ff;
uint32_t msh = (ch - 0x10000U) >> 10;
uint32_t lsh = (ch - 0x10000U) & 0x3ff;

result[0] = static_cast<uint16_t>(0xD800 + msh);
result[1] = static_cast<uint16_t>(0xDC00 + lsh);
Expand Down Expand Up @@ -2455,7 +2464,7 @@ PUGI_IMPL_NS_BEGIN
{
// Move [old_gap_end, new_gap_start) to [old_gap_start, ...)
assert(s >= end);
memmove(end - size, end, reinterpret_cast<char*>(s) - reinterpret_cast<char*>(end));
memmove(end - size, end, PUGI_IMPL_REINTERPRET_CAST_CHAR(s) - PUGI_IMPL_REINTERPRET_CAST_CHAR(end));
}

s += count; // end of current gap
Expand All @@ -2472,7 +2481,7 @@ PUGI_IMPL_NS_BEGIN
{
// Move [old_gap_end, current_pos) to [old_gap_start, ...)
assert(s >= end);
memmove(end - size, end, reinterpret_cast<char*>(s) - reinterpret_cast<char*>(end));
memmove(end - size, end, PUGI_IMPL_REINTERPRET_CAST_CHAR(s) - PUGI_IMPL_REINTERPRET_CAST_CHAR(end));

return s - size;
}
Expand Down Expand Up @@ -5347,7 +5356,7 @@ namespace pugi

PUGI_IMPL_FN size_t xml_attribute::hash_value() const
{
return static_cast<size_t>(reinterpret_cast<uintptr_t>(_attr) / sizeof(xml_attribute_struct));
return reinterpret_cast<uintptr_t>(_attr) / sizeof(xml_attribute_struct);
}

PUGI_IMPL_FN xml_attribute_struct* xml_attribute::internal_object() const
Expand Down Expand Up @@ -6531,7 +6540,7 @@ namespace pugi

PUGI_IMPL_FN size_t xml_node::hash_value() const
{
return static_cast<size_t>(reinterpret_cast<uintptr_t>(_root) / sizeof(xml_node_struct));
return reinterpret_cast<uintptr_t>(_root) / sizeof(xml_node_struct);
}

PUGI_IMPL_FN xml_node_struct* xml_node::internal_object() const
Expand Down Expand Up @@ -6936,7 +6945,7 @@ namespace pugi
PUGI_IMPL_FN xml_node* xml_node_iterator::operator->() const
{
assert(_wrap._root);
return const_cast<xml_node*>(&_wrap); // BCC5 workaround
return PUGI_IMPL_BORLANDC_CONST_CAST(xml_node*, &_wrap);
}

PUGI_IMPL_FN xml_node_iterator& xml_node_iterator::operator++()
Expand Down Expand Up @@ -6997,7 +7006,7 @@ namespace pugi
PUGI_IMPL_FN xml_attribute* xml_attribute_iterator::operator->() const
{
assert(_wrap._attr);
return const_cast<xml_attribute*>(&_wrap); // BCC5 workaround
return PUGI_IMPL_BORLANDC_CONST_CAST(xml_attribute*, &_wrap);
}

PUGI_IMPL_FN xml_attribute_iterator& xml_attribute_iterator::operator++()
Expand Down Expand Up @@ -7058,7 +7067,7 @@ namespace pugi
PUGI_IMPL_FN xml_node* xml_named_node_iterator::operator->() const
{
assert(_wrap._root);
return const_cast<xml_node*>(&_wrap); // BCC5 workaround
return PUGI_IMPL_BORLANDC_CONST_CAST(xml_node*, &_wrap);
}

PUGI_IMPL_FN xml_named_node_iterator& xml_named_node_iterator::operator++()
Expand Down

0 comments on commit 0d7affb

Please sign in to comment.