llvm / llvm/llvm-project

[clang-tidy][check request] Detect implicit conversion from `unique_ptr<Derived>` to `unique_ptr<BaseWithNonVirtualDtor>`

Open
#183,496 3 comments 0 reactions 0 assignees View on GitHub
check-request clang-tidy
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

From [std::unique_ptr - cppreference.com](https://en.cppreference.com/w/cpp/memory/unique_ptr.html#Notes):

> If `T` is a [derived class](https://en.cppreference.com/w/cpp/language/derived_class.html) of some base `B`, then `unique_ptr` is [implicitly convertible](https://en.cppreference.com/w/cpp/memory/unique_ptr/unique_ptr.html) to `unique_ptr`. The default deleter of the resulting `unique_ptr` will use [`operator delete`](https://en.cppreference.com/w/cpp/memory/new/operator_delete.html) for `B`, leading to [undefined behavior](https://en.cppreference.com/w/cpp/language/destructor.html#Virtual_destructors) unless the destructor of `B` is [virtual](https://en.cppreference.com/w/cpp/language/virtual.html). ...

If the second template argument of `unique_ptr` is not same as corresponding default argument, it should be excluded from this check.

Inspired from https://github.com/llvm/llvm-project/pull/164212#discussion_r2649055764 and #183101.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.