public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug lto/114241] New: False-positive -Wodr warning when using -flto and -fno-semantic-interposition
@ 2024-03-05 15:38 abbeyj+gcc at gmail dot com
  2024-03-06  7:46 ` [Bug lto/114241] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: abbeyj+gcc at gmail dot com @ 2024-03-05 15:38 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-06  9:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-05 15:38 [Bug lto/114241] New: False-positive -Wodr warning when using -flto and -fno-semantic-interposition abbeyj+gcc at gmail dot com
2024-03-06  7:46 ` [Bug lto/114241] " rguenth at gcc dot gnu.org
2024-03-06  9:16 ` hubicka at ucw dot cz
2024-03-06  9:18 ` hubicka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).