Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Proposal: Allow using injected class name when template name is in scope

Reply
Thread Tools

Proposal: Allow using injected class name when template name is in scope

 
 
Johannes Schaub (litb)
Guest
Posts: n/a
 
      09-10-2010
The following is not currently well-formed:

template<typename>
struct base { void f() { } };

struct A : base<int> {
void f(int) { }
};

int main() {
A a;
a.base::f();
}

It would seem to be beneficial to make this work by finding the inherited
injected class name of base<int> in A. But currently it is ill-formed
because that name does not denote the same entity as the name found in the
context of the entire postfix-expression, which refers to the base template.

To make this work, could one not get rid of the part of 3.4.3/1 that says
"... and templates whose specializations are types."? When is a class-
template name or a template alias name ever going to be valid before a "::"?
So if this part would be removed, the global base template would be ignored,
and only the injected class name in A would be found and the program would
be valid.
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      09-10-2010
On 9/10/2010 1:15 PM, Johannes Schaub (litb) wrote:
> The following is not currently well-formed:
>
> template<typename>
> struct base { void f() { } };
>
> struct A : base<int> {
> void f(int) { }
> };
>
> int main() {
> A a;
> a.base::f();
> }
>
> It would seem to be beneficial to make this work by finding the inherited
> injected class name of base<int> in A. But currently it is ill-formed
> because that name does not denote the same entity as the name found in the
> context of the entire postfix-expression, which refers to the base template.
>
> To make this work, could one not get rid of the part of 3.4.3/1 that says
> "... and templates whose specializations are types."? When is a class-
> template name or a template alias name ever going to be valid before a "::"?
> So if this part would be removed, the global base template would be ignored,
> and only the injected class name in A would be found and the program would
> be valid.


What problem does it solve that cannot be solved using some other ways?

In your case, try adding a 'using' declaration in 'A':

struct A : base<int> {
void f(int) {}
using base<int>::f;
};

and then omit 'base::' in the call...

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
 
 
 
Johannes Schaub (litb)
Guest
Posts: n/a
 
      09-10-2010
Victor Bazarov wrote:

> On 9/10/2010 1:15 PM, Johannes Schaub (litb) wrote:
>> The following is not currently well-formed:
>>
>> template<typename>
>> struct base { void f() { } };
>>
>> struct A : base<int> {
>> void f(int) { }
>> };
>>
>> int main() {
>> A a;
>> a.base::f();
>> }
>>
>> It would seem to be beneficial to make this work by finding the inherited
>> injected class name of base<int> in A. But currently it is ill-formed
>> because that name does not denote the same entity as the name found in
>> the context of the entire postfix-expression, which refers to the base
>> template.
>>
>> To make this work, could one not get rid of the part of 3.4.3/1 that says
>> "... and templates whose specializations are types."? When is a class-
>> template name or a template alias name ever going to be valid before a
>> "::"? So if this part would be removed, the global base template would be
>> ignored, and only the injected class name in A would be found and the
>> program would be valid.

>
> What problem does it solve that cannot be solved using some other ways?
>
> In your case, try adding a 'using' declaration in 'A':
>
> struct A : base<int> {
> void f(int) {}
> using base<int>::f;
> };
>
> and then omit 'base::' in the call...
>


It just seems intuitive to me if it worked. Because if you place the "base"
template in a non-global namespace, it suddenly works because "base" is then
not found by unqualified lookup anymore. Such a difference causes confusion
I think.

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      09-10-2010
On 9/10/2010 1:24 PM, Johannes Schaub (litb) wrote:
> Victor Bazarov wrote:
>
>> On 9/10/2010 1:15 PM, Johannes Schaub (litb) wrote:
>>> The following is not currently well-formed:
>>>
>>> template<typename>
>>> struct base { void f() { } };
>>>
>>> struct A : base<int> {
>>> void f(int) { }
>>> };
>>>
>>> int main() {
>>> A a;
>>> a.base::f();
>>> }
>>>
>>> It would seem to be beneficial to make this work by finding the inherited
>>> injected class name of base<int> in A. But currently it is ill-formed
>>> because that name does not denote the same entity as the name found in
>>> the context of the entire postfix-expression, which refers to the base
>>> template.
>>>
>>> To make this work, could one not get rid of the part of 3.4.3/1 that says
>>> "... and templates whose specializations are types."? When is a class-
>>> template name or a template alias name ever going to be valid before a
>>> "::"? So if this part would be removed, the global base template would be
>>> ignored, and only the injected class name in A would be found and the
>>> program would be valid.

>>
>> What problem does it solve that cannot be solved using some other ways?
>>
>> In your case, try adding a 'using' declaration in 'A':
>>
>> struct A : base<int> {
>> void f(int) {}
>> using base<int>::f;
>> };
>>
>> and then omit 'base::' in the call...
>>

>
> It just seems intuitive to me if it worked. Because if you place the "base"
> template in a non-global namespace, it suddenly works because "base" is then
> not found by unqualified lookup anymore. Such a difference causes confusion
> I think.


After I posted my reply I thought a bit, and this occurred to me: 'base'
is not a member/base name, is it? 'base<int>' would be, no? I can't
claim full understanding of the lookup rules in the current Standard,
and even less in the upcoming one...

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring a template class with two template params a friend in anon-template class A L C++ 1 08-25-2010 07:25 AM
Unwanted data injected into datagrid textbox kingflux ASP .Net 3 12-21-2006 05:06 PM
Hidden spam links injected into web pages Terry_P Computer Security 3 12-03-2006 12:18 AM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
Root Relative Path Injected as String Variable Jordan Richard ASP .Net 2 05-02-2005 05:40 PM



Advertisments