using declaration

M

Marcin Kalicinski

Hi,

Should the below code compile according to C++ standard?

namespace N { struct S{ }; }
void S() { }
using N::S;

It seems that various compilers behave differently with it. I found the
example on MS newsgroup.

Best regards,
Marcin
 
S

Sharad Kala

Marcin Kalicinski said:
Hi,

Should the below code compile according to C++ standard?

namespace N { struct S{ }; }
void S() { }
using N::S;

IMO, no.
3.4.3.2/5 reads -
<quote>
During the lookup of a qualified namespace member name, if the lookup finds more
than one declaration of the member, and if one declaration introduces a class
name or enumeration name and the other declarations either introduce the same
object, the same enumerator or a set of functions, the non-type name hides the
class or enumeration name if and only if the declarations are from the same
namespace; otherwise (the declarations are from different namespaces), the
program is ill-formed
</quote>

void S() belongs to global namespace while struct S belongs to N. Hence I see
the program as illegal.

-Sharad
 
M

Marcin Kalicinski

U¿ytkownik "Sharad Kala said:
IMO, no.
3.4.3.2/5 reads -
<quote>
During the lookup of a qualified namespace member name, if the lookup finds more
than one declaration of the member, and if one declaration introduces a class
name or enumeration name and the other declarations either introduce the same
object, the same enumerator or a set of functions, the non-type name hides the
class or enumeration name if and only if the declarations are from the same
namespace; otherwise (the declarations are from different namespaces), the
program is ill-formed
</quote>

Right, but standard says 'during lookup'. If S is never used, the lookup is
not performed (am I right?).

Best regards,
Marcin
 
J

JKop

Marcin Kalicinski posted:
Right, but standard says 'during lookup'. If S is never used, the
lookup is not performed (am I right?).

Best regards,
Marcin

DEBATE DEBATE DEBATE


-JKop
 
S

Sharad Kala

Marcin Kalicinski said:
U¿ytkownik "Sharad Kala" <[email protected]> napisa³ w
wiadomo¶ci
[snip]
Right, but standard says 'during lookup'. If S is never used, the lookup is
not performed (am I right?).

Well Comeau online thinks the code is fine while VC++ 7.1 and g++ 3.3.1 don't
think so.
The example in the standard indeed refers to a case where the name is used in
the program. So if S is used in the program then it's not legal, not sure if
it's not used.

-Sharad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,460
Latest member
eibafima

Latest Threads

Top