This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Extract __clamp_to_integral to its own header
ClosedPublic

Authored by ldionne on Dec 7 2021, 1:42 PM.

Details

Summary

In addition to being more consistent with our approach for helpers, this
solves an actual issue where <cmath> was using numeric_limits but never
including the <limits> header directly. In a normal setup, this is not
an issue because the <math.h> header included by <cmath> does include
<limits>. However, I did stumble upon some code where that didn't work,
most likely because they were placing their own <math.h> header in front
of ours. I didn't bother investigating further.

Diff Detail

Event Timeline

ldionne requested review of this revision.Dec 7 2021, 1:42 PM
ldionne created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 7 2021, 1:42 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Quuxplusone added inline comments.
libcxx/include/module.modulemap
670

__numeric seems like a weird place for this, since IIUC it's actually used only in <random>. Shouldn't it go in __random?

libcxx/test/libcxx/numerics/clamp_to_integral.pass.cpp
18

This testing change implies that you meant to #include <__numeric/clamp_to_integral.h> from <numeric> (which would also be consistent with existing practice)... but you didn't.
If you move it to __random/, then this here should #include <random> instead of <numeric>.

ldionne updated this revision to Diff 392551.Dec 7 2021, 2:56 PM
ldionne marked 2 inline comments as done.

Address review comments

ldionne added inline comments.Dec 7 2021, 2:56 PM
libcxx/include/module.modulemap
670

I did that originally, but __clamp_to_integral seemed like a general algorithm that didn't belong to __random, so I changed it. I'll change it back to __random/ on the basis of "it's only used in __random" -- we can change that later if desired.

libcxx/test/libcxx/numerics/clamp_to_integral.pass.cpp
18

Yes, I forgot to do that indeed. Fixing, thanks.

Quuxplusone accepted this revision.Dec 7 2021, 7:11 PM
Quuxplusone added inline comments.
libcxx/include/__random/clamp_to_integral.h
41

type's :)

This revision is now accepted and ready to land.Dec 7 2021, 7:11 PM
ldionne marked an inline comment as done.Dec 8 2021, 5:33 AM
This revision was automatically updated to reflect the committed changes.