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

Bump cppcheck from 2.3 to 2.9 #570

Merged
merged 18 commits into from
Nov 24, 2022
Merged

Bump cppcheck from 2.3 to 2.9 #570

merged 18 commits into from
Nov 24, 2022

Conversation

jmarrec
Copy link
Collaborator

@jmarrec jmarrec commented Oct 18, 2022

No description provided.

@macumber
Copy link
Collaborator

Any idea why the cppcheck build started failing?

@macumber
Copy link
Collaborator

Want some help getting this to pass?

@jmarrec
Copy link
Collaborator Author

jmarrec commented Nov 22, 2022

@macumber Only one type of warning left, the virtualCallInConstructor one. What do we do about this one?

src/model_editor/InspectorGadget.hpp:274]:(style),[virtualCallInConstructor],
Virtual function 'layoutItems' is called from constructor
'InspectorGadget(openstudio::WorkspaceObject&workspaceObj,int indent,ComboHighlightBridge*bridge,bool showComments,bool showAllFields,bool recursive,bool locked)' at line 158. 
Dynamic binding is not used.

@macumber
Copy link
Collaborator

Can we just make InspectorGadget::layoutItems non-virtual? It doesn't look like it is overridden anywhere.

@jmarrec
Copy link
Collaborator Author

jmarrec commented Nov 22, 2022

layoutItems

In this specific case it's fine. This wasn't perhaps the best of examples, the most common one is "setCategoriesAndFields", which is in the base class OSGridController and all derives classes override it and call it from the ctor.

// This function determines the category for
// each button, and the fields associated with
// each category
virtual void setCategoriesAndFields();

SpacesShadingGridController::SpacesShadingGridController(bool isIP, const QString& headerText, IddObjectType iddObjectType, const model::Model& model,
const std::vector<model::ModelObject>& modelObjects)
: OSGridController(isIP, headerText, iddObjectType, model, modelObjects) {
setCategoriesAndFields();
}
void SpacesShadingGridController::setCategoriesAndFields() {
{
std::vector<QString> fields;
fields.push_back(SHADEDSURFACENAME);
fields.push_back(SHADINGSURFACEGROUP);
fields.push_back(CONSTRUCTION);
fields.push_back(TRANSMITTANCESCHEDULE);
//fields.push_back(DAYLIGHTINGSHELFNAME);
std::pair<QString, std::vector<QString>> categoryAndFields = std::make_pair(QString("General"), fields);
addCategoryAndFields(categoryAndFields);
}
OSGridController::setCategoriesAndFields();
}

The clean way would maybe be to have a private setCategoriesAndFieldInternal method that isn't virtual and that's the one both the Ctor and the setCategoriesAndFields would call. But that's an annoying code change

@macumber
Copy link
Collaborator

Ok I see, well IMHO this is an important check so we should probably try to fix these issues. If you want, I can do the remaining changes.

@jmarrec
Copy link
Collaborator Author

jmarrec commented Nov 22, 2022

I guess setCategoriesAndFields isn't a virtual method per se actually.

  • The child setCategoriesAndFields explicitly calls the base OSGridController::setCategoriesAndFields
  • I don't see anywhere setCategoriesAndFields being called from an OSGridController base (but could be wrong)

```python
from pathlib import Path
import re

ROOT_DIR = Path('.').resolve().parent

cpp_files = list(Path(ROOT_DIR / 'src').glob('**/*.cpp'))

for cpp_file in cpp_files:
    replacement_done = False
    
    with open(cpp_file, 'r') as f:
        content = f.read()
    lines = content.splitlines()

    new_lines = []
    in_block = False
    for i, line in enumerate(lines):
        if 'std::vector<QString> fields;' in line:
            replacement_done = True
            in_block = True
            new_lines.append('    std::vector<QString> fields{')
        elif not in_block:
            new_lines.append(line)
        elif 'fields.push_back' in line:
            new_lines.append(line.replace('fields.push_back(', '').replace(');', ','))
        else:
            new_lines.append('    };')
            new_lines.append(line)
            in_block = False
    if not replacement_done:
        continue
    with open(cpp_file, 'w') as f:
        f.write("\n".join(new_lines) + '\n')
```
@jmarrec
Copy link
Collaborator Author

jmarrec commented Nov 22, 2022

@macumber I cleaned up the rest of the cppcheck warnings... I suppose I could have "unvirtualized" a few more functions, but I was getting pretty annoyed by the end. If you could spot check the last commits and do a quick UI test session that'd be great

@macumber
Copy link
Collaborator

Sounds good, will do!

@macumber
Copy link
Collaborator

macumber commented Nov 23, 2022

There seems to be a crash when going to the schedule tab, I'll get a debug build of your branch going and see if I can find it.

I can look later but here is the call stack for the crash. To reproduce, load the example model and then go to the schedules tab.

openstudiolib.dll!std::_Ref_count_base::_Incref() Line 1100	C++
openstudiolib.dll!std::_Ptr_base<openstudio::detail::IdfObject_Impl>::_Incref() Line 1335	C++
openstudiolib.dll!std::_Ptr_base<openstudio::detail::IdfObject_Impl>::_Copy_construct_from<openstudio::detail::IdfObject_Impl>(const std::shared_ptr<openstudio::detail::IdfObject_Impl> & _Other) Line 1293	C++
openstudiolib.dll!std::shared_ptr<openstudio::detail::IdfObject_Impl>::shared_ptr<openstudio::detail::IdfObject_Impl>(const std::shared_ptr<openstudio::detail::IdfObject_Impl> & _Other) Line 1575	C++
openstudiolib.dll!openstudio::IdfObject::IdfObject(const openstudio::IdfObject & other) Line 2031	C++
openstudiolib.dll!openstudio::WorkspaceObject::WorkspaceObject(const openstudio::WorkspaceObject & __that)	C++
openstudiolib.dll!openstudio::model::ModelObject::ModelObject(const openstudio::model::ModelObject & __that)	C++
openstudiolib.dll!openstudio::model::ParentObject::ParentObject(const openstudio::model::ParentObject & __that)	C++
openstudiolib.dll!openstudio::model::ResourceObject::ResourceObject(const openstudio::model::ResourceObject & __that)	C++
openstudiolib.dll!openstudio::model::ScheduleBase::ScheduleBase(const openstudio::model::ScheduleBase & __that)	C++
openstudiolib.dll!openstudio::model::Schedule::Schedule(const openstudio::model::Schedule & __that)	C++
openstudiolib.dll!openstudio::model::ScheduleRuleset::ScheduleRuleset(const openstudio::model::ScheduleRuleset & __that)	C++
**OpenStudioApp.exe!openstudio::ScheduleTab::schedule() Line 670	C++**
OpenStudioApp.exe!openstudio::ScheduleTabHeader::ScheduleTabHeader(openstudio::ScheduleTab * scheduleTab, QWidget * parent) Line 783	C++
OpenStudioApp.exe!openstudio::ScheduleTab::ScheduleTab(const openstudio::model::ScheduleRuleset & schedule, openstudio::SchedulesView * schedulesView, QWidget * parent) Line 613	C++
OpenStudioApp.exe!openstudio::SchedulesView::addSchedule(const openstudio::model::ScheduleRuleset & schedule) Line 250	C++
OpenStudioApp.exe!openstudio::SchedulesView::SchedulesView(bool isIP, const openstudio::model::Model & model) Line 189	C++
OpenStudioApp.exe!openstudio::SchedulesTabController::setSubTab(int index) Line 469	C++

@@ -613,14 +610,15 @@ ScheduleTab::ScheduleTab(const model::ScheduleRuleset& schedule, SchedulesView*
: QWidget(parent),
//m_mouseDown(false),
m_selected(false),
m_header(new ScheduleTabHeader(this)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

@jmarrec there is an issue here because ScheduleTabHeader::ScheduleTabHeader tries to call SchedulesView::schedule before m_schedule is set. I fixed that but hit another error. I think some of these changes to move construction from ctor body to initializer list might not be ok in this file at least.

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 was just running the same inside LLDB right now, came up to the same conclusion about the order of members being initialized, and the fact that the ScheduleTabHeader ctor takes this

@macumber macumber merged commit 2d19d49 into develop Nov 24, 2022
@macumber macumber deleted the cppcheck_bump branch November 24, 2022 16:11
@github-actions github-actions bot locked and limited conversation to collaborators Nov 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants