C99 math ops should not be available when compiling in -std=c++03 mode.
Details
Diff Detail
Event Timeline
We already provide many C++11 extensions in C++03 mode, why should this be an exception?
This is kind of what I wanted to find out. Do we document what those extensions are?
We have quite a strict C library which is picky about what it exposes under different standards. For example, it won't expose C99 math ops if it is being used under __cplusplus < 201103L, which leads to compiler errors (when integrated with libc++ and used with -std=c++03) for a simple program like:
#include <math.h> int x;
We could make our C library a bit more lenient to fix this, but I couldn't find it documented anywhere what stand libcxx takes on C++03 support. I also sent an email to cfe-dev about this but didn't get much attention, so I decided to start with a patch instead :)
I'm happy to document these C++03 extensions on libcxx.llvm.org if I can find out what those extensions are. Any pointers?
Cheers,
/ Asiri
Simplified the patch a little bit more.
Now, library vendors should be able to define _LIBCPP_STRICT_C99_COMPATIBILITY and libc++ will not use/test C99 math functions in C++03/98 modes. Currently it's only the math functions, we can extend this approach to other affected areas if the approach is OK. Not 100% sure about the namings, can change them as needed.
@EricWF: Gentle ping.
We have quite a strict C library which is picky about what it exposes under different standards. For example, it won't expose C99 math ops if it is being used under __cplusplus < 201103L ...
That sounds .. odd to me, having the behavior of the C library depend on the value of __cplusplus
Currently we rely on C++11, C99, BSD, XOPEN, and GNU extensions in all dialects in the headers. We have to do so to safely and correctly implement locales and IO. In order to support this clang++ and g++ explicitly enable the C99 standard library by defining -D_GNU_SOURCE in the driver (Heres a 10yo libstdc++ bug about it).
"strict C95 compatibly" is not a feature for our C++ users. If your C library support C99 you should enable it, not make libc++ conforming. If we have to disable a couple of <math.h> functions to make that work that's OK. However I view that as a defect not a feature.
test/std/depr/depr.c.headers/math_h.pass.cpp | ||
---|---|---|
753 | Tests should be as portable as across standard libraries and not enabled by libc++ specific macros. |
After talking with @rmaprath we have agreed to go in a different direction. Resigning as reviewer to keep my queue clean.
Abandoning: we've decided to relax our C library to expose C99 functionality in C++98/03 modes. This is more inline with upstream intentions and allows us to get rid of some fiddly downstream libc++ patches as well.
Thanks Marshall and Eric for the comments / chats.
/ Asiri
Tests should be as portable as across standard libraries and not enabled by libc++ specific macros.
Disabling tests is OK though. ex #ifndef _LIBCPP_HAS_NO_C99_MATH.