https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84044

            Bug ID: 84044
           Summary: Spurious -Wodr warning with -flto
           Product: gcc
           Version: 7.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: geoffrey at allott dot email
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

a.cpp
=====

struct A {
    virtual ~A();
};

A::~A() {}


b.cpp
=====

struct A {
    virtual ~A();
};

struct B {
    A a;
    A get();
};

A B::get() {
    return a;
}


Makefile
========

main: a.cpp b.cpp
        $(CXX) a.cpp -c -fno-semantic-interposition -fpic -flto
        $(CXX) b.cpp -c -flto -O1
        $(CXX) a.o b.o


This results in:

b.cpp:1:8: warning: virtual table of type ‘struct A’ violates one definition
rule   [-Wodr]
 struct A {
        ^
a.cpp:1:8: note: the conflicting type defined in another translation unit
 struct A {
        ^
a.cpp:5:1: note: virtual method ‘__base_dtor ’
 A::~A() {}
 ^
a.cpp:5:1: note: ought to match virtual method ‘__base_dtor ’ but does not



Note that even something as simple as inlining the definition of the destructor
or the `get` function cause the warning to go away. All of the flags are
necessary to reproduce the error.

Reply via email to