Skip to content

fpclassify namespace specification breaks build on NetBSD #59714

Description

@0-wiz-0

Version

24.7.0

Platform

NetBSD 11.99.1/x86_64

Subsystem

No response

What steps will reproduce the bug?

When building nodejs 24.7.0 on NetBSD, I see:

In file included from ../deps/v8/include/v8-platform.h:8,
                 from ../src/tracing/traced_value.h:8,
                 from ../src/tracing/traced_value.cc:5:
../src/tracing/traced_value.cc: In function 'std::string node::tracing::{anonymous}::DoubleToCString(double)':
../src/tracing/traced_value.cc:90:33: error: expected unqualified-id before '(' token
   90 |   switch (FPCLASSIFY_NAMESPACE::fpclassify(v)) {
      |                                 ^~~~~~~~~~

The problem is that fpclassify is a macro in math.h:

#define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x)

I use this patch as a workaround:

--- src/tracing/traced_value.cc.orig    2025-09-01 20:45:44.230556337 +0000
+++ src/tracing/traced_value.cc
@@ -87,7 +87,11 @@ std::string EscapeString(const char* val
 }

 std::string DoubleToCString(double v) {
+#if defined(__NetBSD__)
+  switch (fpclassify(v)) {
+#else
   switch (FPCLASSIFY_NAMESPACE::fpclassify(v)) {
+#endif
     case FP_NAN: return "\"NaN\"";
     case FP_INFINITE: return (v < 0.0 ? "\"-Infinity\"" : "\"Infinity\"");
     case FP_ZERO: return "0";

Adding || defined(NetBSD) to the FPCLASSIFY_NAMESPACE definition block at the top doesn't work because then it's still ::fpclassify which won't work with the macro.

If this is not allowed to be a macro and I should file a bug report with NetBSD, please let me know.
Thanks!

How often does it reproduce? Is there a required condition?

always

What is the expected behavior? Why is that the expected behavior?

see above

What do you see instead?

see above

Additional information

No response

Activity

  1. targos commented on Sep 2, 2025

    @targos
    Member

    What about adding #include <cmath> ? According to https://en.cppreference.com/w/cpp/numeric/math/fpclassify, that's where std::fpclassify is defined.

  2. 0-wiz-0 commented on Sep 2, 2025

    @0-wiz-0
    ContributorAuthor

    Thanks for the suggestion, @targos ! This patch works too:

    --- src/tracing/traced_value.cc.orig    2025-09-02 07:14:52.741019499 +0000
    +++ src/tracing/traced_value.cc
    @@ -9,6 +9,7 @@
     #include <unicode/utypes.h>
     #endif
    
    +#include <cmath>
     #include <sstream>
    
     #include "node_metadata.h"
    
    
  3. targos commented on Sep 2, 2025

    @targos
    Member

    Nice, feel free to open a PR with that patch!

  4. added a commit that references this issue on Sep 2, 2025
  5. 0-wiz-0 commented on Sep 2, 2025

    @0-wiz-0
    ContributorAuthor

    I've just done that: #59718
    Please let me know if any changes are needed!

  6. added a commit that references this issue on Sep 4, 2025
  7. added a commit that references this issue on Sep 4, 2025
  8. added a commit that references this issue on Sep 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions