public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/48891] New: std functions conflicts with C functions when building with c++0x support.
@ 2011-05-05 21:50 alexis.menard at openbossa dot org
  2011-05-05 21:44 ` [Bug libstdc++/48891] " alexis.menard at openbossa dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: alexis.menard at openbossa dot org @ 2011-05-05 21:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48891

           Summary: std functions conflicts with C functions when building
                    with c++0x support.
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: alexis.menard@openbossa.org


Created attachment 24193
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24193
Small test case.

Hello,

I'm not sure it's a real bug (though that example builds fine with gcc 4.5.0)
but at least perhaps I'll get help.

Consider :

#include <stdlib.h>
#include <cmath>
#include <stdio.h>

using namespace std;

int main(int argc, char** argv)
{
    double number = 0;
    if (isnan(number))
    {
        printf("Nan\n");
    }
    return 0;
}

and build it with : g++ main.cpp -std=c++0x -std=gnu++0x -o test

It fails to compile : 

main.cpp: In function ‘int main(int, char**)’:
main.cpp:10:21: error: call of overloaded ‘isnan(double&)’ is ambiguous
main.cpp:10:21: note: candidates are:
/usr/include/bits/mathcalls.h:235:1: note: int isnan(double)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/cmath:558:3:
note: bool std::isnan(long double)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/cmath:554:3:
note: bool std::isnan(double)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/cmath:550:3:
note: bool std::isnan(float)

If I deactivate the c++0x support it works.

The real issue is that the c++0x standard removes the prohibition on C++
headers declaring C names in the global namespace. The problem here is that
math.h is included therefore the declarations are in the global namespace.

I'm not really sure how the compiler can solve that but this new "feature" of
c++0x seems to be very annoying. I could solve it by not using namespace std
but let say the project is huge, it will requires lot of modifications.

Basically any time you use using namespace std, you may have conflicts with the
underlaying C libraries, it's even more annoying with your own namespace
because your functions can conflict with all the stuff in the global namespace
put by C libraries and it's very common in a cpp file to use "using namespace
foo;"

Any suggestions on how I could "workaround" that?


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-04-09 14:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-05 21:50 [Bug libstdc++/48891] New: std functions conflicts with C functions when building with c++0x support alexis.menard at openbossa dot org
2011-05-05 21:44 ` [Bug libstdc++/48891] " alexis.menard at openbossa dot org
2011-05-05 22:08 ` [Bug libstdc++/48891] std functions conflicts with C functions when building with c++0x support (and using namespace std) redi at gcc dot gnu.org
2011-05-05 22:22 ` alexis.menard at openbossa dot org
2011-05-05 22:47 ` paolo.carlini at oracle dot com
2011-05-05 23:16 ` paolo.carlini at oracle dot com
2012-04-29 13:17 ` marc.glisse at normalesup dot org
2015-04-09 14:35 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).