This is an archive of the discontinued LLVM Phabricator instance.

Protect std::string tests under libcpp-no-exceptions
ClosedPublic

Authored by rogfer01 on Nov 14 2016, 7:03 AM.

Diff Detail

Event Timeline

rogfer01 updated this revision to Diff 77811.Nov 14 2016, 7:03 AM
rogfer01 retitled this revision from to Protect std::string tests under libcpp-no-exceptions.
rogfer01 updated this object.
rogfer01 added reviewers: EricWF, mclow.lists, rmaprath.
rogfer01 added a subscriber: cfe-commits.
mclow.lists edited edge metadata.Nov 15 2016, 7:14 AM

We've been using a different pattern for this kind of tests (as we support more and more noexcept cases). Something like this (for the second change):

		template <class S>
		void
		test(const S& s, typename S::size_type pos, typename S::size_type n)
		{
			if (pos <= s.size())
			{
				S str = s.substr(pos, n);
				LIBCPP_ASSERT(str.__invariants());
				assert(pos <= s.size());
				typename S::size_type rlen = std::min(n, s.size() - pos);
				assert(str.size() == rlen);
				assert(S::traits_type::compare(s.data()+pos, str.data(), rlen) == 0);
			}
		#ifndef TEST_HAS_NO_EXCEPTIONS
			else
			{
				try
				{
					S str = s.substr(pos, n);
					assert(false);
				}
				catch (std::out_of_range&)
				{
					assert(pos > s.size());
				}
			}
		#endif
		}

I think that's much easier to read (and avoids duplication of the tests).

rogfer01 updated this revision to Diff 78012.Nov 15 2016, 8:43 AM
rogfer01 edited edge metadata.

Restructure to minimize code duplication.

mclow.lists accepted this revision.Nov 28 2016, 11:11 AM
mclow.lists edited edge metadata.

LGTM. Thanks.

This revision is now accepted and ready to land.Nov 28 2016, 11:11 AM
This revision was automatically updated to reflect the committed changes.