jstm88
jstm88

Reputation: 3355

LLVM Compiler 2.0: Warning with "using namespace std;"

In Xcode using LLVM 2.0, when I put the line using namespace std; in my C++ code, I get this warning:

Semantic Issue
Using directive refers to implicitly-defined namespace 'std'

Is there a way to fix this? Why is it giving that warning?

Upvotes: 21

Views: 30579

Answers (4)

balagurubaran
balagurubaran

Reputation: 79

i solved this problem like this

#include <iostream>

using namespace std;
/// This function is used to ensure that a floating point number is
/// not a NaN or infinity.
inline bool b2IsValid(float32 x)
{
    if (x != x)
    {
        // NaN.
        return false;
    }
    float32 infinity = std::numeric_limits <float32>::infinity();
    return -infinity < x && x < infinity;
    return true;

}

Upvotes: 7

GC Saab
GC Saab

Reputation: 91

I see that this question is pretty old, but for anyone checking this out in the future, I wanted to add this link from the LLVM documentation as a supplement to the discussion and for poeple looking for more info:

LLVM Coding Standards: Do Not use using namespace std;

I believe that the title is pretty indicative of why I've shared it to help with this question.

In LLVM, we prefer to explicitly prefix all identifiers from the standard namespace with an “std::” prefix, rather than rely on “using namespace std;”.

In header files, adding a 'using namespace XXX' directive pollutes the namespace of any source file that #includes the header. This is clearly a bad thing.

Edit: So instead if using 'using std namespace;' explicitly type std:: for every case where you with to use the standard library. It avoids conflicts with source file namespaces. This is what the quote above from the article advises.

Upvotes: -1

jtony
jtony

Reputation: 101

Moving the using namespace std to after the #include can eliminate this warning.

Upvotes: 9

Motti
Motti

Reputation: 114795

Have you included any standard header files? Otherwise the compiler doesn't know about namespace std.

Please post more code to clarify.

Upvotes: 30

Related Questions