Skip to content

Clang wrongly allows overriding method to vary its return type #111742

@pkasting

Description

@pkasting

The following code generates no warnings in Clang despite the override's return type being incorrect:

struct S {
  virtual const void* f() = 0;
  virtual ~S() = default;  // Silence -Wnon-virtual-dtor
};

struct T : S {
  void* f() override;  // Should warn or error
};

Other compilers:
gcc: Warns
MSVC: Errors
Live example: https://godbolt.org/z/TjoxEzd7M

Larger example demonstrating dispatch in the presence of overloads: https://godbolt.org/z/orcfbrnGz

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions