Topic: Is this a bug in templates?
Author: moudgill@cs.cornell.edu ( Mayan Moudgill)
Date: Tue, 1 Dec 1992 05:09:19 GMT Raw View
The following program exhibits a *VERY* nasty bug in AT&T C++ 3.0.1
while using templates which take values (as opposed to classes) as
parameters. It is standard to use enums to define constant values
for a class, including template classes. If these enums are defined
using the value-parameter watch out! It will not always work.
See the following code.
Of course, this may not be a bug since the ARM is silent on the
subject. But by the law of least surprise....
:(
Mayan
----------------------- INCORRECT CODE ------------------------
#include <iostream.h>
template <int sz>
class Test {
enum {
Size = sz,
};
public:
inline Test()
{
cerr << "size = " << sz << " ?= " << Size << endl;
}
};
main()
{
Test<4> a4;
Test<2> a2;
}