llvm / llvm/llvm-project

[clang-tidy] Check request: bugprone-mixed-smart-pointers

Open
#171,526 1 comment 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

Need check to detect dangerous mismatches between `enable_shared_from_this` implementations and corresponding `shared_ptr` types, specifically when `boost::enable_shared_from_this` is used with `std::shared_ptr`, and vice versa. This mismatch causes runtime error (`shared_from_this()` will fail), so the check should be in bugprone module.

Example:
```
#include
#include

class MyClass : public boost::enable_shared_from_this {
public:
void method() {
auto self = shared_from_this(); // Will fail at runtime!
}
};

void test() {
// Mismatch: boost::enable_shared_from_this with std::make_shared
auto p = std::make_shared();
p->method(); // Undefined behavior!
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the clang-tidy bugprone module and its existing check entry points, then review how boost::enable_shared_from_this and std::enable_shared_from_this are represented in the example. Define coverage for both mismatch directions and add tests demonstrating that each detected combination would make shared_from_this() fail at runtime.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.