Patch to allow Bullet to compile with clang

Stillmoon
Posts: 4
Joined: Thu Dec 10, 2009 5:00 pm

Patch to allow Bullet to compile with clang

Post by Stillmoon »

Currently, the clang compiler cannot compile r2221 of Bullet, the head at the time of this writing. (Clang is a new C-dialect compiler that is included in newer versions of Xcode.)

The problem is some non-standard C++ code in the soft body library. The ZeroInitialize function in btSoftBodyInternals.h uses a dummy static object to easily zero-initialize certain objects. However, the object being initialized needs to have a user-defined default constructor. This is because, even though static objects are zero-initialized, if there is no initializer, they are also default-initialized afterwards. Because the objects are const, a user-defined default constructor is required.

I have attached a simple patch that adds default constructors for the affected structs (members of btSoftBody: Material, Feature, Node, Link, Face, Tetra, and Note). The file is an actual .zip archive, not just a renamed text file. This should not affect program behavior, because the constructors don't do anything that would change the zero-initialized state of the objects. I didn't see any difference in the soft body demos after building & running them on OS X with this patch applied.

I would appreciate it if this could be applied, as clang seems to be replacing gcc on Apple platforms.

Thanks,
Ryan

P.S.
For those interested, the relevant parts of the C++03 standard are section 8.5, paragraph 9:
"Every object of static storage duration shall be zero-initialized at program startup before any other initialization takes place. [Note: in some cases, additional initialization is done later. ]"

and 8.5 paragraph 6:
"If no initializer is specified for an object, and the object is of (possibly cv-qualified) non-POD class type (or array thereof), the object shall be default-initialized; if the object is of const-qualified type, the underlying class type shall have a user-declared default constructor."
You do not have the required permissions to view the files attached to this post.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Patch to allow Bullet to compile with clang

Post by Erwin Coumans »

The patch is applied in the latest trunk, see http://code.google.com/p/bullet/source/detail?r=2222

Thanks a lot for the report/patch, we'll re-upload the Bullet-2.77 package with the updated SVN revision 2222 today.
Thanks,
Erwin