Skip to content

Commit

Permalink
improve error messages upon failed static assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzkry committed Aug 22, 2019
1 parent 6b1bef0 commit d8f5af7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
24 changes: 12 additions & 12 deletions googlemock/include/gmock/gmock-matchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2072,15 +2072,15 @@ class ContainerEqMatcher {
typedef typename View::type StlContainer;
typedef typename View::const_reference StlContainerReference;

static_assert(!std::is_const<Container>::value,
"Container type must not be const");
static_assert(!std::is_reference<Container>::value,
"Container type must not be a reference");

// We make a copy of expected in case the elements in it are modified
// after this matcher is created.
explicit ContainerEqMatcher(const Container& expected)
: expected_(View::Copy(expected)) {
// Makes sure the user doesn't instantiate this class template
// with a const or reference type.
(void)testing::StaticAssertTypeEq<Container,
GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>();
}
: expected_(View::Copy(expected)) {}

void DescribeTo(::std::ostream* os) const {
*os << "equals ";
Expand Down Expand Up @@ -2247,15 +2247,15 @@ class PointwiseMatcher {
typedef typename RhsView::type RhsStlContainer;
typedef typename RhsStlContainer::value_type RhsValue;

static_assert(!std::is_const<RhsContainer>::value,
"RhsContainer type must not be const");
static_assert(!std::is_reference<RhsContainer>::value,
"RhsContainer type must not be a reference");

// Like ContainerEq, we make a copy of rhs in case the elements in
// it are modified after this matcher is created.
PointwiseMatcher(const TupleMatcher& tuple_matcher, const RhsContainer& rhs)
: tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {
// Makes sure the user doesn't instantiate this class template
// with a const or reference type.
(void)testing::StaticAssertTypeEq<RhsContainer,
GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>();
}
: tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {}

template <typename LhsContainer>
operator Matcher<LhsContainer>() const {
Expand Down
9 changes: 4 additions & 5 deletions googlemock/include/gmock/internal/gmock-internal-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,8 @@ class StlContainerView {
typedef const type& const_reference;

static const_reference ConstReference(const RawContainer& container) {
// Ensures that RawContainer is not a const type.
testing::StaticAssertTypeEq<
RawContainer, typename std::remove_const<RawContainer>::type>();
static_assert(!std::is_const<RawContainer>::value,
"RawContainer type must not be const");
return container;
}
static type Copy(const RawContainer& container) { return container; }
Expand All @@ -423,8 +422,8 @@ class StlContainerView<Element[N]> {
typedef const type const_reference;

static const_reference ConstReference(const Element (&array)[N]) {
// Ensures that Element is not a const type.
testing::StaticAssertTypeEq<Element, RawElement>();
static_assert(std::is_same<Element, RawElement>::value,
"Element type must not be const");
return type(array, N, RelationToSourceReference());
}
static type Copy(const Element (&array)[N]) {
Expand Down

0 comments on commit d8f5af7

Please sign in to comment.