This is an archive of the discontinued LLVM Phabricator instance.

Add new file test/support/test_comparisons.h
ClosedPublic

Authored by mclow.lists on Jul 24 2018, 7:00 PM.

Details

Reviewers
ldionne
EricWF
Summary

As I've been plowing through the <chrono> stuff, I found myself writing tests to make sure that the comparisons for a bunch of different types are "sane".

So I factored them out into something that can be used over and over.

Diff Detail

Event Timeline

mclow.lists created this revision.EditedJul 24 2018, 7:00 PM

Usage looks like this:

AssertComparisons6AreNoexcept<month>();
AssertComparisons6ReturnBool<month>();

static_assert(testComparisons6Values<month>( 5U,  5U), "");
static_assert(testComparisons6Values<month>( 5U, 10U), "");

Some of this stuff is marked constexpr despite it requiring C++14 constexpr semantics. Can they be non-constexpr in C++11 and still function? Or should the header explicitly require C++14 to be included?

Can they be non-constexpr in C++11 and still function?

Sure. I'll fix that.

EricWF accepted this revision.Jul 24 2018, 8:47 PM

Otherwise, I'm quite happy with this patch.

The only downside I see is if testComparisons6 fails, it will report the source of the failure as being in the header, and not provide information about the callee.
But I think having simpler tests to read and write is more important. Hopefully they shouldn't be falling too often anyway :-P

This revision is now accepted and ready to land.Jul 24 2018, 8:47 PM
mclow.lists closed this revision.Jul 24 2018, 9:22 PM

Committed as 337885 after changing constexpr -> TEST_CONSTEXPR_CXX14