Opened 5 years ago

Closed 5 years ago

#13181 closed Feature Requests (fixed)

Boost test can't compare classes which have begin and end but not const_iterator

Reported by: marc@… Owned by: Raffi Enficiaud
Milestone: Boost 1.67.0 Component: test
Version: Boost 1.65.0 Severity: Regression
Keywords: Cc:

Description

The following code:

struct s
{
	const int *begin() const;
	const int *end() const;
};

bool operator==(s,s);
std::ostream &operator<<(std::ostream &out, s);

BOOST_AUTO_TEST_CASE(foo)
{
	s s1;
	s s2;
	BOOST_TEST(s1==s2);
}

When compiled in C++14 mode by gcc or clang, fails because s does not contain member types const_iterator and value_type. This works in C++03 mode, and it worked with boost 1.64.

The attached patch fixes the issue.

Attachments (1)

boost-test.diff (868 bytes ) - added by marc@… 5 years ago.

Download all attachments as: .zip

Change History (8)

by marc@…, 5 years ago

Attachment: boost-test.diff added

comment:1 by Raffi Enficiaud, 5 years ago

Owner: changed from Gennadiy Rozental to Raffi Enficiaud
Status: newassigned

Thanks for the report and the patch, will apply for 1.66. A couple of questions:

  • when you say "fails because s does not contain member types ...", does it mean compilation failure or test failure?
  • in 1.65, the behaviour changed to check only for the existence of begin/end, while up to 1.64, it was required to have also value_type and const_iterator (as well as size). In your case, that would mean that your class will switch to the collection comparison, while you are providing operator== and I guess you expect that this operator will be used. What is your suggestion?

As a workaround, does this

BOOST_TEST((s1==s2));

work as you expect?

comment:2 by Raffi Enficiaud, 5 years ago

Milestone: To Be DeterminedBoost 1.66.0

comment:3 by marc@…, 5 years ago

  1. I mean compilation failure.
  1. I would prefer doing collection comparison for the better test failure messages, but it's fine if it uses the user-provided equality operator.

The workaround does work.

comment:4 by Raffi Enficiaud, 5 years ago

Merged to branch topic/13181-collection-compare-missing-typename, but tests are failing, I will check

comment:5 by Raffi Enficiaud, 5 years ago

Building now

comment:6 by Raffi Enficiaud, 5 years ago

Milestone: Boost 1.66.0Boost 1.67.0

comment:7 by Raffi Enficiaud, 5 years ago

Resolution: fixed
Status: assignedclosed
Type: BugsFeature Requests

In master

Note: See TracTickets for help on using tickets.