By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,588 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

using declaration

P: n/a
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

Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Marcin Kalicinski" <ka****@poczta.onet.pl> wrote in message
news:c8**********@korweta.task.gda.pl...
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


Jul 22 '05 #2

P: n/a
Użytkownik "Sharad Kala" <no*****************@yahoo.com> napisał w
wiadomości news:2h************@uni-berlin.de...

"Marcin Kalicinski" <ka****@poczta.onet.pl> wrote in message
news:c8**********@korweta.task.gda.pl...
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>


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

Best regards,
Marcin
Jul 22 '05 #3

P: n/a
Marcin Kalicinski posted:
Użytkownik "Sharad Kala" <no*****************@yahoo.com> napisał w
wiadomości news:2h************@uni-berlin.de...

"Marcin Kalicinski" <ka****@poczta.onet.pl> wrote in message
news:c8**********@korweta.task.gda.pl...
> 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>


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
Jul 22 '05 #4

P: n/a

"Marcin Kalicinski" <ka****@poczta.onet.pl> wrote in message
news:c8**********@korweta.task.gda.pl...
Użytkownik "Sharad Kala" <no*****************@yahoo.com> napisał w
wiadomości news:2h************@uni-berlin.de...
[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
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.