[clang-tidy] New check: modernize-use-atomic-shared-ptr
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
C++20 gives us ability to use `std::atomic>`. Needs a check to convert legacy to use this ability.
Before:
```
std::shared_ptr sharedPtr;
void writer() {
auto newPtr = std::make_shared(42);
std::atomic_store(&sharedPtr, newPtr);
}
void reader() {
auto localPtr = std::atomic_load(&sharedPtr);
if (localPtr) {
std::cout << *localPtr << "\n"; // 42
}
}
```
After:
```
std::atomic> atomicPtr;
void writer() {
auto newPtr = std::make_shared(42);
atomicPtr.store(newPtr);
}
void reader() {
auto localPtr = atomicPtr.load();
if (localPtr) {
std::cout << *localPtr << "\n"; // 42
}
}
```
Contributor guide
Research direction
Start from the before-and-after C++20 examples in the issue and review the clang-tidy modernize-check infrastructure to determine the supported atomic_load and atomic_store forms. Done means the new check consistently converts eligible legacy shared_ptr operations to std::atomic> with equivalent load and store calls.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100