[libcxx-commits] [PATCH] D60097: Fix implementation of ::abs and std::abs LWG 2192.

Eric Fiselier via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 1 13:49:34 PDT 2019


EricWF created this revision.
EricWF added reviewers: mclow.lists, ldionne.
Herald added subscribers: jsji, jdoerfert, dexonsmith, fedor.sergeev, krytarowski.

All overloads of `::abs` and `std::abs` must be present in both `<cmath>` and `<cstdlib>`. This is problematic to implement because C defines `fabs` in `math.h` and `labs` in `stdlib.h`. This introduces a circular dependency between the two headers.

This patch implements that requirement by moving `abs` into `math.h` and making `stdlib.h` include `math.h`. In order to get the underlying C declarations from the "real" `stdlib.h` inside our `math.h` we need some trickery. Specifically we need to make `stdlib.h` include next itself.

Suggestions for a cleaner implementation are welcome.


Repository:
  rCXX libc++

https://reviews.llvm.org/D60097

Files:
  include/math.h
  include/stdlib.h
  test/std/depr/depr.c.headers/math_h.pass.cpp
  test/std/depr/depr.c.headers/stdlib_h.pass.cpp
  test/std/language.support/support.runtime/cstdlib.pass.cpp
  test/std/numerics/c.math/cmath.pass.cpp
  www/cxx1z_status.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60097.193174.patch
Type: text/x-patch
Size: 13106 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190401/c637e0bd/attachment-0001.bin>


More information about the libcxx-commits mailing list