Ticket #11219 (closed defect: wontfix)

Opened 6 months ago

Last modified 3 months ago

wxIsNaN doesn't compile on Snow Leopard if cmath is included after wx/math.j

Reported by: SnowLeopard Owned by:
Priority: low Milestone:
Component: base Version: 2.9.0
Keywords: wxIsNaN Cc:
Blocked By: Patch: no
Blocking:

Description

When I call wxIsNaN in my code, I get an "isnan was not declared in this scope" compile message.

I have <wx/math> included and compiles fine on windows XP.

I'm on Snow Leopard with 2.9.0

Change History

Changed 6 months ago by SnowLeopard

Maybe you have to use "gnu_cxx::isnan" or something special like that? I found this article if that helps at all:

 http://lists.apple.com/archives/darwin-development/2002/Aug/msg00485.html

Changed 6 months ago by vadz

  • status changed from new to infoneeded_new

I don't think this 7 year old message can be relevant. And it works just fine for me under 10.5:

#include <wx/init.h>
#include <wx/math.h>

int main(int argc, char **argv)
{
    wxInitializer init;
    if ( !init.IsOk() ) {
        printf("Failed to initialize wxWidgets.\n");
        return 1;
    }

    double x;
    printf("x is %sa NaN\n", wxIsNaN(x) ? "is " : "");

    return 0;
}

Can you please check if this really fails for you under 10.6? If it doesn't, I guess you need to look at your /usr/include/math.h and check what's going on there.

Changed 6 months ago by SnowLeopard

  • status changed from infoneeded_new to new

Yes, that message is still relevant.

Add this line:

#include <wx/math.h>
#include <cmath>

and you will the error that I mention. The header cmath doesn't play nicely with isnan, and unfortunately it's pretty common to see that header used in C++ code. Perhaps using isnand instead of isnan will fix it.

Changed 6 months ago by vadz

  • priority changed from normal to low
  • status changed from new to confirmed
  • summary changed from wxIsNaN doesn't compile on Snow Leopard to wxIsNaN doesn't compile on Snow Leopard if cmath is included after wx/math.j
  • version set to 2.9.0
  • milestone deleted

Ok, I see, thanks. If you can find some way to make it work, please don't hesitate to submit a patch. In the meanwhile I'm afraid I can only recommend not include cmath or including it before wx/math.h.

Changed 6 months ago by SnowLeopard

Well, I see a fix (sort of). cmath puts isnan into the "std" namespace, that's the problem. Frankly, Windows should have this same compile error too, but I guess it's Koenig lookup is more forgiving than GCC.

Saying "#define wxIsNan(x) std::isnan(x)" fixes it, but that adds C++ features to your wx/math.h, which isn't an option. There are probably more conflicts with wx/math.h and cmath, so I guess that will just have to be a known issue. Thanks.

Changed 3 months ago by SnowLeopard

  • status changed from confirmed to closed
  • resolution set to wontfix
Note: See TracTickets for help on using tickets.