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

Improving code efficiency by errors from cppcheck #1369

Closed
wants to merge 14 commits into from
Closed

Improving code efficiency by errors from cppcheck #1369

wants to merge 14 commits into from

Conversation

Surajjalpun2002
Copy link
Contributor

Raising PR for issue #1346

Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

… being used for implicit type conversions

Signed-off-by: Surajjalpun2002 <[email protected]>
@Surajjalpun2002 Surajjalpun2002 changed the title Added explicit keyword infront of the constructor Improving code efficiency by errors from cppcheck Oct 11, 2023
Here the term !valid will always return false hence its useless for the logic

Signed-off-by: Surajjalpun2002 <[email protected]>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also used clang-format on the 2 files.

@github-actions
Copy link
Contributor

Here are the build results
Avogadro2.AppImage
macOS.dmg
Win64.exe
Artifacts will only be retained for 90 days.

@ghutchis
Copy link
Member

I'll take a look at the clang-format check on Thursday.

'd' has been allocated new memory

copied the data from the 'other' object to the newly allocated memory for 'd' pointer

Signed-off-by: Surajjalpun2002 <[email protected]>
'd' has been allocated new memory

copied the data from the 'other' object to the newly allocated memory for 'd' pointer

Signed-off-by: Surajjalpun2002 <[email protected]>
Such, so called 'Converting constructors', should in general be explicit for type safety reasons as that prevents unintended implicit conversions.

Signed-off-by: Surajjalpun2002 <[email protected]>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this commit somehow has message from the previous commit, but changes in it are for the just next commit about removing unused private function

}

/** Copy constructor, note the copy made of the internal data of other. */
Array(const Array& other) : d(new Container(*other.d)) {}
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we don't want to do this. The Array class is copy-on-write. Please remove and/or tell cppcheck to ignore this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@Surajjalpun2002
Copy link
Contributor Author

Any tips?

@ghutchis
Copy link
Member

If you click "details" on any of the tests, you should be able to see the build report:

/Users/runner/actions-runner/_work/avogadrolibs/avogadrolibs/avogadrolibs/avogadro/core/variant.h:133:3: error: expected member name or ';' after declaration specifiers
  private : Type m_type;
  ^

(Then lots more errors)

@ghutchis
Copy link
Member

Please, let's stick to small changes. I'd rather have multiple PR with individual small changes and merge them, then have you keep pushing to this one. I don't know when you're "done" so I can review and give comments and test. (Beyond the unit tests, it's important to do functional testing because small changes can still yield big changes, e.g. in Array)

Signed-off-by: Surajjalpun2002 <[email protected]>
@Surajjalpun2002
Copy link
Contributor Author

Surajjalpun2002 commented Oct 13, 2023

image
should we do something about these?

@Surajjalpun2002
Copy link
Contributor Author

Surajjalpun2002 commented Oct 14, 2023

Should i close this PR as well and open a new one, as most of the changes ive made have been causing errors and i believe there is only one small commit thats reasonable in this whole pr. I hope not be anymore of a hassle for you.

@ghutchis
Copy link
Member

You're certainly not a hassle, but definitely submitting small changes as separate PR for testing would be appreciated.

Understand that cppcheck and other static analyzers are not perfect. They flag plenty of false positives. They do also offer useful suggestions.

For example the cube.cpp issues you note above are probably useful to fix.

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.

2 participants