spurious values accessing blaze vector as a const reference

Issue #68 wontfix
varunhiremath created an issue

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)

  1. Klaus Iglberger

    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 your Data class.

    Best regards,

    Klaus!

  2. Log in to comment