Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from

Conversation

tanmoy87544
Copy link
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
Contributor

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

@tanmoy87544
Copy link
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
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.

None yet

2 participants