[all-commits] [llvm/llvm-project] d0846b: Recommit [libc++] Move abs and div into stdlib.h t...
Eric via All-commits
all-commits at lists.llvm.org
Tue Apr 28 06:43:14 PDT 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: d0846b432c3040bb04484f30239858d6cff9fc0d
https://github.com/llvm/llvm-project/commit/d0846b432c3040bb04484f30239858d6cff9fc0d
Author: Eric Fiselier <eric at efcs.ca>
Date: 2020-04-28 (Tue, 28 Apr 2020)
Changed paths:
M libcxx/include/math.h
M libcxx/include/stdlib.h
Log Message:
-----------
Recommit [libc++] Move abs and div into stdlib.h to fix header cycle.
This relands this commit as it broke the LLDB bot the first time it landed.
See also the discussion on https://reviews.llvm.org/rG82b47b2978405f802a33b00d046e6f18ef6a47be
Since D74892 this code should now also work on macOS.
Original description:
libc++ is careful to not fracture overload sets. When one overload
is visible to a user, all of them should be. Anything less causes
subtle bugs and ODR violations.
Previously, in order to support ::abs and ::div being supplied by
both <cmath> and <cstdlib> we had to do awful things that make
<math.h> and <stdlib.h> have header cycles and be non-modular.
This really breaks with modules.
Specifically the problem was that in C++ ::abs introduces overloads
for floating point numbers, these overloads forward to ::fabs,
which are defined in math.h. Therefore ::abs needed to be in math.h
too. But this required stdlib.h to include math.h and math.h to
include stdlib.h.
To avoid these problems the definitions have been moved to stddef.h
(which math includes), and the floating point overloads of ::abs
have been changed to call __builtin_fabs, which both Clang and GCC
support.
More information about the All-commits
mailing list