Skip to content

#116 Shallow Copy in CompressedBlockVectorWindow

Metadata

Property Value
Reported by Oliver Sander (oliver.sander@tu-dresden.de)
Reported at Mar 22, 2006 09:19
Type Bug Report
Version Git (pre2.4) [autotools]
Operating System Unspecified / All

Description

Consider the following piece of code:

BCRSMatrix<...> A,B;

[...]

for (int i=0; i<A.N(); i++) {

    BCRSMatrix<...>::row_type tmp = A[i];  //  (*)
    tmp *= 2;
    B[i] += tmp;
}

One would expect this to do only B += 2*A, but the copy constructor in line (*) does only a shallow copy. Thus, A gets screwed up in the process.

This behaviour is documented, but I think it is very counter-intuitive, and people don't usually read the documentation for copy constructors anyways. The errors it creates are very difficult to find.