[all-commits] [llvm/llvm-project] 82b47b: [libc++] Move abs and div into stdlib.h to fix hea...

Eric via All-commits all-commits at lists.llvm.org
Sat Feb 15 16:03:36 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 82b47b2978405f802a33b00d046e6f18ef6a47be
      https://github.com/llvm/llvm-project/commit/82b47b2978405f802a33b00d046e6f18ef6a47be
  Author: Eric Fiselier <eric at efcs.ca>
  Date:   2020-02-15 (Sat, 15 Feb 2020)

  Changed paths:
    M libcxx/include/math.h
    M libcxx/include/stdlib.h

  Log Message:
  -----------
  [libc++] Move abs and div into stdlib.h to fix header cycle.

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