[cfe-dev] Providing C99/C11 features from C++11 and above

Louis Dionne via cfe-dev cfe-dev at lists.llvm.org
Tue Feb 12 14:18:14 PST 2019


Actually, I just found precedent in limit.h and other headers: https://github.com/llvm-mirror/clang/blob/master/lib/Headers/limits.h#L92 <https://github.com/llvm-mirror/clang/blob/master/lib/Headers/limits.h#L92>.

I think that answers my question. I'll submit a Phab review and we'll see then :-)

Louis

> On Feb 12, 2019, at 16:37, Louis Dionne via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> In C++11 and above, C99/C11 features should be available even when using C++. For example, FLT_HAS_SUBNORM should be provided by <float.h>:
> 
>     $ cat <<EOF | clang++ -xc++ -std=c++11 -
>     #include <float.h>
> 
>     #ifndef FLT_HAS_SUBNORM
>     #   error "FLT_HAS_SUBNORM is missing"
>     #endif
>     EOF
> 
> This should also work when including `<cfloat>`. However, this currently:
> - fails in -std=c++11 or above
> - succeeds in -std=gnu++11 or above
> - succeeds in -std=c11 or above
> - succeeds in -std=gnu11 or above
> 
> If I understand correctly, the problem is that we currently have the following in clang/lib/Headers/float.h:
> 
>     #include_next <float.h> // pick up whatever the system provides
> 
>     ...
>     #undef FLT_HAS_SUBNORM // undefine what the system provides
>     ...
> 
>     // redefine our own version of the macro
>     #if __STDC_VERSION__ >= 201112L || !defined(__STRICT_ANSI__)
>         ...
>     #  define FLT_HAS_SUBNORM __FLT_HAS_DENORM__
>         ...
>     #endif
> 
> The #if block checks whether we're compiling in C11 or above, or whether we're compiling in a non-strict dialect (basically some any gnuXXX dialect). However, it doesn't check for strictly conforming C++, and as a result we don't get the definitions. I'd like to know what's the right strategy for providing these definitions in C++, and whether there's an established way of doing this already. Naively, changing the #if to
> 
>     #if __STDC_VERSION__ >= 201112L || !defined(__STRICT_ANSI__) || (defined(__cplusplus) && __cplusplus >= 201103L)
>         ...
>     #  define FLT_HAS_SUBNORM __FLT_HAS_DENORM__
>         ...
>     #endif
> 
> seems to do the job. But I'm not very familiar with how Clang's headers are imbricked into libc++ and how they interact with per-platform headers, so I'm asking here.
> 
> Thanks,
> Louis
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190212/08c0449c/attachment.html>


More information about the cfe-dev mailing list