[cfe-commits] [patch] Conditionalize use of 'long long' for libc++
Howard Hinnant
hhinnant at apple.com
Mon Nov 26 13:19:25 PST 2012
On Nov 26, 2012, at 4:05 PM, Dimitry Andric <dimitry at andric.com> wrote:
> On 2012-11-26 17:59, Howard Hinnant wrote:
>> On Nov 25, 2012, at 12:24 PM, Dimitry Andric <dimitry at andric.com> wrote:
>>> When using libc++ headers on FreeBSD, in combination with -std=c++98,
>>> -ansi or -std=c++03, the long long type is not supported. So in this
>>> case, several functions and types, like lldiv_t, strtoll(), are not
>>> declared.
>>>
>>> The attached patch conditionalizes those types and functions for libc++,
>>> using a _LIBCPP_HAS_NO_LONG_LONG define. This can easily be extended
>>> to other operating systems.
> ...
>> Thanks for the patch Dimitry.
>>
>> long long is used extensively throughout the libc++ headers. I'm counting over 200 uses (just a quick search which also picks up comments). The reason long long isn't already guarded is because libc++ wasn't meant to serve as a C++98/03 implementation.
>
> I understand; on FreeBSD, we indeed build the libc++ implementation with
> -std=c++0x. But the idea is that if there is a relatively simple way of
> using just the *headers* in that mode, it would be nice to have.
>
>
>> I'm wondering if your patch actually expands the usability of libc++ on FreeBSD. It only guards 2 of the 14 or so headers that use long long. I'm hesitant both to put in a partial solution, and also to clutter the library by guarding all uses.
>>
>> Can you clarify what differentiates <cstdlib> and <cwchar> from all of the other headers that use long long?
>
> When you use clang and gcc in -std=c++98 mode, they don't actually
> forbid using the long long type, unless you are using -pedantic (and
> then you get what you ask for :). So there really isn't a problem in
> using the type throughout the headers, and there is no need to
> conditionalize all of the uses.
>
> The reason <cstdlib> and <cwchar> are special, at least on FreeBSD, is
> that the corresponding C headers <stdlib.h> and <wchar.h> do not declare
> some macros, types, functions when compiling for __cplusplus < 201103L.
> Namely, the following:
>
> macros:
> ULLONG_MAX
> LLONG_MAX
> LLONG_MIN
> types:
> lldiv_t
> functions:
> atoll()
> llabs()
> lldiv()
> strtoll()
> strtoull()
> wcstoll()
> wcstoull()
>
> The patch I posted just conditionalizes these specific types and
> functions; the macros are only referenced in a comment in <climits>, so
> there is no need to do anything about those.
>
> Note, Linux (actually glibc) also has a define, __GLIBC_HAVE_LONG_LONG,
> used to conditionalize a similar list of functions like atoll, strtoll,
> etc. So the approach in my could also work for the Linux case. And
> I'll assume something like this is also used in the OSX headers...
>
Ok, thanks for the clarification. Committed revision 168610.
Howard
More information about the cfe-commits
mailing list