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

Simbody is useful for internal coordinate and coarse grained molecule modeling, large scale mechanical models like skeletons, and anything else that can be modeled as bodies interconnected by joints, acted upon by forces, and restricted by constraints.
POST REPLY
User avatar
Samuel Flores
Posts: 189
Joined: Mon Apr 30, 2007 1:06 pm

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

Post by Samuel Flores » Wed May 31, 2017 3:01 pm

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); } \
^~~~~~~~~~~~~~~~~~~~~~~~

User avatar
Samuel Flores
Posts: 189
Joined: Mon Apr 30, 2007 1:06 pm

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

Post by Samuel Flores » Wed May 31, 2017 3:02 pm

I am building on OS 10.12 Sierra.

thanks

sam

User avatar
Michael Sherman
Posts: 805
Joined: Fri Apr 01, 2005 6:05 pm

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

Post by Michael Sherman » Wed May 31, 2017 3:24 pm

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

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

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

Post by Christopher Dembia » Wed May 31, 2017 6:43 pm

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).

User avatar
Samuel Flores
Posts: 189
Joined: Mon Apr 30, 2007 1:06 pm

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

Post by Samuel Flores » Thu Jun 01, 2017 12:42 am

Good to know that's not the problem. I'll continue hacking. Should I be using -std=c++14 , on simbody, openmm, and molmodel?

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

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

Post by Christopher Dembia » Thu Jun 01, 2017 2:50 pm

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.

POST REPLY