I am writing a tiny kernel with C ++ 11 and have two instances of the same type that must be created before any other static objects are created.
The code I wrote is as follows:
// test.hpp class test { // blahblah... }; // test.cpp typedef char fake_inst[sizeof(test)] __attribute__((aligned(alignof(test)))); fake_inst inst1; fake_inst inst2; // main.cpp extern test inst1; extern test inst2; int kmain() { // copy data section // initialize bss section new (&inst1) test(); new (&inst2) test(); // call constructors in .init_array // kernel stuffs }
It builds and works as expected without warning messages, but not with LTO.
I get a ton of warning messages complaining about type matching, and I'm wondering if there is a workaround, as this confuses me to find other “real” warnings or error messages.
Any suggestion?
source share