This is an archive of the discontinued LLVM Phabricator instance.

libcxx: Move #include_next <math.h> out of header guard in wrapper header.
ClosedPublic

Authored by pcc on Jan 22 2018, 6:35 PM.

Details

Summary

Code on Windows expects to be able to do:

#define _USE_MATH_DEFINES
#include <math.h>

and receive the definitions of mathematical constants, even if <math.h>
has previously been included. To support this scenario, re-include
<math.h> every time the wrapper header is included.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc created this revision.Jan 22 2018, 6:35 PM

LGTM, though I'll wait a few days before accepting in case Eric and Marshall have comments.

libcxx/include/math.h
11 ↗(On Diff #130996)

Could you add a comment explaining why this include is outside the header guards, since that's not standard?

Also, do you think it's worth adding a test for this? It would necessarily have to be Windows-only, and we don't have a Windows libc++ buildbot right now so it wouldn't catch regressions right away, but I think it'd be helpful for the future.

pcc updated this revision to Diff 131520.Jan 25 2018, 4:00 PM
  • Address review comments
pcc marked an inline comment as done.Jan 25 2018, 4:01 PM
compnerd accepted this revision.Jan 25 2018, 5:05 PM

Yay for extensions.

This revision is now accepted and ready to land.Jan 25 2018, 5:05 PM
This revision was automatically updated to reflect the committed changes.

I've raised https://bugs.llvm.org/show_bug.cgi?id=36382 against this. I think the patch to fix it is trivial.

A couple of points to consider here:

  • "Windows users expect" is not a compelling argument.
  • If done, this behavior should be windows-specific.
  • You should include <__config> before anything else.
libcxx/trunk/test/libcxx/depr/depr.c.headers/math_h.sh.cpp
12

This test should use the libc++ macro, not the naked _MSC_VER