Skip to content

Commit

Permalink
fix any equals if one argument is nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Jan 8, 2018
1 parent ff8840c commit 2f975ff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/shogun/lib/any.h
Expand Up @@ -153,7 +153,12 @@ namespace shogun
auto compare_impl(maybe_most_important, T* lhs, T* rhs)
-> decltype(lhs->equals(rhs))
{
return lhs->equals(rhs);
if (lhs && rhs)
return lhs->equals(rhs);
else if (!lhs && ! rhs)
return true;
else
return false;
}

template <class T>
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/lib/Any_unittest.cc
Expand Up @@ -285,6 +285,19 @@ TEST(Any, equals_pointer)
delete b;
}

TEST(Any, equals_null_pointer)
{
Simple* a = nullptr;
Simple* b = nullptr;
EXPECT_EQ(erase_type(a), erase_type(b));
EXPECT_EQ(erase_type(b), erase_type(a));

b = new Simple;
EXPECT_NE(erase_type(a), erase_type(b));
EXPECT_NE(erase_type(b), erase_type(a));
delete b;
}

TEST(Any, equals_value)
{
Simple a;
Expand Down

0 comments on commit 2f975ff

Please sign in to comment.