ODR violation warning when compiling with -flto -fno-semantic-interposition -fPIC

Dmitriy Demin demindf@gmail.com
Sat Jun 3 02:11:00 GMT 2017


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



More information about the Gcc-help mailing list