libantioch / antioch

C++ Chemical Kinetics, Thermodynaimics, and Transport Library
https://libantioch.github.io/
Other
22 stars 17 forks source link

Check for "Scalar foo = bar;" initializations #237

Closed roystgnr closed 7 years ago

roystgnr commented 7 years ago

You'd think that means to construct using Scalar(bar), but the compiler is legally allowed to do Scalar() followed by Scalar::operator=(bar), and Intel 17 seems to prefer the latter with '-O0' at least. This is a problem when Scalar is valarray, the empty constructor creates an empty array, and the assignment operator is then a buffer overflow.

pbauman commented 7 years ago

God dammit C++. Somewhere @knepley is laughing at us. (I was just telling him about Antioch the other day.)

roystgnr commented 7 years ago

No, wait. C++ doesn't allow that; = initializations allow for "construct temporary then copy construct from it" pessimization but not for "construct default then assign to it" pessimization. I'm actually not sure what's going on now. All I know is that I'm seeing a buffer overflow with lines like const StateType as = a[s]; and changing to const StateType as(a[s]); somehow fixes it.

roystgnr commented 7 years ago

This is baffling. I just undid my changes to experiment further, and the test still doesn't fail. "not sure what's going on now" doesnt' begin to describe my confusion.