Skip to content

Use aggregate initialization instead of default initialization that l…#389

Open
tanmoy87544 wants to merge 1 commit intoITensor:v3from
tanmoy87544:AggregateInit
Open

Use aggregate initialization instead of default initialization that l…#389
tanmoy87544 wants to merge 1 commit intoITensor:v3from
tanmoy87544:AggregateInit

Conversation

@tanmoy87544
Copy link
Copy Markdown
Contributor

…eaves simple types undefined. The problem with the default initialization is it calls value initialization, which leaves simple types undefined. This gives a compilation error when Block(0) is being moved. Changing it to aggregate initialization forces elements to be zero initialized. The time penalty of constructing the arr_ array should be minimal.

@emstoudenmire
Copy link
Copy Markdown
Contributor

Hi, so for this one, is the issue that it could give a compilation error in the future?

@tanmoy87544
Copy link
Copy Markdown
Contributor Author

Hi, so for this one, is the issue that it could give a compilation error in the future?

Definitely with C++20, which is my default. But, the same standards violation (moving undefined parts of a struct) is true for C++17, I can check whether the compiler complains in C++17 mode or not.

@tanmoy87544
Copy link
Copy Markdown
Contributor Author

Hi, so for this one, is the issue that it could give a compilation error in the future?

OK, checked. It complains when building v3 with g++ (MacPorts gcc10 10.2.0_5) 10.2.0

Compiling itensor/itdata/qdense.cc with optimizations
In file included from /Users/tanmoy/iTensor/ITensor/itensor/tensor/types.h:21,
from /Users/tanmoy/iTensor/ITensor/itensor/tensor/rangeiter.h:20,
from /Users/tanmoy/iTensor/ITensor/itensor/tensor/teniter.h:19,
from /Users/tanmoy/iTensor/ITensor/itensor/tensor/ten.h:20,
from /Users/tanmoy/iTensor/ITensor/itensor/tensor/sliceten.h:20,
from itdata/qdense.cc:20:
/Users/tanmoy/iTensor/ITensor/itensor/util/infarray.h: In member function 'std::tuple<const T*, itensor::InfArray<long int, 11>, long int> itensor::QDense::getEltBlockOffset(const itensor::IndexSet&, const Indexable&) const [with Indexable = itensor::InfArray<long int, 11>; T = double]':
/Users/tanmoy/iTensor/ITensor/itensor/util/infarray.h:131:31: warning: '((void)& +16)' may be used uninitialized in this function [-Wmaybe-uninitialized]
131 | vec_(std::move(o.vec_))
| ^
/Users/tanmoy/iTensor/ITensor/itensor/util/infarray.h: In member function 'std::tuple<const T*, itensor::InfArray<long int, 11>, long int> itensor::QDense::getEltBlockOffset(const itensor::IndexSet&, const Indexable&) const [with Indexable = itensor::InfArray<long int, 11>; T = std::complex]':
/Users/tanmoy/iTensor/ITensor/itensor/util/infarray.h:131:31: warning: '((void)& +16)' may be used uninitialized in this function [-Wmaybe-uninitialized]
131 | vec_(std::move(o.vec_))
| ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants