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

            Bug ID: 114241
           Summary: False-positive -Wodr warning when using -flto and
                    -fno-semantic-interposition
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: abbeyj+gcc at gmail dot com
  Target Milestone: ---

When building the following example, a `-Wodr` warning is shown.  I don't think
the code violates the ODR so this warning is unexpected.  This reproducer
consists of 3 files.

d.h:
```
class A {
public:
  virtual ~A();
  virtual void a1();
};

class B : public A {
public:
  void a1();
  virtual void b1() = 0;
  virtual void b2() = 0;
};

class C : public B {
};

class D : public C {
public:
  void b1();
  void b2();
};
```


foo.cpp:
```
#include "d.h"

void foo() {
  D x;
}
```


bar.cpp:
```
#include "d.h"

void B::a1() {
}

void bar() {
  D y;
}
```


Build using:
g++ -fPIC -fno-semantic-interposition -flto -c foo.cpp
g++ -fPIC -fno-semantic-interposition -flto -c bar.cpp
g++ -shared foo.o bar.o -o lib.so


Output:
> d.h:14:7: warning: virtual table of type ‘struct C’ violates one definition 
> rule [-Wodr]
>    14 | class C : public B {
>       |       ^
> d.h:14:7: note: the conflicting type defined in another translation unit has 
> virtual table with more entries
>    14 | class C : public B {
>       |       ^


The warning message here is not great as it refers to "another translation
unit" but never names either of the two translation units involved.  In this
reduced example there are only two translation units but when there are many
translation units involved it is more difficult to figure out where the problem
is coming from.

The bigger issue is that I don't think this warning should have been issued at
all.  I can't see any way that the code is violating the ODR.

The earliest version that I've been able to reproduce with is 8.4

Godbolt link: https://godbolt.org/z/ncnqPMdzq

Reply via email to