[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: isnan function conflicts with C++ standard library declarations

From: Martin Storsjö
Subject: Re: isnan function conflicts with C++ standard library declarations
Date: Wed, 28 Aug 2019 13:22:27 +0300 (EEST)
User-agent: Alpine 2.20 (DEB 67 2015-01-07)


On Wed, 28 Aug 2019, Bruno Haible wrote:


Martin Storsjö wrote:
When the isnan function is enabled in gnulib, the added bits in math.h
break if included in C++ translation units.

A minimal reproducion example is available at
https://martin.st/temp/gnulib-isnan-repro-0.0.0.tar.gz (preconfigured and
directly buildable) and
https://martin.st/temp/gnulib-isnan-repro-source.tar.gz (original source,
requires running gnulib-tool and autoreconf).

The error manifests both with GCC/libstdc++ and Clang/libc++, with error
messages like these:

In file included from myprog.cpp:2:0:
lib/math.h: In function ‘int isnan(float)’:
lib/math.h:2829:1: error: ‘int isnan(float)’ conflicts with a previous 
In file included from /usr/include/c++/7/math.h:36:0,
                  from lib/math.h:27,
                  from myprog.cpp:2:
/usr/include/c++/7/cmath:618:3: note: previous declaration ‘constexpr bool 
    isnan(float __x)

I reproduce the issue on mingw - thanks for a very nicely made
reproduction example -, and have applied the fix below.

Thanks for the very quick fix!

In file included from myprog.cpp:2:
lib/math.h:2829:36: error: 'isnan' is missing exception specification 'throw()'
       previous declaration is here
isnan(float __lcpp_x) _NOEXCEPT { return __libcpp_isnan(__lcpp_x); }

Probably I should test this also on macOS and other platforms...

Well in addition to macOS, I can also still reproduce the issue on Linux (Ubuntu 18.04, with its default GCC 7) as well, so maybe it's an issue with newer C++ standard headers, regardless of platform?

This issue can crop up e.g. when trying to build gettext for mingw (which
has got the gnulib isnan function bundled, even if it isn't used).

I'm regularly building gettext on mingw and haven't seen this issue. Therefore
thanks again for the reproduction example.

I ran into it while trying to build gettext with clang (with my pure-llvm based toolchain, at https://github.com/mstorsjo/llvm-mingw in case you're interested), so I presume there's something that goes different in gettext with clang/lld compared to gcc, that makes the few bits of C++ in gettext not be built and/or include gnulib's math.h with isnan. Otherwise I'm sure lots of others would have run into it ages ago. (Also, I only run into it if building a shared gettext, not with a static-only build, for some reason.)

// Martin

reply via email to

[Prev in Thread] Current Thread [Next in Thread]