Skip to content

Resolve cppcheck unreadVariable warnings#11411

Draft
dareumnam wants to merge 4 commits intodevelopfrom
cppcheckStyleErrors
Draft

Resolve cppcheck unreadVariable warnings#11411
dareumnam wants to merge 4 commits intodevelopfrom
cppcheckStyleErrors

Conversation

@dareumnam
Copy link
Collaborator

Pull request overview

  • Fix cppcheck unreadVariable warnings
  • Removed unused variables when their values were never referenced
  • Added comments where I made changes beyond simply removing unused variables

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 6, 2026
{

std::array<Real64, DataConvergParams::ConvergLogStackDepth> tmpRealARR = {};
std::array<Real64, DataConvergParams::ConvergLogStackDepth> tmpRealARR;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove the zero-initialization of tmpRealARR. It is always overwritten before being read, so the initialization was redundant and triggered a cppcheck warning.

} else if (field_value.get<std::string>().empty()) {
isDefaulted = findDefault(defaultValue, schema_field_obj);
if (isDefaulted) {
if (findDefault(defaultValue, schema_field_obj)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove the temporary isDefaulted variable and use findDefault() directly in the condition to remove cppcheck error as it was redundant and only stored an intermediate result.

auto epwFile = state.files.inputWeatherFilePath.open(state, "CalcThermalComfortAdaptiveASH55");
for (i = 1; i <= 8; ++i) { // Headers
epwLine = epwFile.readLine().data;
epwFile.readLine();
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 updated the code to call readLine() without assigning the result to epwLine, since the code stored each skipped line into epwLine and immediately overwrote it in the next iteration without ever reading it. This removes the dead assignments flagged by cppcheck and makes the intent clearer, with no change in behavior. I made the same change below.

ExpandComplexState(state, iSurf, state.dataSurface->Surface(iSurf).Construction);
CurrentCFSState = state.dataSurface->SurfaceWindow(iSurf).ComplexFen.NumStates;
state.dataSurface->SurfaceWindow(iSurf).ComplexFen.CurrentState = CurrentCFSState;
state.dataSurface->SurfaceWindow(iSurf).ComplexFen.CurrentState = state.dataSurface->SurfaceWindow(iSurf).ComplexFen.NumStates;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Drop the redundant CurrentCFSState local and write directly to ComplexFen.CurrentState. The cached value wasn’t needed and cppcheck flagged it as unreadVariable. No behavior change.


ngllayer = state.dataConstruction->Construct(ConstrNum).TotGlassLayers;
nglface = 2 * ngllayer;
nglfacep = nglface;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Dropped this initialization as it gets overwritten before being read, so cppcheck flags it as unreadVariable. No behavior change.

A(3, 3) = 1.0;
A(4, 3) = -1.0 * rhodb;
A(3, 4) = -1.0 * rhom;
// cppcheck-suppress unreadVariable
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 false positive: this routine fills A as an output matrix, so the last assignment A(4,4)=1.0 isn’t unused in practice. Added a local suppress to keep the intent clear.

}
}
}
CFSLAYERFlag = LOK && DOK && BOK;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Dropped unused CFSLAYERFlag as it was computed but never read.

TGapNew(1) =
TAve(1) - (TAve(1) - TAve(2)) * (GapHeightChar(1) / GapHeight) * (1 - EpsChar(1)) * (1 - EpsChar(2)) / (1 - EpsChar(1) * EpsChar(2));

// cppcheck-suppress unreadVariable
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 false positive: TGapNew is an output array; TGapNew(2) is set here for the caller.

Real64 BlindIRreflBack = G(2) * (1.0 - fEdge) + fEdge * ri; // Blind back IR reflectance

// Back IR emissivity
// cppcheck-suppress unreadVariable
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 false positive: p is an output array and p(15) is set here for the caller.

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

⚠️ Regressions detected on ubuntu-24.04 for commit 0243091

Regression Summary
  • ERR: 14
  • PERF_LOG: 1

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.

2 participants