 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Fri Nov 03, 2006 12:51 am Post subject: A non-dependent name becomes a dependent name? |
|
|
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: () 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
|
Posted: Fri Nov 03, 2006 5:22 am Post subject: Re: A non-dependent name becomes a dependent name? |
|
|
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: () 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 |
|
 |
|
|
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
|
|