Skip to content

Commit

Permalink
[libcxx] chrono::month_weekday should not be default constructible
Browse files Browse the repository at this point in the history
It was not in P0355R7, nor has it ever been so in a working draft.

Drive-by:
* tests should test something: fix loop bounds so initial value is not >= final value
* calender type streaming tests are useless - let's remove them
* don't declare printf, especially if you don't intend to use it

Differential Revision: https://reviews.llvm.org/D117638
  • Loading branch information
CaseyCarter committed Jan 20, 2022
1 parent 8105e40 commit 864b5b4
Show file tree
Hide file tree
Showing 54 changed files with 148 additions and 858 deletions.
3 changes: 3 additions & 0 deletions libcxx/docs/ReleaseNotes.rst
Expand Up @@ -108,6 +108,9 @@ API Changes
as either ``for (auto&& c : path)`` or ``for (const auto& c : path)``.
``std::reverse_iterator<path::iterator>`` is no longer rejected.

- Removed the nonstandard default constructor from ``std::chrono::month_weekday``.
You must now explicitly initialize with a ``chrono::month`` and
``chrono::weekday_indexed`` instead of "meh, whenever".

ABI Changes
-----------
Expand Down
1 change: 0 additions & 1 deletion libcxx/include/__chrono/calendar.h
Expand Up @@ -540,7 +540,6 @@ class month_weekday {
chrono::month __m;
chrono::weekday_indexed __wdi;
public:
month_weekday() = default;
constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept
: __m{__mval}, __wdi{__wdival} {}
inline constexpr chrono::month month() const noexcept { return __m; }
Expand Down
Expand Up @@ -33,7 +33,7 @@ int main(int, char**)
static_assert(testComparisons6Values<day>(0U, 0U), "");
static_assert(testComparisons6Values<day>(0U, 1U), "");

// Some 'ok' values as well
// Some 'ok' values as well
static_assert(testComparisons6Values<day>( 5U, 5U), "");
static_assert(testComparisons6Values<day>( 5U, 10U), "");

Expand Down

This file was deleted.

Expand Up @@ -48,7 +48,7 @@ int main(int, char**)
assert(!(month_day{month{i}, day{32}}.ok()));
}

// If the month is not ok, all the days are bad
// If the month is not ok, all the days are bad
for (unsigned i = 1; i <= 35; ++i)
assert(!(month_day{month{13}, day{i}}.ok()));

Expand Down
Expand Up @@ -50,15 +50,15 @@ int main(int, char**)
month_day{std::chrono::February, day{1}},
false, true), "");

// same day, different months
// same day, different months
for (unsigned i = 1; i < 12; ++i)
for (unsigned j = 1; j < 12; ++j)
assert((testComparisons6(
month_day{month{i}, day{1}},
month_day{month{j}, day{1}},
i == j, i < j )));

// same month, different days
// same month, different days
for (unsigned i = 1; i < 31; ++i)
for (unsigned j = 1; j < 31; ++j)
assert((testComparisons6(
Expand Down

This file was deleted.

Expand Up @@ -35,10 +35,10 @@ int main(int, char**)
static_assert( testComparisons6Values<month_day_last>(month{1}, month{1}), "");
static_assert( testComparisons6Values<month_day_last>(month{1}, month{2}), "");

// same day, different months
for (unsigned i = 1; i < 12; ++i)
for (unsigned j = 1; j < 12; ++j)
assert((testComparisons6Values<month_day_last>(month{i}, month{j})));
// same day, different months
for (unsigned i = 1; i <= 12; ++i)
for (unsigned j = 1; j <= 12; ++j)
assert(testComparisons6Values<month_day_last>(month{i}, month{j}));

return 0;
return 0;
}
Expand Up @@ -36,7 +36,7 @@ int main(int, char**)
assert( mdl.ok());
}

// If the month is not ok, all the days are bad
// If the month is not ok, all the days are bad
for (unsigned i = 13; i <= 50; ++i)
{
month_day_last mdl{month{i}};
Expand Down

This file was deleted.

Expand Up @@ -36,12 +36,12 @@ int main(int, char**)
static_assert(testComparisons6Values<month>(0U ,0U), "");
static_assert(testComparisons6Values<month>(0U, 1U), "");

// Some 'ok' values as well
// Some 'ok' values as well
static_assert(testComparisons6Values<month>( 5U, 5U), "");
static_assert(testComparisons6Values<month>( 5U, 10U), "");

for (unsigned i = 1; i < 10; ++i)
for (unsigned j = 10; j < 10; ++j)
for (unsigned i = 1; i <= 12; ++i)
for (unsigned j = 1; j <= 12; ++j)
assert(testComparisons6Values<month>(i, j));

return 0;
Expand Down
Expand Up @@ -31,12 +31,13 @@ constexpr bool testConstexpr()
{
M m{5};
Ms offset{3};
if (m - offset != M{2}) return false;
if (m - M{2} != offset) return false;
assert(m - offset == M{2});
assert(m - M{2} == offset);
}

// Check the example
if (M{1} - M{2} != Ms{11}) return false;
// Check the example
assert(M{1} - M{2} == Ms{11});

return true;
}

Expand All @@ -51,18 +52,18 @@ int main(int, char**)
ASSERT_SAME_TYPE(month , decltype(std::declval<month>() - std::declval<months>()));
ASSERT_SAME_TYPE(months, decltype(std::declval<month>() - std::declval<month> ()));

static_assert(testConstexpr<month, months>(), "");
static_assert(testConstexpr<month, months>(), "");

month m{6};
for (unsigned i = 1; i <= 12; ++i)
{
month m1 = m - months{i};
// months off = m - month {i};
// months off = m - month {i};
int exp = 6 - i;
if (exp < 1)
exp += 12;
assert(static_cast<unsigned>(m1) == static_cast<unsigned>(exp));
// assert(off.count() == static_cast<unsigned>(exp));
// assert(off.count() == static_cast<unsigned>(exp));
}

return 0;
Expand Down
Expand Up @@ -36,10 +36,10 @@ constexpr bool testConstexpr()
{
M m{1};
Ms offset{4};
if (m + offset != M{5}) return false;
if (offset + m != M{5}) return false;
// Check the example
if (M{2} + Ms{11} != M{1}) return false;
assert(m + offset == M{5});
assert(offset + m == M{5});
// Check the example
assert(M{2} + Ms{11} == M{1});
return true;
}

Expand Down Expand Up @@ -69,5 +69,5 @@ int main(int, char**)
assert(static_cast<unsigned>(m2) == exp);
}

return 0;
return 0;
}

This file was deleted.

Expand Up @@ -31,8 +31,6 @@ int main(int, char**)
ASSERT_NOEXCEPT( std::declval<const month_weekday>().month());
ASSERT_SAME_TYPE(month, decltype(std::declval<const month_weekday>().month()));

static_assert( month_weekday{}.month() == month{}, "");

for (unsigned i = 1; i <= 50; ++i)
{
month_weekday md(month{i}, weekday_indexed{Sunday, 1});
Expand Down
Expand Up @@ -44,9 +44,9 @@ int main(int, char**)
assert(mwd.ok() == (j >= 1 && j <= 5));
}

// If the month is not ok, all the weekday_indexed are bad
// If the month is not ok, all the weekday_indexed are bad
for (unsigned i = 1; i <= 10; ++i)
assert(!(month_weekday{month{13}, weekday_indexed{Sunday, i}}.ok()));

return 0;
return 0;
}

0 comments on commit 864b5b4

Please sign in to comment.