C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

A non-dependent name becomes a dependent name?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Fri Nov 03, 2006 12:51 am    Post subject: A non-dependent name becomes a dependent name? Reply with quote



template<typename T>
struct B
{
//void f();
};

template<typename T>
struct D:B<T>
{
using B<T>::f;
D()
{
f();
}
};

int main()
{}

According to the standard, f() in D:Very Happy() is clearly a non-dependent
name, therefore looked up and bound at the time it's used.
But, since "using B<T>::f" introduced a name f into D, the name look up
will find it, thus bind the f() call to B<T>::f which is clearly a
dependent name.
Does this make f() a dependent name again? Or it's just a case where a
non-dependent name bounded to a dependent name?


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Alberto Ganesh Barbati
Guest





PostPosted: Fri Nov 03, 2006 5:22 am    Post subject: Re: A non-dependent name becomes a dependent name? Reply with quote



pongba (AT) gmail (DOT) com ha scritto:
Quote:
template<typename T
struct B
{
//void f();
};

template<typename T
struct D:B<T
{
using B<T>::f;
D()
{
f();
}
};

int main()
{}

According to the standard, f() in D:Very Happy() is clearly a non-dependent
name, therefore looked up and bound at the time it's used.
But, since "using B<T>::f" introduced a name f into D, the name look up
will find it, thus bind the f() call to B<T>::f which is clearly a
dependent name.
Does this make f() a dependent name again? Or it's just a case where a
non-dependent name bounded to a dependent name?


§14.6.2/1 couldn't be clearer:

---
[...] In an expression of the form:

postfix-expression ( expression-list_opt )

where the postfix-expression is an identifier, the identifier denotes a
dependent name if and only if any of the expressions in the
expression-list is a type-dependent expression (14.6.2.2). [...]
---

As there's no expression-list in your case, f is never dependent. The
presence of the using declaration is irrelevant. Whether this is good or
bad, I can't tell. Certainly it's not the first not-so-intuitive name
lookup rule in the realm of templates. Fortunately, there's always the
"this->f()" notation if you want to be sure the name is dependent.

HTH,

Ganesh

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.