This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Don't use C99 math ops in -std=c++03 mode
AbandonedPublic

Authored by rmaprath on Aug 26 2016, 8:56 AM.

Details

Reviewers
mclow.lists
Summary

C99 math ops should not be available when compiling in -std=c++03 mode.

Diff Detail

Event Timeline

rmaprath updated this revision to Diff 69383.Aug 26 2016, 8:56 AM
rmaprath retitled this revision from to [libcxx] Don't use C99 math ops in -std=c++03 mode.
rmaprath updated this object.
rmaprath added reviewers: mclow.lists, EricWF.
rmaprath added a subscriber: cfe-commits.
EricWF edited edge metadata.Aug 26 2016, 8:17 PM

We already provide many C++11 extensions in C++03 mode, why should this be an exception?

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

rmaprath updated this revision to Diff 69710.Aug 30 2016, 9:06 AM
rmaprath edited edge metadata.

Re-spinning a new patch to test the waters.

@EricWF: Does this approach look OK?

/ Asiri

rmaprath updated this revision to Diff 69962.Sep 1 2016, 2:32 AM

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.

mclow.lists edited edge metadata.Sep 3 2016, 4:16 PM

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

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.

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.
Disabling tests is OK though. ex #ifndef _LIBCPP_HAS_NO_C99_MATH.

EricWF resigned from this revision.Sep 15 2016, 3:15 PM
EricWF removed a reviewer: EricWF.

After talking with @rmaprath we have agreed to go in a different direction. Resigning as reviewer to keep my queue clean.

rmaprath abandoned this revision.Sep 16 2016, 1:52 AM

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