Bug 115435 - Issue warning for indirect call to pure virtual function in ctor or dtor
Summary: Issue warning for indirect call to pure virtual function in ctor or dtor
Status: RESOLVED DUPLICATE of bug 47940
Alias: None
Product: gcc
Classification: Unclassified
Component: ipa (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: new-warning, new_warning
  Show dependency treegraph
 
Reported: 2024-06-11 14:24 UTC by Jonathan Wakely
Modified: 2024-06-11 14:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-06-11 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2024-06-11 14:24:02 UTC
We warn about undefined calls to pure virtual functions from constructors and destructors:

struct Base {
    virtual void f() = 0;
    Base() { f(); }
};

<source>: In constructor 'Base::Base()':
<source>:3:15: warning: pure virtual 'virtual void Base::f()' called from constructor
    3 |     Base() { f(); }
      |              ~^~


But for indirect calls we don't warn:

struct Base {
    virtual void f() = 0;
    Base() { g(); }
    void g() { f(); }
};

It would be good if IPA could warn for this case too. After g() is inlined into the constructor we know that the call to f() is undefined.

I assume this would mean moving the warning from the front end to the middle end.
Comment 1 Andrew Pinski 2024-06-11 14:27:58 UTC
.
Comment 2 Andrew Pinski 2024-06-11 14:31:22 UTC
Dup. will update that bug.

*** This bug has been marked as a duplicate of bug 47940 ***