I found that this odd case of some code (below) does not compile in Visual Studio 2008 and produces "error C2872:" Ambiguity ": ambiguous character" on line 12.
Removing use namespace RequiredNamespacein the last line fixes the error, but I expect that putting using namespaceat the end of the file should not have any effect. It also relies on AnotherFunctionas a template function, so I expect the compiler to generate template functions in the wrong area or not reset the list of namespaces that will be used before.
The same code compiles under GCC.
Both compilers seem to generate code for TemplatedFunctionafter determining using namespace Namespace, at least as far as I can tell, by inputting errors and looking at how they are output.
namespace Ambiguity
{
class cSomeClass
{
};
template<class T>
void TemplatedFunction(T a)
{
Ambiguity::cSomeClass();
}
}
namespace RequiredNamespace
{
class Ambiguity
{
};
}
int main()
{
Ambiguity::TemplatedFunction(4);
}
using namespace RequiredNamespace;
Obviously, this is a manufactured example, but the original is extracted from the real case when it using namespaceis in an automatically generated file created by third-party code.
Is this a bug in the compiler?
source
share