VS 2005 died on template (part II)

A

Alex

template <class T> void S(){ T t; }
struct A{ A(){} }; // died
//struct A{ ~A(){} }; // died
//struct A{void a(){}}; // not died
void kill(){
struct B{A a;};
S<B>();
}
void bill(){
struct B{A a;};
S<B>();
}
 
J

James Kanze

template <class T> void S(){ T t; }
struct A{ A(){} }; // died
//struct A{ ~A(){} }; // died
//struct A{void a(){}}; // not died
void kill(){
struct B{A a;};
S<B>();}

void bill(){
struct B{A a;};
S<B>();

}

What does "died" mean in this case? The above code is illegal,
and shouldn't compile (regardless of which version of A you
define).
 
A

Alex

What does "died" mean in this case?  The above code is illegal,
and shouldn't compile (regardless of which version of A you
define).

"Died" means abnormal VS 2005 compiler termination.
If select the case "struct A{void a(){}};" this code compilled OK on
VS 2005.
On G++ compiler this code is really illegal.
 
J

James Kanze

"Died" means abnormal VS 2005 compiler termination.

You mean an internal compiler error? That's sort of a proof
that you've encountered a compiler but.
If select the case "struct A{void a(){}};" this code compilled OK on
VS 2005.
On G++ compiler this code is really illegal.

The code is illegal. If a compiler doesn't complain (emit a
diagnostic), it's a bug. (Assuming, of course, that you've
invoked it as a conformant compiler, with all extensions turned
off.)
 
A

Alex

You mean an internal compiler error?  That's sort of a proof
that you've encountered a compiler but.


The code is illegal.  If a compiler doesn't complain (emit a
diagnostic), it's a bug.  (Assuming, of course, that you've
invoked it as a conformant compiler, with all extensions turned
off.)

MS fixed this bug in VC++ 2008.
Compiled OK (not terminated).
I used default compiler settings.
//
James,Am I right - you consider template of local type illegal.
foo(){
typedef struct {} A;
typedef std::vector<A> LocalTypedVector; // is it illegal?
}
G++ thinks so.
 
I

Ian Collins

foo(){
typedef struct {} A;
typedef std::vector<A> LocalTypedVector; // is it illegal?
}

Yes, it is illegal, local types can not be used for template arguments.
 
R

red floyd

MS fixed this bug in VC++ 2008.
Compiled OK (not terminated).
I used default compiler settings.
//
James,Am I right - you consider template of local type illegal.
foo(){
 typedef struct {} A;
 typedef std::vector<A> LocalTypedVector; // is it illegal?}

Not only James.

Please see ISO/IEC 14882:2003 14.3.1/2:

"A local type, a type with no linkage, an unnamed type or a type
compounded from any of these types shall not be used as a
template-argument for a template type-parameter."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,147
Messages
2,570,837
Members
47,385
Latest member
Joneswilliam01

Latest Threads

Top