-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang-tidy] Improve modernize-make-shared check (#70600)
Improved modernize-make-shared check to support std::shared_ptr implementations that inherit the reset method from a base class. In GCC that class is called __shared_ptr. Fixes #64481
- Loading branch information
Showing
3 changed files
with
35 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 18 additions & 9 deletions
27
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/shared_ptr.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,33 @@ | ||
namespace std { | ||
|
||
template <typename type> | ||
class shared_ptr { | ||
class __shared_ptr { | ||
protected: | ||
__shared_ptr(); | ||
__shared_ptr(type *ptr); | ||
~__shared_ptr(); | ||
public: | ||
shared_ptr(); | ||
shared_ptr(type *ptr); | ||
shared_ptr(const shared_ptr<type> &t) {} | ||
shared_ptr(shared_ptr<type> &&t) {} | ||
~shared_ptr(); | ||
type &operator*() { return *ptr; } | ||
type *operator->() { return ptr; } | ||
type *release(); | ||
void reset(); | ||
void reset(type *pt); | ||
shared_ptr &operator=(shared_ptr &&); | ||
template <typename T> | ||
shared_ptr &operator=(shared_ptr<T> &&); | ||
|
||
private: | ||
type *ptr; | ||
}; | ||
|
||
template <typename type> | ||
class shared_ptr : public __shared_ptr<type> { | ||
public: | ||
shared_ptr(); | ||
shared_ptr(type *ptr); | ||
shared_ptr(const shared_ptr<type> &t); | ||
shared_ptr(shared_ptr<type> &&t); | ||
~shared_ptr(); | ||
shared_ptr &operator=(shared_ptr &&); | ||
template <typename T> | ||
shared_ptr &operator=(shared_ptr<T> &&); | ||
}; | ||
|
||
} // namespace std |