Skip to content

GCC warns "may be used uninitialized" when accessing tensor element from etl::vector #181

@FreddyGoodman

Description

@FreddyGoodman

I came across an issue when accessing individual elements of a tensor retrieved from an etl::vector:

<source>:48:20: error: '*(const double*)((char*)&p1 + offsetof(const Fastor::T_Vec2, Fastor::Tensor<double, 2>::<unnamed>))' 
may be used uninitialized [-Werror=maybe-uninitialized]

A small example which demonstrates the error can be examined in this Compiler Explorer workspace.

While moving code around, I noticed that it only ever warns about p1, never about p0 or p2. Furthermore, only when checking the destination size after assigning the elements from the vector does the warning go away. This can be tried by appropriately defining OK and NOTOK.

Since I have already found a solution but do not understand it, I would be most grateful for an explanation of the behaviour I am observing. But any other helpful tips or pointers to places where I can take this issue are great, too.

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions