deallocate() function in allocator marked as not used
已回答
In a custom allocator, the IDE marks the deallocate function (but not allocate) as never used:
template<typename T>
class e_allocator {
public:
using value_type = T;
using pointer = value_type *;
using difference_type = typename std::pointer_traits<pointer>::difference_type;
using size_type = std::make_unsigned_t<difference_type>;
pointer allocate(size_type n) {
return static_cast<pointer>(::operator new(n * sizeof(value_type),
static_cast<std::align_val_t>(alignof(value_type))));
}
void deallocate(pointer p, size_type n) {
// volatile is required here to defeat the optimizer
std::fill_n(static_cast<volatile pointer>(p), n, 0);
::operator delete(p);
}
};
void foo() { std::vector<int, e_allocator<int> > v; }
Is there a way to suppress the warning?
Thanks.
请先登录再写评论。
Hi! Yes, you can disable or suppress the "Unused global declaration" inspection:
More details: https://www.jetbrains.com/help/clion/disabling-and-enabling-inspections.html.
Also I've created https://youtrack.jetbrains.com/issue/CPP-15080, feel free to comment or upvote in order to get updates. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.