Expression and Meta Templates Problem using C++

Olaf Petzold opetzold@wit.regiocom.net
Wed Sep 10 12:04:00 GMT 2003


Hello,

I'm using the gcc suite:

Reading specs from
/usr//bin/../lib/gcc-lib/i586-mandrake-linux-gnu/3.2/specs
Configured with:
../configure --prefix=/usr --libdir=/usr/lib --with-slibdir=/lib --mandir=/u
sr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posi
x --disable-checking --enable-long-long --enable-__cxa_atexit --enable-langu
ages=c,c++,ada,f77,objc,java --host=i586-mandrake-linux-gnu --with-system-zl
ib
Thread model: posix
gcc version 3.2 (Mandrake Linux 9.0 3.2-1mdk)

But, the problem is related to other/newer/older versions too. The compiler
flags were

g++ -O2 gcc.cc -o gcc && ./gcc

as well as higher optimizations

-O2 -W -Wall -Winline -finline-limit=5000 -ftemplate-depth-200 -fstrict-alia
sing -malign-double

I've got no error or warnings compiling the attached file. The program's
output is:

B = Matrix<d, 3, 2> = [
  [-0.05, 0],
  [0, 0.05],
  [0.05, -0.05]
]
D = Matrix<d, 3, 3> = [
  [2000, 1000, 0],
  [1000, 2000, 0],
  [0, 0, 500]
]
K = Matrix<d, 2, 2> = [
  [6.25, -5001.25],
  [-3.75, 2506.25]
]

Where K has the wrong result. It should be:

K = Matrix<d, 2, 2> = [
  [6.25, -3.75],
  [-3.75, 6.25]
]

Well, I'm the owner of the tvmet project at http://tvmet.sourceforge.net/.
The libary is using expression and meta templates e.g. for unlooping the
matrix-matrix product. The problem is related to the temporary temp_lhs used
by the prod function. If I make the temp static I've got right results but,
other/further matrix multiplications calculate wrong results (same
dimensions with other values using the same static temp). As used here in
the example using RVO results in wrong results. Parts of the result are
correct, other not. The algorithm/code used is correct (checked with a lot
of regression tests). A simple product of matrizes (using prod(const
Matrix<>&, const Matrix<>&) not shown here) got the expected result. What is
going on here?

Thanks
Olaf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tvmet.cc
Type: application/octet-stream
Size: 12371 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20030910/f61c4386/attachment.obj>


More information about the Gcc-bugs mailing list