Skip to content

StBTofCalibMaker: fix variable shadowing#273

Merged
veprbl merged 1 commit intostar-bnl:mainfrom
veprbl:pr/btofcalibmaker_dopid_shadow
Jan 7, 2022
Merged

StBTofCalibMaker: fix variable shadowing#273
veprbl merged 1 commit intostar-bnl:mainfrom
veprbl:pr/btofcalibmaker_dopid_shadow

Conversation

@veprbl
Copy link
Copy Markdown
Member

@veprbl veprbl commented Jan 5, 2022

The code in question looks like this:

    int doPID = 0;
    for(;;) {
       // ...
       Bool_t doPID = kFALSE;
       // ...
       if(!doPID) continue;
       doPID++;
    }
    LOG_INFO << doPID << endm;

The doPID variable from the outer scope gets shadowed by the boolean flag variable. That should make it always report 0.

This was found with a following compiler diagnostic:

.sl79_gcc485/obj/StRoot/StBTofCalibMaker/StBTofCalibMaker.cxx: In member function 'void StBTofCalibMaker::processStEvent()':
.sl79_gcc485/obj/StRoot/StBTofCalibMaker/StBTofCalibMaker.cxx:1241:14: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
 1241 |         doPID++;
      |              ^~
.sl79_gcc485/obj/StRoot/StBTofCalibMaker/StBTofCalibMaker.cxx: In member function 'void StBTofCalibMaker::processMuDst()':
.sl79_gcc485/obj/StRoot/StBTofCalibMaker/StBTofCalibMaker.cxx:1496:18: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
 1496 |             doPID++;
      |                  ^~

The code in question looks like this:

    int doPID = 0;
    for(;;) {
       // ...
       Bool_t doPID = kFALSE;
       // ...
       if(!doPID) continue;
       doPID++;
    }
    LOG_INFO << doPID << endm;

The doPID variable from the outer scope gets shadowed by the boolean flag variable. That should make it always report 0.

This was found with a following compiler diagnostic:

    .sl79_gcc485/obj/StRoot/StBTofCalibMaker/StBTofCalibMaker.cxx: In member function 'void StBTofCalibMaker::processStEvent()':
    .sl79_gcc485/obj/StRoot/StBTofCalibMaker/StBTofCalibMaker.cxx:1241:14: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
     1241 |         doPID++;
          |              ^~
    .sl79_gcc485/obj/StRoot/StBTofCalibMaker/StBTofCalibMaker.cxx: In member function 'void StBTofCalibMaker::processMuDst()':
    .sl79_gcc485/obj/StRoot/StBTofCalibMaker/StBTofCalibMaker.cxx:1496:18: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
     1496 |             doPID++;
          |                  ^~
Copy link
Copy Markdown
Member

@fgeurts fgeurts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good catch. Recent code updates introduced a counter that had the exact same name as a boolean flag that was used inside a loop. The good news is that this shadowing did not have any detrimental to the calibrations as the counter was only used for logging purposes and the boolean "reset" happened inside the loop for each individual track - as originally intended.

@veprbl veprbl merged commit 99b7bd9 into star-bnl:main Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants