Skip to content

SCTErrMonAlg: unused RAII lock_guard

Christos Anastopoulos requested to merge ATLAS-EGamma/athena:SCTMon_RAII into master

Hey,

I picked this up due to !31749 (merged)

but prb this is a pre-existing issue @oda ?

More or less this is kind of a known bugprone situation for RAII types

Running clang-tidy https://clang.llvm.org/extra/clang-tidy/checks/bugprone-unused-raii.html

does this fix

+++ b/InnerDetector/InDetMonitoring/SCT_Monitoring/src/SCTErrMonAlg.cxx
@@ -72,7 +72,7 @@ StatusCode SCTErrMonAlg::fillHistograms(const EventContext& ctx) const {
 
   // The numbers of disabled modules, links, strips do not change during a run.
   if (m_isFirstConfigurationDetails) {
-    lock_guard{m_mutex};
+    lock_guard give_me_a_name{m_mutex};
     if (m_isFirstConfigurationDetails) {
       ATH_CHECK(fillConfigurationDetails(ctx));
       m_isFirstConfigurationDetails = false;

And then just put glock for give_me_a_name ...

Anyhow without a name the subsequent statement happens after the lock has been destructed which I assume is not what you want as then why have a lock guard guarding nothing.

silly example https://godbolt.org/z/XAvLzK

Edited by Christos Anastopoulos

Merge request reports