| Issue |
171526
|
| Summary |
[clang-tidy] Check request: bugprone-mixed-smart-pointers
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
denzor200
|
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 <boost/enable_shared_from_this.hpp>
#include <memory>
class MyClass : public boost::enable_shared_from_this<MyClass> {
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<MyClass>();
p->method(); // Undefined behavior!
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs