Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
shared_ptr: ignore false alarm from GCC-12
Browse files Browse the repository at this point in the history
before GCC addresses this issue, we have to disable this
warning.

see also scylladb#1037
and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105204.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
tchaikov committed Nov 30, 2022
1 parent 2bb5124 commit 4af2ad8
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions include/seastar/core/shared_ptr.hh
Original file line number Diff line number Diff line change
@@ -290,17 +290,31 @@ public:
lw_shared_ptr(std::nullptr_t) noexcept : lw_shared_ptr() {}
lw_shared_ptr(const lw_shared_ptr& x) noexcept : _p(x._p) {
if (_p) {
#pragma GCC diagnostic push
// to silence the false alarm from GCC 12, see
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105204
#if defined(__GNUC__) && (__GNUC__ >= 12)
#pragma GCC diagnostic ignored "-Wuse-after-free"
#endif
++_p->_count;
#pragma GCC diagnostic pop
}
}
lw_shared_ptr(lw_shared_ptr&& x) noexcept : _p(x._p) {
x._p = nullptr;
}
[[gnu::always_inline]]
~lw_shared_ptr() {
#pragma GCC diagnostic push
// to silence the false alarm from GCC 12, see
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105204
#if defined(__GNUC__) && (__GNUC__ >= 12)
#pragma GCC diagnostic ignored "-Wuse-after-free"
#endif
if (_p && !--_p->_count) {
accessors<T>::dispose(_p);
}
#pragma GCC diagnostic pop
}
lw_shared_ptr& operator=(const lw_shared_ptr& x) noexcept {
if (_p != x._p) {
@@ -534,9 +548,16 @@ public:
x._p = nullptr;
}
~shared_ptr() {
#pragma GCC diagnostic push
// to silence the false alarm from GCC 12, see
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105204
#if defined(__GNUC__) && (__GNUC__ >= 12)
#pragma GCC diagnostic ignored "-Wuse-after-free"
#endif
if (_b && !--_b->count) {
delete _b;
}
#pragma GCC diagnostic pop
}
shared_ptr& operator=(const shared_ptr& x) noexcept {
if (this != &x) {

0 comments on commit 4af2ad8

Please sign in to comment.