Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StBTofCalibMaker: fix variable shadowing #273

Merged
merged 1 commit into from
Jan 7, 2022

Conversation

veprbl
Copy link
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
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