diff --git a/src/common/buffer.cc b/src/common/buffer.cc
index 3d01a460af2..b9da5bf9c14 100644
--- a/src/common/buffer.cc
+++ b/src/common/buffer.cc
@@ -2258,8 +2258,8 @@ int buffer::list::write_file(const char *fn, int mode)
 
 static int do_writev(int fd, struct iovec *vec, uint64_t offset, unsigned veclen, unsigned bytes)
 {
-  ssize_t r = 0;
   while (bytes > 0) {
+    ssize_t r = 0;
 #ifdef HAVE_PWRITEV
     r = ::pwritev(fd, vec, veclen, offset);
 #else
@@ -2492,9 +2492,8 @@ void buffer::list::hexdump(std::ostream &out, bool trailing_newline) const
   unsigned per = 16;
   bool was_zeros = false, did_star = false;
   for (unsigned o=0; o<length(); o += per) {
-    bool row_is_zeros = false;
     if (o + per < length()) {
-      row_is_zeros = true;
+      bool row_is_zeros = true;
       for (unsigned i=0; i<per && o+i<length(); i++) {
 	if ((*this)[o+i]) {
 	  row_is_zeros = false;
diff --git a/src/common/crc32c.cc b/src/common/crc32c.cc
index a30d3866413..d5c984ab463 100644
--- a/src/common/crc32c.cc
+++ b/src/common/crc32c.cc
@@ -218,8 +218,8 @@ uint32_t ceph_crc32c_zeros(uint32_t crc, unsigned len)
   len = len >> 4;
   range = 4;
   while (len != 0) {
-    uint32_t crc1 = 0;
     if ((len & 1) == 1) {
+      uint32_t crc1 = 0;
       uint32_t* ptr = crc_turbo_table/*.val*/[range];
       while (crc != 0) {
         uint32_t mask = ~((crc & 1) - 1);
diff --git a/src/common/obj_bencher.h b/src/common/obj_bencher.h
index e1ddc832c31..0d4a5c11c91 100644
--- a/src/common/obj_bencher.h
+++ b/src/common/obj_bencher.h
@@ -107,7 +107,7 @@ protected:
   ostream& out(ostream& os);
   ostream& out(ostream& os, utime_t& t);
 public:
-  explicit ObjBencher(CephContext *cct_) : show_time(false), cct(cct_), lock("ObjBencher::lock") {}
+  explicit ObjBencher(CephContext *cct_) : show_time(false), cct(cct_), lock("ObjBencher::lock"), data() {}
   virtual ~ObjBencher() {}
   int aio_bench(
     int operation, int secondsToRun,
diff --git a/src/compressor/lz4/LZ4Compressor.h b/src/compressor/lz4/LZ4Compressor.h
index 5ad5d31b762..8f0f093249c 100644
--- a/src/compressor/lz4/LZ4Compressor.h
+++ b/src/compressor/lz4/LZ4Compressor.h
@@ -50,12 +50,10 @@ class LZ4Compressor : public Compressor {
     int pos = 0;
     const char *data;
     unsigned num = src.get_num_buffers();
-    uint32_t origin_len;
-    int compressed_len;
     encode((uint32_t)num, dst);
     while (left) {
-      origin_len = p.get_ptr_and_advance(left, &data);
-      compressed_len = LZ4_compress_fast_continue(
+      uint32_t origin_len = p.get_ptr_and_advance(left, &data);
+      int compressed_len = LZ4_compress_fast_continue(
         &lz4_stream, data, outptr.c_str()+pos, origin_len,
         outptr.length()-pos, 1);
       if (compressed_len <= 0)
diff --git a/src/include/denc.h b/src/include/denc.h
index b32502a9603..3a332ed48bf 100644
--- a/src/include/denc.h
+++ b/src/include/denc.h
@@ -1093,8 +1093,8 @@ public:
   static void bound_encode(const container& s, size_t& p, uint64_t f = 0) {
     if constexpr (traits::bounded) {
       if constexpr (traits::featured) {
-        size_t elem_size = 0;
         if (!s.empty()) {
+          size_t elem_size = 0;
           denc(*s.begin(), elem_size, f);
           p += elem_size * s.size();
         }
diff --git a/src/librbd/io/ImageDispatchSpec.cc b/src/librbd/io/ImageDispatchSpec.cc
index 07bead92da1..df63f35256b 100644
--- a/src/librbd/io/ImageDispatchSpec.cc
+++ b/src/librbd/io/ImageDispatchSpec.cc
@@ -15,7 +15,7 @@ struct ImageDispatchSpec<I>::SendVisitor
   : public boost::static_visitor<void> {
   ImageDispatchSpec* spec;
 
-  SendVisitor(ImageDispatchSpec* spec)
+  explicit SendVisitor(ImageDispatchSpec* spec)
     : spec(spec) {
   }
 
diff --git a/src/librbd/io/ImageRequestWQ.cc b/src/librbd/io/ImageRequestWQ.cc
index cc1371f8d31..cbcdf1010ab 100644
--- a/src/librbd/io/ImageRequestWQ.cc
+++ b/src/librbd/io/ImageRequestWQ.cc
@@ -54,7 +54,7 @@ struct ImageRequestWQ<I>::C_AcquireLock : public Context {
 template <typename I>
 struct ImageRequestWQ<I>::C_BlockedWrites : public Context {
   ImageRequestWQ *work_queue;
-  C_BlockedWrites(ImageRequestWQ *_work_queue)
+  explicit C_BlockedWrites(ImageRequestWQ *_work_queue)
     : work_queue(_work_queue) {
   }
 
diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc
index 5ff2aeebb71..64a703136d0 100644
--- a/src/mgr/BaseMgrModule.cc
+++ b/src/mgr/BaseMgrModule.cc
@@ -644,11 +644,11 @@ BaseMgrModule_init(BaseMgrModule *self, PyObject *args, PyObject *kwds)
         return -1;
     }
 
-    self->py_modules = (ActivePyModules*)PyCapsule_GetPointer(
-        py_modules_capsule, nullptr);
+    self->py_modules = static_cast<ActivePyModules*>(PyCapsule_GetPointer(
+        py_modules_capsule, nullptr));
     assert(self->py_modules);
-    self->this_module = (ActivePyModule*)PyCapsule_GetPointer(
-        this_module_capsule, nullptr);
+    self->this_module = static_cast<ActivePyModule*>(PyCapsule_GetPointer(
+        this_module_capsule, nullptr));
     assert(self->this_module);
 
     return 0;
diff --git a/src/mgr/BaseMgrStandbyModule.cc b/src/mgr/BaseMgrStandbyModule.cc
index 468e970359d..12182f360cc 100644
--- a/src/mgr/BaseMgrStandbyModule.cc
+++ b/src/mgr/BaseMgrStandbyModule.cc
@@ -47,8 +47,8 @@ BaseMgrStandbyModule_init(BaseMgrStandbyModule *self, PyObject *args, PyObject *
         return -1;
     }
 
-    self->this_module = (StandbyPyModule*)PyCapsule_GetPointer(
-        this_module_capsule, nullptr);
+    self->this_module = static_cast<StandbyPyModule*>(PyCapsule_GetPointer(
+        this_module_capsule, nullptr));
     assert(self->this_module);
 
     return 0;
diff --git a/src/mgr/Mgr.cc b/src/mgr/Mgr.cc
index cf055e91773..6a027deedf1 100644
--- a/src/mgr/Mgr.cc
+++ b/src/mgr/Mgr.cc
@@ -523,7 +523,7 @@ bool Mgr::ms_dispatch(Message *m)
       m->put();
       break;
     case MSG_SERVICE_MAP:
-      handle_service_map((MServiceMap*)m);
+      handle_service_map(static_cast<MServiceMap*>(m));
       py_module_registry->notify_all("service_map", "");
       m->put();
       break;
diff --git a/src/mon/MonMap.cc b/src/mon/MonMap.cc
index 890289cf52e..56d8926e28b 100644
--- a/src/mon/MonMap.cc
+++ b/src/mon/MonMap.cc
@@ -339,8 +339,7 @@ int MonMap::build_from_host_list(std::string hostlist, const std::string &prefix
   }
 
   // maybe they passed us a DNS-resolvable name
-  char *hosts = NULL;
-  hosts = resolve_addrs(hostlist.c_str());
+  char *hosts = resolve_addrs(hostlist.c_str());
   if (!hosts)
     return -EINVAL;
   bool success = parse_ip_port_vec(hosts, addrs);
diff --git a/src/mon/PGMap.cc b/src/mon/PGMap.cc
index e8a9b4768e9..aba19b5f73a 100644
--- a/src/mon/PGMap.cc
+++ b/src/mon/PGMap.cc
@@ -3024,7 +3024,6 @@ int process_pg_map_command(
     cmd_putval(g_ceph_context, cmdmap, "pool", pool);
   }
 
-  int r = 0;
   stringstream ds;
   if (prefix == "pg stat") {
     if (f) {
@@ -3174,12 +3173,12 @@ int process_pg_map_command(
     cmd_getval(g_ceph_context, cmdmap, "threshold", threshold,
                g_conf->get_val<int64_t>("mon_pg_stuck_threshold"));
 
-    r = pg_map.dump_stuck_pg_stats(ds, f, (int)threshold, stuckop_vec);
-    odata->append(ds);
-    if (r < 0)
+    if (pg_map.dump_stuck_pg_stats(ds, f, (int)threshold, stuckop_vec) < 0) {
       *ss << "failed";
-    else
+    } else {
       *ss << "ok";
+    }
+    odata->append(ds);
     return 0;
   }
 
diff --git a/src/msg/async/dpdk/DPDKStack.h b/src/msg/async/dpdk/DPDKStack.h
index 73759128fde..5bc8f3122a2 100644
--- a/src/msg/async/dpdk/DPDKStack.h
+++ b/src/msg/async/dpdk/DPDKStack.h
@@ -218,7 +218,7 @@ class DPDKWorker : public Worker {
   };
   std::unique_ptr<Impl> _impl;
 
-  virtual void initialize();
+  virtual void initialize() override;
   void set_ipv4_packet_filter(ip_packet_filter* filter) {
     _impl->_inet.set_packet_filter(filter);
   }
@@ -245,7 +245,7 @@ class DPDKStack : public NetworkStack {
     funcs.resize(cct->_conf->ms_async_max_op_threads);
   }
   virtual bool support_zero_copy_read() const override { return true; }
-  virtual bool support_local_listen_table() const { return true; }
+  virtual bool support_local_listen_table() const override { return true; }
 
   virtual void spawn_worker(unsigned i, std::function<void ()> &&func) override;
   virtual void join_worker(unsigned i) override {
diff --git a/src/msg/async/dpdk/IP.h b/src/msg/async/dpdk/IP.h
index 3769c65b816..480b4b95b32 100644
--- a/src/msg/async/dpdk/IP.h
+++ b/src/msg/async/dpdk/IP.h
@@ -118,7 +118,7 @@ class ipv4_tcp final : public ip_protocol {
  public:
   ipv4_tcp(ipv4& inet, EventCenter *c);
   ~ipv4_tcp();
-  virtual void received(Packet p, ipv4_address from, ipv4_address to);
+  virtual void received(Packet p, ipv4_address from, ipv4_address to) override;
   virtual bool forward(forward_hash& out_hash_data, Packet& p, size_t off) override;
   friend class ipv4;
 };
@@ -167,7 +167,7 @@ class ipv4_icmp final : public ip_protocol {
   icmp _icmp;
  public:
   ipv4_icmp(CephContext *c, ipv4& inet) : cct(c), _inet_l4(inet), _icmp(c, _inet_l4) {}
-  virtual void received(Packet p, ipv4_address from, ipv4_address to) {
+  virtual void received(Packet p, ipv4_address from, ipv4_address to) override {
     _icmp.received(std::move(p), from, to);
   }
   friend class ipv4;
diff --git a/src/msg/async/dpdk/net.cc b/src/msg/async/dpdk/net.cc
index 3ef69446822..85e82d61ee5 100644
--- a/src/msg/async/dpdk/net.cc
+++ b/src/msg/async/dpdk/net.cc
@@ -39,8 +39,8 @@
 #undef dout_prefix
 #define dout_prefix *_dout << "net "
 
-interface::interface(CephContext *c, std::shared_ptr<DPDKDevice> dev, EventCenter *center)
-    : cct(c), _dev(dev),
+interface::interface(CephContext *cct, std::shared_ptr<DPDKDevice> dev, EventCenter *center)
+    : cct(cct), _dev(dev),
       _rx(_dev->receive(
           center->get_id(),
           [center, this] (Packet p) {
diff --git a/src/msg/async/dpdk/net.h b/src/msg/async/dpdk/net.h
index 53ef473cf95..2104e5d31e4 100644
--- a/src/msg/async/dpdk/net.h
+++ b/src/msg/async/dpdk/net.h
@@ -117,7 +117,7 @@ class interface {
  private:
   int dispatch_packet(EventCenter *c, Packet p);
  public:
-  explicit interface(CephContext *cct, std::shared_ptr<DPDKDevice> dev, EventCenter *c);
+  explicit interface(CephContext *cct, std::shared_ptr<DPDKDevice> dev, EventCenter *center);
   ethernet_address hw_address() { return _hw_address; }
   const struct hw_features& get_hw_features() const { return _hw_features; }
   subscription<Packet, ethernet_address> register_l3(
diff --git a/src/rgw/rgw_coroutine.cc b/src/rgw/rgw_coroutine.cc
index fecfbb4c679..89f7b33d205 100644
--- a/src/rgw/rgw_coroutine.cc
+++ b/src/rgw/rgw_coroutine.cc
@@ -430,7 +430,7 @@ bool RGWCoroutinesStack::collect(int *ret, RGWCoroutinesStack *skip_stack) /* re
 
 static void _aio_completion_notifier_cb(librados::completion_t cb, void *arg)
 {
-  ((RGWAioCompletionNotifier *)arg)->cb();
+  (static_cast<RGWAioCompletionNotifier *>(arg))->cb();
 }
 
 RGWAioCompletionNotifier::RGWAioCompletionNotifier(RGWCompletionManager *_mgr, const rgw_io_id& _io_id, void *_user_data) : completion_mgr(_mgr),
@@ -531,7 +531,7 @@ void RGWCoroutinesManager::handle_unblocked_stack(set<RGWCoroutinesStack *>& con
                                                   RGWCompletionManager::io_completion& io, int *blocked_count)
 {
   assert(lock.is_wlocked());
-  RGWCoroutinesStack *stack = (RGWCoroutinesStack *)io.user_info;
+  RGWCoroutinesStack *stack = static_cast<RGWCoroutinesStack *>(io.user_info);
   if (context_stacks.find(stack) == context_stacks.end()) {
     return;
   }
diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h
index 0219c670910..c6997d27816 100644
--- a/src/rgw/rgw_op.h
+++ b/src/rgw/rgw_op.h
@@ -2190,15 +2190,15 @@ public:
   void execute() override {}
 
   const char* name() const override { return "get_bucket_meta_search"; }
-  virtual RGWOpType get_type() { return RGW_OP_GET_BUCKET_META_SEARCH; }
-  virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; }
+  virtual RGWOpType get_type() override { return RGW_OP_GET_BUCKET_META_SEARCH; }
+  virtual uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
 };
 
 class RGWDelBucketMetaSearch : public RGWOp {
 public:
   RGWDelBucketMetaSearch() {}
 
-  int verify_permission();
+  int verify_permission() override;
   void pre_exec() override;
   void execute() override;
 
diff --git a/src/rgw/rgw_otp.cc b/src/rgw/rgw_otp.cc
index c937cb4a29a..570562158f1 100644
--- a/src/rgw/rgw_otp.cc
+++ b/src/rgw/rgw_otp.cc
@@ -119,12 +119,10 @@ public:
 
     RGWRados *store = info->store;
 
-    list<string> unfiltered_keys;
-
     int ret = store->list_raw_objects_next(no_filter, max, info->ctx,
                                            keys, truncated);
     if (ret < 0 && ret != -ENOENT)
-      return ret;		        
+      return ret;
     if (ret == -ENOENT) {
       if (truncated)
         *truncated = false;
diff --git a/src/rgw/rgw_rest_bucket.cc b/src/rgw/rgw_rest_bucket.cc
index f6c2c623dcb..bab693f3be4 100644
--- a/src/rgw/rgw_rest_bucket.cc
+++ b/src/rgw/rgw_rest_bucket.cc
@@ -211,7 +211,7 @@ class RGWOp_Set_Bucket_Quota : public RGWRESTOp {
 public:
   RGWOp_Set_Bucket_Quota() {}
 
-  int check_caps(RGWUserCaps& caps) {
+  int check_caps(RGWUserCaps& caps) override {
     return caps.check_cap("buckets", RGW_CAP_WRITE);
   }
 
diff --git a/src/rgw/rgw_rest_config.h b/src/rgw/rgw_rest_config.h
index 0c82674dce9..785fb7e30a7 100644
--- a/src/rgw/rgw_rest_config.h
+++ b/src/rgw/rgw_rest_config.h
@@ -41,7 +41,7 @@ class RGWOp_ZoneConfig_Get : public RGWRESTOp {
 public:
   RGWOp_ZoneConfig_Get() {}
 
-  int check_caps(RGWUserCaps& caps) {
+  int check_caps(RGWUserCaps& caps) override {
     return caps.check_cap("admin", RGW_CAP_READ);
   }
   int verify_permission() override {
diff --git a/src/rgw/rgw_sync_module_aws.cc b/src/rgw/rgw_sync_module_aws.cc
index 9dac4cbb470..42008a74fc6 100644
--- a/src/rgw/rgw_sync_module_aws.cc
+++ b/src/rgw/rgw_sync_module_aws.cc
@@ -949,7 +949,7 @@ public:
   }
 
   void send_ready(const rgw_rest_obj& rest_obj) override {
-    RGWRESTStreamS3PutObj *r = (RGWRESTStreamS3PutObj *)req;
+    RGWRESTStreamS3PutObj *r = static_cast<RGWRESTStreamS3PutObj *>(req);
 
     map<string, string> new_attrs;
     if (!multipart.is_multipart) {
@@ -1088,7 +1088,7 @@ public:
         return set_cr_error(retcode);
       }
 
-      if (!((RGWAWSStreamPutCRF *)out_crf.get())->get_etag(petag)) {
+      if (!(static_cast<RGWAWSStreamPutCRF *>(out_crf.get()))->get_etag(petag)) {
         ldout(sync_env->cct, 0) << "ERROR: failed to get etag from PUT request" << dendl;
         return set_cr_error(-EIO);
       }