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

Add nice error messages for unsupported && and || #1480

Merged
merged 1 commit into from
Jan 1, 2019
Merged
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
15 changes: 15 additions & 0 deletions include/internal/catch_decomposer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "catch_tostring.h"
#include "catch_stringref.h"
#include "catch_meta.hpp"

#include <iosfwd>

Expand Down Expand Up @@ -143,6 +144,20 @@ namespace Catch {
return { static_cast<bool>(m_lhs <= rhs), m_lhs, "<=", rhs };
}

template<typename RhsT>
auto operator && ( RhsT const& ) -> BinaryExpr<LhsT, RhsT const&> const {
static_assert(always_false<RhsT>::value,
"operator&& is not supported inside assertions, "
"wrap the expression inside parentheses, or decompose it");
}

template<typename RhsT>
auto operator || ( RhsT const& ) -> BinaryExpr<LhsT, RhsT const&> const {
static_assert(always_false<RhsT>::value,
"operator|| is not supported inside assertions, "
"wrap the expression inside parentheses, or decompose it");
}

auto makeUnaryExpr() const -> UnaryExpr<LhsT> {
return UnaryExpr<LhsT>{ m_lhs };
}
Expand Down
5 changes: 5 additions & 0 deletions include/internal/catch_meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef TWOBLUECUBES_CATCH_META_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_META_HPP_INCLUDED

#include <type_traits>

template< typename... >
struct TypeList{};

Expand Down Expand Up @@ -73,4 +75,7 @@ struct combine
};
};

template<typename T>
struct always_false : std::false_type {};

#endif // TWOBLUECUBES_CATCH_META_HPP_INCLUDED