Page 1 of 1

Can't figure out: binding dereferenced null pointer to reference has undefined behavior

Posted: Wed May 31, 2017 3:01 pm
by sam
Guys,

I am getting a puzzling warning when building the latest release of simbody. Actually it only occurs when building examples, but since I am having problems downstream I think this needs to be addressed. The warning is below. Any advice?

Thanks

Sam


In file included from /Users/Sam/github/simbody/SimTKcommon/src/PrivateInstantiations.cpp:28:
In file included from /Users/Sam/github/simbody/SimTKcommon/src/../Geometry/src/PolygonalMeshImpl.h:27:
In file included from /Users/Sam/github/simbody/SimTKcommon/Geometry/include/SimTKcommon/internal/PolygonalMesh.h:27:
In file included from /Users/Sam/github/simbody/SimTKcommon/./include/SimTKcommon/Simmatrix.h:36:
In file included from /Users/Sam/github/simbody/SimTKcommon/Scalar/include/SimTKcommon/Scalar.h:42:
/Users/Sam/github/simbody/SimTKcommon/Scalar/include/SimTKcommon/internal/NTraits.h:1076:1: warning: binding dereferenced null pointer to reference has undefined behavior
[-Wnull-dereference]
SimTK_DEFINE_REAL_NTRAITS(float);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/Sam/github/simbody/SimTKcommon/Scalar/include/SimTKcommon/internal/NTraits.h:982:62: note: expanded from macro 'SimTK_DEFINE_REAL_NTRAITS'
static T& imag(T&) { assert(false); return *reinterpret_cast<T*>(0); } \
^~~~~~~~~~~~~~~~~~~~~~~~

Re: Can't figure out: binding dereferenced null pointer to reference has undefined behavior

Posted: Wed May 31, 2017 3:02 pm
by sam
I am building on OS 10.12 Sierra.

thanks

sam

Re: Can't figure out: binding dereferenced null pointer to reference has undefined behavior

Posted: Wed May 31, 2017 3:24 pm
by sherm
Hi, Sam. I think that just reflects a smarter compiler that noticed some tricky code that has always been there and is actually OK. Is the fact that there is a warning causing you trouble? We could suppress it.

Best regards,
Sherm

Re: Can't figure out: binding dereferenced null pointer to reference has undefined behavior

Posted: Wed May 31, 2017 6:43 pm
by chrisdembia
It is unlikely that your downstream problems are related to this warning. There is currently an Issue and a Pull Request on GitHub regarding this warning (https://github.com/simbody/simbody/pull/533).

Re: Can't figure out: binding dereferenced null pointer to reference has undefined behavior

Posted: Thu Jun 01, 2017 12:42 am
by sam
Good to know that's not the problem. I'll continue hacking. Should I be using -std=c++14 , on simbody, openmm, and molmodel?

Re: Can't figure out: binding dereferenced null pointer to reference has undefined behavior

Posted: Thu Jun 01, 2017 2:50 pm
by chrisdembia
Simbody requires C++11 features. C++14 is not required for Simbody, but I think Simbody should also compile under C++14 (this is not tested regularly). If you compile Simbody with C++11, then all code that depends on Simbody must also be compiled with C++11. I don't know about the requirements for OpenMM or MolModel.