Indeed, Loaden's sample code works perfectly. That's the syntax I used in older files, but I've dropped it for the single line "using namespace".
I don't know how the CC parser works, but can't you do like a C++ compiler does ? When you read a "using namespace XX" directive, you temporarily bring to the current scope all the content of what has been previously parsed in this namespace/class.
Alternatively, you could check for each symbol found after a "using namespace XX" if is has any match both in the global scope and in namespace XX.
Depending on the size of the namespace and the file to parse, one or the other solution is better, but I guess the latter one would be the most efficient ("using namespace std", which is probably the most used one, sure contains a LOT of symbols...).
CC's parser do much less job than a compiler.
you temporarily bring to the current scope all the content of what has been previously parsed in this namespace/class.
This sounds reasonable, but if the using directive is in a header file, also the header file was included in many cpp files, how can we deal with this? Currently, we just parse every file once, which means a header file will only be parsed once. This is much different with a C++ compiler. The compiler will do much dirty job, like preprocessing, which means a header file will be parsered several times in different translation unit. CC avoid doing that things to save time.
Alternatively, you could check for each symbol found after a "using namespace XX" if is has any match both in the global scope and in namespace XX.
This is the same thing as before, which means we should do at least "semantic checking". which means we should maintain an "Exposed namespace set" dynamically. see the code below:
#include "SomeHeader.h"
using namespace A;
void f()
{
using namespace B;
XXX;
{
using namespace C;
YYY;
}
}
ZZZ;
When parsing the statement "YYY", we should the current exposed namespace set is
{A,B,C, namespace exposed in the "SomeHeader.h"}.
When parsing the statement "ZZZ", we only check the namespace
{A, namespace exposed in the "SomeHeader.h"}.
That's too complex for CC to remember all the exposed namespace scopes.
BTW: there are some code like:
using B::b;
using A::a;
....
a;
b;
which only introduce some variables or types of a namespace, which will make the semantic check more harder.
Finally, I think that's to complex for use.... C++'s grammar is toooo complex to write a simple parser.

This is why I some days ago suggest using some compiler directly, such as GCCsense or Clang.
search our forum for more details.
