Skip to content

Cpp check redundant assignment#11441

Open
dareumnam wants to merge 10 commits intodevelopfrom
cppCheck_redundantAssignment
Open

Cpp check redundant assignment#11441
dareumnam wants to merge 10 commits intodevelopfrom
cppCheck_redundantAssignment

Conversation

@dareumnam
Copy link
Collaborator

Pull request overview

  • Fix cppcheck redundantAssignment warnings
  • Removed redundant assignments when their values were reassigned before the old one has been used.
  • Added comments where I made changes beyond simply removing redundant assignments

Description of the purpose of this PR

Pull Request Author

  • Title of PR should be user-synopsis style (clearly understandable in a standalone changelog context)
  • Label the PR with at least one of: Defect, Refactoring, NewFeature, Performance, and/or DoNoPublish
  • Pull requests that impact EnergyPlus code must also include unit tests to cover enhancement or defect repair
  • Author should provide a "walkthrough" of relevant code changes using a GitHub code review comment process
  • If any diffs are expected, author must demonstrate they are justified using plots and descriptions
  • If changes fix a defect, the fix should be demonstrated in plots and descriptions
  • If any defect files are updated to a more recent version, upload new versions here or on DevSupport
  • If IDD requires transition, transition source, rules, ExpandObjects, and IDFs must be updated, and add IDDChange label
  • If structural output changes, add to output rules file and add OutputChange label
  • If adding/removing any LaTeX docs or figures, update that document's CMakeLists file dependencies
  • If adding/removing any output files (e.g., eplustbl.*)
    • Update ..\scripts\Epl-run.bat
    • Update ..\scripts\RunEPlus.bat
    • Update ..\src\EPLaunch\ MainModule.bas, epl-ui.frm, and epl.vbp (VersionComments)
    • Update ...github\workflows\energyplus.py

Reviewer

  • Perform a Code Review on GitHub
  • If branch is behind develop, merge develop and build locally to check for side effects of the merge
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified
  • Check that performance is not impacted (CI Linux results include performance check)
  • Run Unit Test(s) locally
  • Check any new function arguments for performance impacts
  • Verify IDF naming conventions and styles, memos and notes and defaults
  • If new idf included, locally check the err file and other outputs

@dareumnam dareumnam added the DoNotPublish Includes changes that shouldn't be reported in the changelog label Feb 27, 2026
} else {
S1PLR = 0.0;
}

Copy link
Collaborator Author

@dareumnam dareumnam Feb 27, 2026

Choose a reason for hiding this comment

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

S1PLR gets set right after the stage-1 full-load calc, but that value is never used before S1PLR is recomputed in the “Determine run-time fractions” block, line 545 - 550 (develop). We can just drop the first S1PLR = PartLoadRatio or 0.0 assignment (no behavior change, since it was overwritten before use).


// Stage 1
} else if (CycRatio > 0.0 || (CycRatio > 0.0 && SingleMode == 1)) {
} else if (CycRatio > 0.0 || (CycRatio > 0.0 && SingleMode == 1)) { // cppCheck Redundant Condition flag
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If the intent was to include SingleMode in the logic, this might need to be CycRatio > 0.0 || SingleMode == 1 or CycRatio > 0.0 && SingleMode == 1; otherwise it can be simplified to CycRatio > 0.0.

Copy link
Collaborator

Choose a reason for hiding this comment

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

SingleMode (1 = Yes, 0 = No) does operate just like a cycling coil except that at speeds > 1 the cycling is between capacity at speed = x and off. There are other logic conditionals like this in code and I think testing would be required to know for sure but your suggestion of CycRatio > 0.0 may be correct since line 14070 says "Stage 1" and at stage 1 it wouldn't matter what SingleMode was.

    if (SpeedNum > 1 && SingleMode == 0) {
    } else if (CycRatio > 0.0) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rraustad Thanks for your input and for confirming the fix.

lineIn = statFile.readLine();
}
lineIn = statFile.readLine();
lineAvg = lineIn.data;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The last lineIn = readLine() inside the 7-line skip loop is immediately overwritten by the next readLine() before it’s ever used. Easiest fix is to discard the skipped lines without assigning to lineIn, then read the actual avg line once into lineAvg.

}

// no unshaded run for now
NeedUnshadedRun = false;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NeedUnshadedRun is possibly set true a few lines before, but then immediately forced to false before it’s ever used, so the earlier assignments are dead. Either drop the unconditional NeedUnshadedRun = false; (to keep the logic), or remove the previous NeedUnshadedRun = true lines would be the fix. As the comment said "no unshaded run for now", I left NeedUnshadedRun = false and erased two NeedUnshadedRun = true lines.

// Get Water System tank connections
// A8, \field Name of Water Storage Tank for Supply
cFieldName = "Supply Water Storage Tank Name"; // cAlphaFields(8)
// cFieldName = "Supply Water Storage Tank Name"; // cAlphaFields(8)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I avoided re-declaring cFieldName in inner scopes (like in the previous commit) since that caused a mac build issue. Instead, I commented out the two cFieldName assignments that were never used before being overwritten.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed. This is fine to leave like this for reference.

lineIn = statFile.readLine();
lineAvg = lineIn.data;
auto lineAvgIn = statFile.readLine();
lineAvg = lineAvgIn.data;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The last lineIn = statFile.readLine(); inside the 7-line skip loop is immediately overwritten by the next readLine() before it’s ever used. Easiest fix is to discard the skipped lines without assigning to lineIn, then read the actual avg line once into lineAvg.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe the intent of this was just to cycle through until they have read enough lines to get to the one they do want. I'll push a tiny cleanup here.


cFieldName = "Condenser Type"; // cAlphaFields(6)
std::string const condenserType = s_ip->getAlphaFieldValue(fields, schemaProps, "condenser_type");
if ((Util::SameString(condenserType, "AirCooled")) || cFieldName.empty()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I also spotted what looks like a bug in this line:
|| cFieldName.empty() in the Condenser Type check probably meant condenserType.empty() I guess, as cFieldName has always have a value due to line 842 (2 lines above).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, this does look like a bug. Feel free to submit an issue and PR separately.

// get current total capacity, SHR, EIR
if (SpeedRatio >= 1.0) {
TotCap = TotCapHS;
SHR = SHRHS;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cppcheck is flagging SHR here because it gets assigned in the SpeedRatio >= 1.0 path, then reassigned again later in the UserSHRCurveExists block before the earlier value is actually used. This looks more like a redundant intermediate assignment than a functional issue.
In if (thisDXCoil.UserSHRCurveExists) - else block (line 11817 in this branch), SHR is assigned on all paths, so the warning is about this SHR assignment here being overwritten before use.

@mitchute mitchute marked this pull request as ready for review March 10, 2026 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DoNotPublish Includes changes that shouldn't be reported in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants