The smallest instance of my problem that I encountered is as follows:
struct __attribute__((aligned(16))) Foo { float x, y, z; Foo(float x, float y, float z) : x(x), y(y), z(z) {} }; class Bar { public: Foo foo; Bar(const Foo &foo) : foo(foo) {} Foo bar() { return foo; } }; int main() { Bar *bar = new Bar(Foo(0.0f, 0.0f, 0.0f)); bar->bar(); return 0; }
This piece of code leads to a segmentation error at startup if compiled with clang++ (version 3.4, available by default on Ubuntu 14.04). The problem does not occur when I compile this with g++ (version 4.8.4). Is this a compiler error or is there some problem with my code?
As a side note: the program does not crash if bar allocated on the stack, that is:
Bar bar(Foo(0.0f, 0.0f, 0.0f)); bar.bar();
works as intended.
source share