c++.beta - namespace bug?
- Anton Sekeris (64/64) Feb 18 2004 Background:
Background:
The code below is a simplification of a problem I encounter. I think
it is a bug, but I cannot match it against other compilers at this
time, nor can I find a fullly relevant section in the standard.
The error occurs in a moderately large project where many levels of
includes and uses exist, and where many header files are 'header-only
libraries' like WINSTL. In my case therefore the easiest and most
acceptable workaround was 3 (see below).
The error did not occur in v838, it occurs in v839 and v840 beta.
Commandline: dmc -c test.cpp
Error:
return f(1);
^
test.cpp(48) : Error: ambiguous reference to symbol
Had: ns::f(int ,int )
and: ns::f(int ,int )
--- errorlevel 1
Workarounds:
1. Replace both 'using ns::f' instances with 'using namespace ns' and
it works.
2. Remove either of the 'using ns::f' and it works.
3. Replace 'f(1)' with 'ns::f(1)' and it works (irrespective of using
directives).
Code (also attached):
//**********************************************************************
//Block __INC1_HPP would normally be like #include "inc1.hpp"
#ifndef __INC1_HPP
#define __INC1_HPP
//Block __GENERIC_INC_HPP would normally be like #include
"generic.hpp"
#ifndef __GENERIC_INC_HPP
#define __GENERIC_INC_HPP
namespace ns
{
int f (int i, int i2 = 10)
{
return 0;
}
}
#endif //__GENERIC_INC_HPP
using ns::f;
#endif //__INC1_HPP
//Block __INC2_HPP would normally be like #include "inc2.hpp"
#ifndef __INC2_HPP
#define __INC2_HPP
//Block __GENERIC_INC_HPP would normally be like #include
"generic.hpp"
#ifndef __GENERIC_INC_HPP
#define __GENERIC_INC_HPP
namespace ns
{
int f (int i, int i = 10)
{
return 0;
}
}
#endif //__GENERIC_INC_HPP
using ns::f;
#endif //__INC2_HPP
int main ()
{
return f(1);
}
//**********************************************************************
Feb 18 2004








"Anton Sekeris" <no.spam inter.nl.net>