On 2017-06-03 05:11 +0300, Dmitriy Demin wrote: > Hi, > > GCC emits strange ODR warning for the code below when I compile it > with "-flto -fno-semantic-interposition -fPIC". > > ---- 1.h ---- > struct Foo { > virtual ~Foo(); > }; > > ---- 1.cpp ---- > #include "1.h" > > Foo::~Foo() { } > > ---- 2.cpp ---- > #include "1.h" > > void f(Foo x) { > Foo y(x); > } > > int main() { } > > -------- > > When compiling it > $ g++ -c 1.cpp -flto -fno-semantic-interposition -fPIC > $ g++ -c 2.cpp -flto -fno-semantic-interposition -fPIC > $ g++ 1.o 2.o > > it produces warnings: > > 1.h:1:8: warning: virtual table of type ‘struct Foo’ violates one > definition rule [-Wodr] > struct Foo { > ^ > 1.h:1:8: note: the conflicting type defined in another translation unit > struct Foo { > ^ > 1.cpp:3:1: note: virtual method ‘__base_dtor ’ > Foo::~Foo() { } > ^ > 1.h:2:13: note: ought to match virtual method ‘__comp_dtor ’ but does not > virtual ~Foo(); > > ---- ---- > > I can't find anything wrong with the code, am I missing anything? > Could it be a bug in ODR detection or optimizer? If so, should I worry > about correctness of compiled code? I can only reproduce this when all > three -f* flags are present. I tried current gcc snapshot (8.0.0 > 20170528) as well as gcc 7.1 and gcc 6.3. All of them show the same > warning. > > Thanks in advance I can't reproduce it on x86_64-linux-gnu. What is your architecture? -- Xi Ruoyao <ryxi@xxxxxxxxxxxxxxxxx> School of Aerospace Science and Technology, Xidian University