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 (or suppress) clang warnings #261

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions src/rttr/detail/conversion/number_conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ typename std::enable_if<std::is_floating_point<F>::value &&
bool>::type
convert_to(const F& from, T& to)
{
if (from > std::numeric_limits<T>::max())
if (from > static_cast<F>(std::numeric_limits<T>::max()))
return false; // value too large
else if (from < -std::numeric_limits<T>::max())
else if (from < static_cast<F>(-std::numeric_limits<T>::max()))
return false; // value to small

to = static_cast<T>(from);
Expand All @@ -151,7 +151,7 @@ typename std::enable_if<std::is_floating_point<F>::value &&
bool>::type
convert_to(const F& from, T& to)
{
if (from < 0 || from > std::numeric_limits<T>::max())
if (from < 0 || from > static_cast<F>(std::numeric_limits<T>::max()))
return false; // value too large

to = static_cast<T>(from);
Expand Down
9 changes: 9 additions & 0 deletions src/unit_tests/variant/variant_assign_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ TEST_CASE("move assignment", "[variant]")

TEST_CASE("variant::operator=() - self assignment", "[variant]")
{
#if RTTR_COMPILER == RTTR_COMPILER_CLANG || RTTR_COMPILER == RTTR_COMPILER_APPLECLANG
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need implementation for other compilers as well. I think @acki-m prefers this?

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wself-assign"
#endif

SECTION("self assign - empty")
{
variant a;
Expand All @@ -165,6 +170,10 @@ TEST_CASE("variant::operator=() - self assignment", "[variant]")

CHECK(a.is_valid() == true);
}

#if RTTR_COMPILER == RTTR_COMPILER_CLANG || RTTR_COMPILER == RTTR_COMPILER_APPLECLANG
#pragma clang diagnostic pop
#endif
}

/////////////////////////////////////////////////////////////////////////////////////////