Skip to content

Bug: <cfloat> incude will break <cmath> #1257

@cristianadam

Description

@cristianadam

Contact Details

No response

What happened?

Given the following C++ program:

#include <cfloat>
#include <cmath>
#include <iostream>

int main()
{
    std::cout << std::boolalpha
              << "signbit(+0.0) = " << std::signbit(+0.0) << '\n'
              << "signbit(-0.0) = " << std::signbit(-0.0) << '\n'
              << "signbit(+nan) = " << std::signbit(+NAN) << '\n'
              << "signbit(-nan) = " << std::signbit(-NAN) << '\n'
              << "signbit(+inf) = " << std::signbit(+INFINITY) << '\n'
              << "signbit(-inf) = " << std::signbit(-INFINITY) << '\n';
}

Compiling the program with g++ on Linux results:

$ g++ -O2 main.cpp -o signbit && ./signbit
signbit(+0.0) = false
signbit(-0.0) = true
signbit(+nan) = false
signbit(-nan) = true
signbit(+inf) = false
signbit(-inf) = true

Compiling with cosmoc++ results in:

$ cosmoc++ -O2 main.cpp -o signbit && ./signbit
In file included from /home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath:327,
                 from main.cpp:2:
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/math.h:415:20: error: 'signbit' has not been declared in 'std::__1::__math'
  415 | using std::__math::signbit;
      |                    ^~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/math.h:419:20: error: 'isfinite' has not been declared in 'std::__1::__math'
  419 | using std::__math::isfinite;
      |                    ^~~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/math.h:420:20: error: 'isgreater' has not been declared in 'std::__1::__math'
  420 | using std::__math::isgreater;
      |                    ^~~~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/math.h:421:20: error: 'isgreaterequal' has not been declared in 'std::__1::__math'
  421 | using std::__math::isgreaterequal;
      |                    ^~~~~~~~~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/math.h:422:20: error: 'isinf' has not been declared in 'std::__1::__math'
  422 | using std::__math::isinf;
      |                    ^~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/math.h:423:20: error: 'isless' has not been declared in 'std::__1::__math'
  423 | using std::__math::isless;
      |                    ^~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/math.h:424:20: error: 'islessequal' has not been declared in 'std::__1::__math'
  424 | using std::__math::islessequal;
      |                    ^~~~~~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/math.h:425:20: error: 'islessgreater' has not been declared in 'std::__1::__math'
  425 | using std::__math::islessgreater;
      |                    ^~~~~~~~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/math.h:426:20: error: 'isnan' has not been declared in 'std::__1::__math'
  426 | using std::__math::isnan;
      |                    ^~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/math.h:427:20: error: 'isnormal' has not been declared in 'std::__1::__math'
  427 | using std::__math::isnormal;
      |                    ^~~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/math.h:428:20: error: 'isunordered' has not been declared in 'std::__1::__math'
  428 | using std::__math::isunordered;
      |                    ^~~~~~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/math.h:493:20: error: 'signbit' has not been declared in 'std::__1::__math'
  493 | using std::__math::signbit;
      |                    ^~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath:346:9: error: 'signbit' has not been declared in '::'
  346 | using ::signbit _LIBCPP_USING_IF_EXISTS;
      |         ^~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath:348:9: error: 'isfinite' has not been declared in '::'
  348 | using ::isfinite _LIBCPP_USING_IF_EXISTS;
      |         ^~~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath:349:9: error: 'isinf' has not been declared in '::'
  349 | using ::isinf _LIBCPP_USING_IF_EXISTS;
      |         ^~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath:350:9: error: 'isnan' has not been declared in '::'
  350 | using ::isnan _LIBCPP_USING_IF_EXISTS;
      |         ^~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath:351:9: error: 'isnormal' has not been declared in '::'
  351 | using ::isnormal _LIBCPP_USING_IF_EXISTS;
      |         ^~~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath:352:9: error: 'isgreater' has not been declared in '::'
  352 | using ::isgreater _LIBCPP_USING_IF_EXISTS;
      |         ^~~~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath:353:9: error: 'isgreaterequal' has not been declared in '::'
  353 | using ::isgreaterequal _LIBCPP_USING_IF_EXISTS;
      |         ^~~~~~~~~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath:354:9: error: 'isless' has not been declared in '::'
  354 | using ::isless _LIBCPP_USING_IF_EXISTS;
      |         ^~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath:355:9: error: 'islessequal' has not been declared in '::'
  355 | using ::islessequal _LIBCPP_USING_IF_EXISTS;
      |         ^~~~~~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath:356:9: error: 'islessgreater' has not been declared in '::'
  356 | using ::islessgreater _LIBCPP_USING_IF_EXISTS;
      |         ^~~~~~~~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath:357:9: error: 'isunordered' has not been declared in '::'
  357 | using ::isunordered _LIBCPP_USING_IF_EXISTS;
      |         ^~~~~~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath:358:9: error: 'isunordered' has not been declared in '::'
  358 | using ::isunordered _LIBCPP_USING_IF_EXISTS;
      |         ^~~~~~~~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath: In function 'constexpr bool std::__1::__constexpr_isnan(_A1)':
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath:591:15: error: 'isnan' is not a member of 'std'
  591 |   return std::isnan(__lcpp_x);
      |               ^~~~~
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath: In function 'constexpr bool std::__1::__constexpr_isinf(_A1)':
/home/cristian/Projects/cosmopolitan/repo/cosmocc/include/third_party/libcxx/cmath:605:15: error: 'isinf' is not a member of 'std'
  605 |   return std::isinf(__lcpp_x);
      |               ^~~~~
main.cpp: In function 'int main()':
main.cpp:8:45: error: 'signbit' is not a member of 'std'
    8 |               << "signbit(+0.0) = " << std::signbit(+0.0) << '\n'
      |                                             ^~~~~~~
main.cpp:9:45: error: 'signbit' is not a member of 'std'
    9 |               << "signbit(-0.0) = " << std::signbit(-0.0) << '\n'
      |                                             ^~~~~~~
main.cpp:10:45: error: 'signbit' is not a member of 'std'
   10 |               << "signbit(+nan) = " << std::signbit(+NAN) << '\n'
      |                                             ^~~~~~~
main.cpp:11:45: error: 'signbit' is not a member of 'std'
   11 |               << "signbit(-nan) = " << std::signbit(-NAN) << '\n'
      |                                             ^~~~~~~
main.cpp:12:45: error: 'signbit' is not a member of 'std'
   12 |               << "signbit(+inf) = " << std::signbit(+INFINITY) << '\n'
      |                                             ^~~~~~~
main.cpp:13:45: error: 'signbit' is not a member of 'std'
   13 |               << "signbit(-inf) = " << std::signbit(-INFINITY) << '\n';

Commenting the first #include <cfloat> fixes the errors.

Version

$ cosmoc++ --version
cosmoc++ (GCC) 14.1.0

What operating system are you seeing the problem on?

Linux

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    medium severityUsed to report medium severity bugs (e.g. Malfunctioning Features but still useable)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions