Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > this pointer

Reply
Thread Tools

this pointer

 
 
Ian Collins
Guest
Posts: n/a
 
      01-20-2007
John Carson wrote:
>>>Jersay Ballot wrote:
>>>
>>>>template<class T>
>>>>T& getref(T&)
>>>>{
>>>> return *this;
>>>>}

>>

>
> Try calling the function and you will get an error. In a departure from the
> Standard, VC++ doesn't implement two-phase lookup for templates, so you
> often have to call functions/declare objects to get an error.
>

Isn't it the other way round? gcc performs too much checking of
templates that aren't instantiated.

--
Ian Collins.
 
Reply With Quote
 
 
 
 
John Carson
Guest
Posts: n/a
 
      01-21-2007
"Ian Collins" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)
> John Carson wrote:
>>>> Jersay Ballot wrote:
>>>>
>>>>> template<class T>
>>>>> T& getref(T&)
>>>>> {
>>>>> return *this;
>>>>> }
>>>

>>
>> Try calling the function and you will get an error. In a departure
>> from the Standard, VC++ doesn't implement two-phase lookup for
>> templates, so you often have to call functions/declare objects to
>> get an error.
>>

> Isn't it the other way round? gcc performs too much checking of
> templates that aren't instantiated.


You mean that it is gcc and VC++ that is not standard compliant? I believe
not. I'm not familiar with the details of what should be checked at each
phase, but VC++ is known to be non-compliant by design with this aspect of
the standard. Like gcc, Comeau online

http://www.comeaucomputing.com/tryitout/

refuses to compile the code.

--
John Carson


 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      01-21-2007
John Carson wrote:
> "Ian Collins" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)
>
>>John Carson wrote:
>>
>>>>
>>>Try calling the function and you will get an error. In a departure
>>>from the Standard, VC++ doesn't implement two-phase lookup for
>>>templates, so you often have to call functions/declare objects to
>>>get an error.
>>>

>>
>>Isn't it the other way round? gcc performs too much checking of
>>templates that aren't instantiated.

>
>
> You mean that it is gcc and VC++ that is not standard compliant? I believe
> not. I'm not familiar with the details of what should be checked at each
> phase, but VC++ is known to be non-compliant by design with this aspect of
> the standard. Like gcc, Comeau online
>
> http://www.comeaucomputing.com/tryitout/
>
> refuses to compile the code.
>

I can't find the relevant section in the standard (I'd forgotten how
long the template section is!), but I'm sure the compiler is only
supposed to check syntax for unused templates.

--
Ian Collins.
 
Reply With Quote
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      01-21-2007
Ian Collins wrote:

> John Carson wrote:
>> "Ian Collins" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)
>>
>>>John Carson wrote:
>>>
>>>>>
>>>>Try calling the function and you will get an error. In a departure
>>>>from the Standard, VC++ doesn't implement two-phase lookup for
>>>>templates, so you often have to call functions/declare objects to
>>>>get an error.
>>>>
>>>
>>>Isn't it the other way round? gcc performs too much checking of
>>>templates that aren't instantiated.

>>
>>
>> You mean that it is gcc and VC++ that is not standard compliant? I
>> believe not. I'm not familiar with the details of what should be checked
>> at each phase, but VC++ is known to be non-compliant by design with this
>> aspect of the standard. Like gcc, Comeau online
>>
>> http://www.comeaucomputing.com/tryitout/
>>
>> refuses to compile the code.
>>

> I can't find the relevant section in the standard (I'd forgotten how
> long the template section is!), but I'm sure the compiler is only
> supposed to check syntax for unused templates.


What do you mean by "check syntax"? Are you saying that a file containing
just

template < typename T >
struct X {
int ( int ] int int [ ) {}
};

is supposed to compile?


Best

Kai-Uwe Bux
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      01-21-2007
Kai-Uwe Bux wrote:
> Ian Collins wrote:
>>
>>I can't find the relevant section in the standard (I'd forgotten how
>>long the template section is!), but I'm sure the compiler is only
>>supposed to check syntax for unused templates.

>
>
> What do you mean by "check syntax"? Are you saying that a file containing
> just
>
> template < typename T >
> struct X {
> int ( int ] int int [ ) {}
> };
>
> is supposed to compile?
>

I'll have to search the standard again, but if X isn't instantiated, why
should it fail to compile?

--
Ian Collins.
 
Reply With Quote
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      01-21-2007
Ian Collins wrote:

> Kai-Uwe Bux wrote:
>> Ian Collins wrote:
>>>
>>>I can't find the relevant section in the standard (I'd forgotten how
>>>long the template section is!), but I'm sure the compiler is only
>>>supposed to check syntax for unused templates.

>>
>>
>> What do you mean by "check syntax"? Are you saying that a file containing
>> just
>>
>> template < typename T >
>> struct X {
>> int ( int ] int int [ ) {}
>> };
>>
>> is supposed to compile?
>>

> I'll have to search the standard again, but if X isn't instantiated, why
> should it fail to compile?


Well, what about the sequence of tokens not being a well-formed program
[1.3.14] according to the production rules in the grammar of C++? That
alone should make the compiler barff.

A more interesting question arises from the fact that the C++ in not context
free. The amount of checking for semantic constraints may actually depend
on whether a template is instantiated or not (keyword: diagnosable semantic
rules). But pure syntax check is clearly required.


Best

Kai-Uwe Bux
 
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
pointer to an array vs pointer to pointer subramanian100in@yahoo.com, India C Programming 5 09-23-2011 10:28 AM
Pointer to pointer or reference to pointer A C++ 7 07-05-2011 07:49 PM
Pointer to pointer Vs References to Pointer bansalvikrant@gmail.com C++ 4 07-02-2009 10:20 AM
passing the address of a pointer to a func that doesnt recieve a pointer-to-a-pointer jimjim C Programming 16 03-27-2006 11:03 PM
Pointer-to-pointer-to-pointer question masood.iqbal@lycos.com C Programming 10 02-04-2005 02:57 AM



Advertisments