boostorg / boostorg/ublas

Undefined return value on GCC/MSVC with -O2 using "auto"

Open
#84 8 comments 0 reactions 2 assignees Claimed by @amitsingh19975 View on GitHub
bug question
Dominant language
C++
Stars
122
Forks
151
PR merge metrics
No merged PRs in 30d

Description

Dear everyone,
I hope you are doing well. I stumbled across an oddity using ublas::vector which I am not able to explain. Any information as to why this happens and how it can be prevented would be very appreciated. I have reproduced the issue in Compiler-Explorer:

https://godbolt.org/z/pknvaB

Description [Boost 1.73]:
Doing simple vector arithmetic on a fixed sized vec3, I get different (wrong) results using the "auto" keyword once any optimizations (anything other than -O0) are in place on GCC and MSVC. Clang does not have this problem. I attached the code used in Compiler-Explorer to this E-Mail.

Defining BOOST_UBLAS_SIMPLE_ET_DEBUG seems to also resolve the issue?

Is this the right spot to ask this question or should I post this to the Mailing List aswell?

Best,
Faaux

```cpp
#include
#include

namespace ublas = boost::numeric::ublas;
class vec3 : public ublas::vector >
{
typedef ublas::vector > Base_vector;
public:
// Default construction
vec3 () : Base_vector(3)
{}
// Construction and assignment from a uBLAS vector expression or copy assignment
template vec3 (const ublas::vector_expression& r) : Base_vector(r)
{}
template void operator=(const ublas::vector_expression& r)
{
Base_vector::operator=(r);
}
template void operator=(const Base_vector& r)
{
Base_vector::operator=(r);
}
};

int main () {
vec3 v;
v (0) = -0.5;
v (1) = -0.5;
v (2) = -0.5;

vec3 b;
b (0) = 0.5;
b (1) = 0.5;
b (2) = 0.5;

auto impl = (b-v)*0.5;
vec3 expl = (b-v)*0.5;
std::cout << "AutoType : " << impl << std::endl; // Returns (1.4822e-323,1.4822e-323,1.4822e-323) (GCC 10.1 -O2)
std::cout << "Immediate : " << (b-v)*0.5 << std::endl; // Returns (0.5,0.5,0.5) (GCC 10.1 -O2)
std::cout << "Explicit vec3: " << expl << std::endl; // Returns (0.5,0.5,0.5) (GCC 10.1 -O2)
}

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.