Skip to content

[libc++][test] Bogus loops in time.cal.ymdlast.nonmembers/comparisons.pass.cpp #100502

Closed
@StephanTLavavej

Description

@StephanTLavavej

Recently introduced by @mordante's #98169.

MSVC's /analyze complains:

D:\GitHub\STL\llvm-project\libcxx\test\std\time\time.cal\time.cal.ymdlast\time.cal.ymdlast.nonmembers\comparisons.pass.cpp(62) : warning C6294: Ill-defined for-loop.  Loop body not executed.
D:\GitHub\STL\llvm-project\libcxx\test\std\time\time.cal\time.cal.ymdlast\time.cal.ymdlast.nonmembers\comparisons.pass.cpp(63) : warning C6294: Ill-defined for-loop.  Loop body not executed.

This warning is usually a nuisance (complaining about loops that intentionally perform no iterations; calling them "ill-defined" isn't great either), but in this case it found actually-squirrely code 🐿️ :

// same month, different years
for (int i = 1000; i < 20; ++i)
for (int j = 1000; j < 20; ++j)
assert((testOrder(year_month_day_last{year{i}, month_day_last{January}},
year_month_day_last{year{j}, month_day_last{January}},
i == j ? std::strong_ordering::equal
: i < j ? std::strong_ordering::less
: std::strong_ordering::greater)));

I'm not sure what this code was intended to be doing. It appears that "same month, different years" previously looped from 1000 to 2000. Perhaps 1000 * 1000 = 1 million nested iterations was excessive, and the code should be looping from (say) 1000 to 1020?

Metadata

Metadata

Assignees

Labels

libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.test-suite

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions