Issue |
146324
|
Summary |
[clang-tidy] `bugprone-unhandled-self-assignment` doesn't know about allocator arguments to copy/move constructors
|
Labels |
clang-tidy
|
Assignees |
|
Reporter |
MikeWeller
|
I may have copy/move constructors that take an additional allocator argument (similar to `vector( const vector& other, const Allocator& alloc );`). Additionally, the type may use the [leading-allocator convention](https://en.cppreference.com/w/cpp/memory/uses_allocator.html) with `std::allocator_arg_t`.
If I call one of these "extended" copy/move constructors in my copy/move-and-swap idiom, `bugprone-unhandled-self-assignment` doesn't recognize it and produces a false positive warning (copy-and-swap/move should not trigger the warning).
A rough test:
```
// REQUIRES: static-analyzer
// RUN: clang-tidy -checks='-*,bugprone-unhandled-self-assignment' %s -- | FileCheck %s
namespace std {
namespace pmr {
template <typename TYPE = void>
class allocator {};
}
struct allocator_arg_t {} allocator_arg;
};
#define LEADING_STYLE 1
class MyValueType
{
// pointer member to trigger bugprone-unhandled-self-assignment
void *foo = nullptr;
public:
using allocator_type = std::pmr::allocator<>;
MyValueType(const MyValueType& other)
{
}
#ifdef LEADING_STYLE
MyValueType(std::allocator_arg_t, const allocator_type& alloc, const MyValueType& other)
{
}
#else
MyValueType(const MyValueType& other, const allocator_type& alloc)
{
}
#endif
#ifdef LEADING_STYLE
// CHECK-NOT: warning
MyValueType& operator=(const MyValueType& other)
{
MyValueType tmp(std::allocator_arg, get_allocator(), other);
swap(tmp);
return *this;
}
#else
// CHECK-NOT: warning
MyValueType& operator=(const MyValueType& other)
{
MyValueType tmp(other, get_allocator());
swap(tmp);
return *this;
}
#endif
void swap(MyValueType& other) noexcept {
}
allocator_type get_allocator() const {
return allocator_type();
}
};
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs