[cfe-dev] Building the Bullet Physics SDK with Clang: Success!

Daniel Dunbar daniel at zuster.org
Mon Oct 4 10:07:40 PDT 2010


FYI, Bullet is actually part of the LLVM test-suite repository, which
we regular build / test / time as part of our nightly tests.

 - Daniel

On Fri, Oct 1, 2010 at 11:01 PM, Ryan Gerleve <aikavanak at gmail.com> wrote:
> Mostly just for fun, I decided to try compiling the Bullet Physics SDK
> (www.bulletphysics.org) with clang. I am happy to report that aside
> from a very small modification to the Bullet code, clang built the entire
> SDK (libraries and demos) with no problem!
>
> The small refactor was necessary because the soft body library
> tries to use static const variables to zero-initialize certain objects.
> The objects happen to be structs, without a user-defined constructor,
> derived from another struct with a user-defined default constructor.
> The reduced test case is
>
> struct Base {
>   Base() {}
> };
>
> struct Derived: Base {
> };
>
> static const Derived d;
>
> Clang says, "error: default initialization of an object of const
> type 'const Derived' requires a user-provided default constructor."
> G++ accepts this code.
>
> Looking at the C++03 standard, I'm a bit confused. Section 8.5 paragraph 6
> says that "Every object of static storage duration shall be zero-initialized at
> program startup before any other initialization takes place." But it also says
> in paragraph 9 of the same section that "If no initializer is specified for an
> object, ... if the object is of const-qualified type, the underlying class type
> shall have a user-declared default constructor."
>
> My intuition tells me that static objects get zero-initialized first,
> then default-constructed a bit later, all during program startup. Is this the
> correct interpretation of the standard? If so, it sounds like it goes against
> the C++ principle of not paying for things you don't use. Why zero-init an
> object if it's just going to be default-initialized immediately after?
>
> Of course, if this is the case, then clang is correct, and g++ & Bullet are
> not standard-conforming.
>
> -Ryan
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>




More information about the cfe-dev mailing list