Skip to content

[clang] Warn about unnecessary virtual specifiers #131108

@zmodem

Description

@zmodem

Consider:

struct S final {
  virtual void foo();
};

S::foo() doesn't override anything and it cannot be overridden because S is final, so declaring it virtual is wasteful and the compiler could warn about that.


Maybe not as useful but in a similar vein, Clang could warn about members which are known never to be overridden because the class is local to the file, for example:

namespace {
struct S {
  virtual void foo() { ... }
};
}

[... no classes derived from S, or at least none that override S::foo() ... ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions