Bug 105701 - Warn about unused initializer for virtual base
Summary: Warn about unused initializer for virtual base
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
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:
Known to work:
Known to fail:
Last reconfirmed:


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.