Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > New template rules is bad

Reply
Thread Tools

New template rules is bad

 
 
Grizlyk
Guest
Posts: n/a
 
      01-30-2007

New C++ rules are always trying to do "fast" compilation - to compile code,
which must be compiled at point of instance only (not during declaration
stage). The behaviour is intoducing many wrong limitations.

Look at this strange limitation:

1. Can not declare templated friend

template< class T>
class X
{
friend class T;
//error: using template type parameter 'T' after 'class'
//error: friend declaration does not name a class or function
};

--
Maksim A Polyanin


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-30-2007
Grizlyk wrote:
> New C++ rules are always trying to do "fast" compilation - to compile
> code, which must be compiled at point of instance only (not during
> declaration stage). The behaviour is intoducing many wrong
> limitations.
> Look at this strange limitation:
>
> 1. Can not declare templated friend
>
> template< class T>
> class X
> {
> friend class T;
> //error: using template type parameter 'T' after 'class'
> //error: friend declaration does not name a class or function
> };


Friendship is overrated.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
Thomas Tutone
Guest
Posts: n/a
 
      01-30-2007
On Jan 30, 5:53 pm, "Grizlyk" <(E-Mail Removed)> wrote:

> New C++ rules are always trying to do "fast" compilation - to compile code,
> which must be compiled at point of instance only (not during declaration
> stage). The behaviour is intoducing many wrong limitations.
>
> Look at this strange limitation:
>
> 1. Can not declare templated friend
>
> template< class T>
> class X
> {
> friend class T;
> //error: using template type parameter 'T' after 'class'
> //error: friend declaration does not name a class or function
>
> };


Why do you call these "new" template rules? As far as I know, this
has been the standard behavior since the standard was adopted almost
ten years ago.

Best regards,

Tom


 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      01-30-2007
Victor Bazarov wrote:

> Friendship is overrated.


Oh yeah? Try bumming a beer from your enemies!


 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      01-30-2007
Grizlyk wrote:
> New C++ rules are always trying to do "fast" compilation - to compile code,
> which must be compiled at point of instance only (not during declaration
> stage). The behaviour is intoducing many wrong limitations.
>
> Look at this strange limitation:
>
> 1. Can not declare templated friend
>
> template< class T>
> class X
> {
> friend class T;
> //error: using template type parameter 'T' after 'class'
> //error: friend declaration does not name a class or function
> };
>

I'd always put this down to gcc compiling a template when it shouldn't.
But I can't find the relevant section of the standard that says how a
compiler should treat an uninstantiated template.

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

>
> New C++ rules are always trying to do "fast" compilation - to compile
> code, which must be compiled at point of instance only (not during
> declaration stage). The behaviour is intoducing many wrong limitations.
>
> Look at this strange limitation:
>
> 1. Can not declare templated friend
>
> template< class T>
> class X
> {
> friend class T;
> //error: using template type parameter 'T' after 'class'
> //error: friend declaration does not name a class or function
> };


What you encounter here is not some general rule about template
instantiation. It is in fact a consequence of [7.1.5.3/2] and the syntax
specification that a friend declaration needs an elaborate-type-specifier.
In my opinion, these rules could be relaxed without negatively affecting
the complexity of compilation. In fact, due to a bug, g++ accepts the
following invalid code, which circumvents the provision:


template < typename T >
class identity {
public:

typedef T me;

};

template < typename T >
class my_friend {
private:

friend class identity< T >::me;

char x;

};

class The_T {
public:

static
char & peek_friend ( my_friend< The_T > & f ) {
return( f.x );
}

};

int main (void) {
my_friend< The_T > x;
The_T:eek_friend( x );
}

(See also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21498)


Best

Kai-Uwe Bux


 
Reply With Quote
 
Grizlyk
Guest
Posts: n/a
 
      01-31-2007
Thomas Tutone wrote:
>
> Why do you call these "new" template rules? As far as I know, this
> has been the standard behavior since the standard was adopted almost
> ten years ago.


Because it can be easy compiled by bcc32 (version 5.5.1)
and probably by g++ (version 2.95).

--
Maksim A Polyanin


 
Reply With Quote
 
Grizlyk
Guest
Posts: n/a
 
      01-31-2007
Victor Bazarov wrote:
>
> Friendship is overrated.
>



What does it mean?

--
Maksim A Polyanin


 
Reply With Quote
 
Grizlyk
Guest
Posts: n/a
 
      01-31-2007
Kai-Uwe Bux wrote:
>
> What you encounter here is not some general rule about template
> instantiation. It is in fact a consequence of [7.1.5.3/2] and the syntax
> specification that a friend declaration needs an elaborate-type-specifier.
> In my opinion, these rules could be relaxed without negatively affecting
> the complexity of compilation. In fact, due to a bug, g++ accepts the
> following invalid code, which circumvents the provision:


As i can understand, it is even not extention, just error, so can not be
used.

I think, I will make dummy classes

template<class T>class dummy;

template<class T>
class X
{
friend class dummy<T>;
};

template<class T>
class dummy
{
//pass all X:rivate into dummy:ublic
};

--
Maksim A Polyanin


 
Reply With Quote
 
Greg Herlihy
Guest
Posts: n/a
 
      01-31-2007



On 1/30/07 2:53 PM, in article epoi7n$gt8$(E-Mail Removed), "Grizlyk"
<(E-Mail Removed)> wrote:

>
> New C++ rules are always trying to do "fast" compilation - to compile code,
> which must be compiled at point of instance only (not during declaration
> stage). The behaviour is intoducing many wrong limitations.
>
> Look at this strange limitation:
>
> 1. Can not declare templated friend
>
> template< class T>
> class X
> {
> friend class T;
> //error: using template type parameter 'T' after 'class'
> //error: friend declaration does not name a class or function
> }


You have it backwards. The new rules for friend declarations (specifically,
"extended friend declarations") make the friend T declaration above legal in
the next C++ Standard.

Most C++ compilers have not yet been updated to recognize this kind of
friend declaration (though I believe VC++ 2005 is an exception). So until
your C++ compiler adds support for extended friend declarations, your C++
program will be governed by the "old rules", and not by the new ones.

Greg

 
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
integer >= 1 == True and integer.0 == False is bad, bad, bad!!! rantingrick Python 44 07-13-2010 06:33 PM
Bad media, bad files or bad Nero? John Computer Information 23 01-08-2008 09:17 PM
ActiveX apologetic Larry Seltzer... "Sun paid for malicious ActiveX code, and Firefox is bad, bad bad baad. please use ActiveX, it's secure and nice!" (ok, the last part is irony on my part) fernando.cassia@gmail.com Java 0 04-16-2005 10:05 PM
24 Season 3 Bad Bad Bad (Spoiler) nospam@nospam.com DVD Video 12 02-23-2005 03:28 AM
24 Season 3 Bad Bad Bad (Spoiler) nospam@nospam.com DVD Video 0 02-19-2005 01:10 AM



Advertisments