info-sather
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sather: templates necessary?


From: Eray Ozkural
Subject: Re: Sather: templates necessary?
Date: Tue, 17 Oct 2000 00:13:44 +0300

Norbert Nemec wrote:
> 
> On Sun, Oct 15, 2000 at 06:51:37PM +0300, Eray Ozkural wrote:
> > FYI, g++ can detect semantic errors in template implementations
> > before instantiation. So can many other c++ compilers.
> 
> What does it check against? It has no information about the semantics
> of the parameter type. Of course, there is some semantic stuff that can
> be checked, but the crucial part of C++ semantic checking is the
> typechecking. There is no type-info about the parameters.

Sure it can't typecheck the compatibility of template parameters
before instantiation. Almost everything else seems to get checked though.
Also, it knows something about it. For instance, in

template <class T>
void ... {

}

  It knows that T is a class; therefore there may be instances of
T, but the following code would be wrong:

template <class T>
void f(const T & a) {

  a = 3;

}

because a is a constant reference.

This would also be wrong:

template <class T>
void f(const T & a) {

  T.x = 3;

}

:)

Anyway, these weren't very good examples perhaps :)

In practice, that's very important because in the old days it would
be almost impossible to track down errors that occured at the point of
instantiation. Now, the template implementation is treated like
ordinary code, and if there are errors the compiler tells them in the
template code and you have a chance to fix them.

I'm not sure how far g++ goes BTW. IIRC, it doesn't catch
every detectable error.

-- 
Eray (exa) Ozkural
Comp. Sci. Dept., Bilkent University, Ankara
e-mail: address@hidden
www: http://www.cs.bilkent.edu.tr/~erayo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]