- changed status to wontfix
spurious values accessing blaze vector as a const reference
Issue #68
wontfix
Hi Klaus,
Could you please explain me why the attached test.cpp program doesn't work as expected? Is there some bug? I am using blaze 3 and g++ version 6.2.0.
Thanks, Varun
$ g++ -Wall test.cpp
$ ./a.out
_array = ( -1 -1 -1 -1 -1 )
a = ( -1 -1 -1 -1 -1 )
_array = ( -1 -1 -1 -1 -1 )
b = ( 0 -1 -1 -1 -1 )
a.out: test.cpp:42: int main(): Assertion `b[0] == -1' failed. [1] 23858 abort ./a.out
Comments (2)
-
-
reporter Sorry, I was confused by const references: http://stackoverflow.com/questions/36676419/why-do-rvalue-const-references-have-memory-address-and-size. I thought the const reference "&b" would extend the lifetime of the temporary Data Vector, but I'm wrong. Thanks for the explanation.
- Log in to comment
Hi!
Your
getData()
function returns a temporary object, which you remember via reference-to-const (line 39). However, this temporary is destroyed at the end of the statement. Accessing it later via the reference is undefined behavior (line 40 and 42). Please convince yourself about the correctness of this analysis by adding an output statement to the destructor of yourData
class.Best regards,
Klaus!