Bug 48406 - <algorithm> #undefs isfinite() from math.h in C++0x mode
Summary: <algorithm> #undefs isfinite() from math.h in C++0x mode
Status: RESOLVED DUPLICATE of bug 14608
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-02 01:12 UTC by Jeffrey Yasskin
Modified: 2011-04-02 10:46 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeffrey Yasskin 2011-04-02 01:12:45 UTC
$ cat test.cc
#include <math.h>
#include <algorithm>

bool foo(double d) {
  return isfinite(d);
}
$ ~/opensource/gcc/git/install/bin/g++ -c test.cc 
$ ~/opensource/gcc/git/install/bin/g++ -c test.cc -std=gnu++0x
test.cc: In function ‘bool foo(double)’:
test.cc:5:20: error: ‘isfinite’ was not declared in this scope
test.cc:5:20: note: suggested alternative:
.../include/c++/4.7.0/cmath:528:21: note:   ‘std::isfinite’
$

This is a regression since gcc-4.4:

$ g++-4.4 -c test.cc -std=gnu++0x
$ 

It happens because <stl_algo.h> includes <random> in C++0x mode only, and <random> includes <cmath>, which #undefs all the C99 math functions that <math.h> defined, without 'using' the std functions back into the global namespace.

As far as I can tell, [depr.c.headers] says that <math.h> puts the <cmath> names into the global namespace, and it doesn't allow a later include of <cmath> to take them back out. [depr.c.headers] also allows <cmath> to unconditionally put its declarations and definitions into the global namespace, which is what I'd propose as a fix.
Comment 1 Jeffrey Yasskin 2011-04-02 05:52:12 UTC
FWIW, the path from algorithm->cmath appears to have been introduced in gcc-4.5.
Comment 2 Paolo Carlini 2011-04-02 10:46:32 UTC
.

*** This bug has been marked as a duplicate of bug 14608 ***