Bug 105701 - Warn about unused initializer for virtual base
Summary: Warn about unused initializer for virtual base
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.1.1
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: new-warning, new_warning
  Show dependency treegraph
 
Reported: 2022-05-23 09:31 UTC by Jonathan Wakely
Modified: 2024-04-10 09:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2022-05-23 09:31:25 UTC
struct Base
{
  Base() { }
  Base(int) { }
  virtual void f() = 0;
};

struct Abstract : virtual Base
{
  Abstract(int i) : Base(i) { }
};

struct Concrete : Abstract
{
  Concrete() : Abstract(1) { }

  void f() override { }
};


A user on IRC suggested we should warn about the Base(i) initializer in the Abstract(int) constructor. That class can never be constructed, so it can never initialize the virtual base.

IIUC that is true even if the derived class does 'using Abstract::Abstract;' so I don't think there's any way for that Base(i) to ever be used.