In C++ `std::moving` a `const`-qualified value yields a constant
r-value reference (`const T&&`) which won't be matched with a callable
taking non-constant r-value reference (like move constructors) but
can play with one taking a constant l-value reference (like copy
constructors do). This behaviour is surprising especially in lambas
where adding or removing the `mutable` specifier may lead to different
behaviour. The problem isn't obvious and it's easy to wrongly drop
the `mutable` druing a clean-up. Therefore introducing a tool for
developers to fail at compile-time if that happens seems desired.
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*-
+// vim: ts=8 sw=2 smarttab expandtab
+
+#pragma once
+
+#include <type_traits>
+
+template <class T>
+void assert_moveable(T& t) {
+ // It's fine
+}
+template <class T>
+void assert_moveable(const T& t) {
+ static_assert(always_false<T>::value, "unable to move-out from T");
+}
+
#include <sstream>
#include "common/likely.h"
+#include "crimson/common/utility.h"
#include "crimson/os/seastore/logging.h"
#include "node_extent_manager.h"
}
return seastar::now().then(
[c, &pos, this_ref = std::move(this_ref), this, FNAME] () mutable {
+ assert_moveable(this_ref);
#ifndef NDEBUG
assert(!impl->is_keys_empty());
if (impl->has_single_value()) {