c++.beta - namespace bug?
- "Anton Sekeris" <no.spam inter.nl.net> Feb 18 2004
This is a multipart message in MIME format
--Xananews.1.2.3
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);
}
//**********************************************************************
--Xananews.1.2.3
Content-Type: Application/Octet-Stream; name=test.cpp
Content-Transfer-Encoding: base64
Ly8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq
KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq
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0KDQojZW5kaWYgLy9fX0lOQzJfSFBQDQoNCmludCBtYWluICgpDQp7DQogIHJldHVy
biBmKDEpOw0KfQ0KLy8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq
KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq
KioqKioqKioqKioqKioqKioNCg==
--Xananews.1.2.3--
Feb 18 2004








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