Skip to content

[clang-tidy] Improve documentation of bugprone-pointer-arithmetic-on-polymorphic-object #107831

@chrchr-github

Description

@chrchr-github

https://clang.llvm.org/extra/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.html

  • The first example doesn't compile (virtual void ~Base();)
  • The example also produces a clang-analyzer-cplusplus.NewDelete warning, which might lead to confusion

A better example could be

struct Base {
  virtual ~Base();
  int i;
};

struct Derived : public Base {};

int foo(const Derived d[]) {
    return d[1].i;
}

In this case, making Derived final suppresses the warning, which should also be mentioned.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions