public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "abbeyj+gcc at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug lto/114241] New: False-positive -Wodr warning when using -flto and -fno-semantic-interposition
Date: Tue, 05 Mar 2024 15:38:34 +0000	[thread overview]
Message-ID: <bug-114241-4@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2024-03-05 15:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-05 15:38 abbeyj+gcc at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-114241-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).