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

Cppcheck 1.81 warnings #102

Closed
edmundvermeulen opened this issue Nov 24, 2017 · 5 comments
Closed

Cppcheck 1.81 warnings #102

edmundvermeulen opened this issue Nov 24, 2017 · 5 comments

Comments

@edmundvermeulen
Copy link

edmundvermeulen commented Nov 24, 2017

Description

Cppcheck 1.81 reports a bunch of issues. We can't really start using doctest until at least the red (error and warning) Cppcheck warnings have been fixed.

[doctest.h:1913]: (warning) Member variable 'ContextBuilder::stackChunks' is not initialized in the constructor.
[doctest.h:691]: (style) Class 'String' has a constructor with 1 argument that is not explicit.
[doctest.h:807]: (style) Struct 'any_t' has a constructor with 1 argument that is not explicit.
[doctest.h:1508]: (style) Struct 'ExpressionDecomposer' has a constructor with 1 argument that is not explicit.
[doctest.h:2013]: (style) Struct 'test_suite' has a constructor with 1 argument that is not explicit.
[doctest.h:2022]: (style) Struct 'description' has a constructor with 1 argument that is not explicit.
[doctest.h:2031]: (style) Struct 'skip' has a constructor with 1 argument that is not explicit.
[doctest.h:2040]: (style) Struct 'timeout' has a constructor with 1 argument that is not explicit.
[doctest.h:2049]: (style) Struct 'may_fail' has a constructor with 1 argument that is not explicit.
[doctest.h:2058]: (style) Struct 'should_fail' has a constructor with 1 argument that is not explicit.
[doctest.h:2067]: (style) Struct 'expected_failures' has a constructor with 1 argument that is not explicit.
[doctest.h:1757]: (style) Exception should be caught by reference.
[doctest.h:1123]: (performance) Function parameter 'value' should be passed by reference.
[doctest.h:5241]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.
[doctest.h:3487]: (warning) Member variable 'ContextState::rand_seed' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::first' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::last' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::abort_after' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::subcase_filter_levels' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::case_sensitive' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::exit' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::duration' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::no_exitcode' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::no_run' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::no_version' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::no_colors' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::force_colors' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::no_breaks' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::no_skip' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::no_path_in_filenames' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::no_line_numbers' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::no_skipped_summary' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::help' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::version' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::count' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::list_test_cases' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::list_test_suites' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::currentTest' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::hasLoggedCurrentTestStart' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::numAssertionsForCurrentTestcase' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::hasCurrentTestFailed' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::subcasesCurrentLevel' is not initialized in the constructor.
[doctest.h:3487]: (warning) Member variable 'ContextState::subcasesHasSkipped' is not initialized in the constructor.
[doctest.h:2095]: (style) class 'Context' does not have a copy constructor which is recommended since the class contains a pointer to allocated memory.
[doctest.h:1296]: (warning) The struct 'Subcase' has 'copy constructor' but lack of 'operator='.

Extra information

  • doctest version: 1.2.6
@onqtam
Copy link
Member

onqtam commented Nov 24, 2017

Hi there!

So doctest is clean from compiler warnings, but for static code analysis tools - thats much trickier...

here are the suppression flags I use on the CI for cppcheck - but different versions of the tool produce different output (and sometimes complains about an unknown suppression flag). Also there are bugs in some versions - like a suppression flag/comment not working... It would be a huge task to make doctest clean for most versions of most static code analysis tools - I've integrated 4-5 tools just to catch bugs in doctest but it was never a goal for the project to be 100% clean for users using static code analysis tools - only for compiler warnings.

Also sometimes inline suppressions in the code like // cppcheck-suppress unusedStructMember don't work - no matter on which line I put them (so I suppress them globally from the command line...) - or work on some versions of the tool...

My advice would be to try to silence all cppcheck warnings for the header - it should be possible to exclude headers/folders (with any tool).

I'll think about this... If it is a big pain for users - I might think of something, so I'm keeping this open

@edmundvermeulen
Copy link
Author

This one is definitely a bug:

[doctest.h:5241]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.

onqtam added a commit that referenced this issue Nov 26, 2017
@onqtam
Copy link
Member

onqtam commented Nov 26, 2017

true - fixed it in the dev branch. Anyway I'll be moving to streams (away from format specifiers) in a future internal refactoring

@edmundvermeulen
Copy link
Author

Our code base cannot have any red Cppcheck warnings, so that is no-go. Luckily, I was able to easily fix the warnings. By the way, Catch2 does not give any Cppcheck warnings.

@onqtam
Copy link
Member

onqtam commented Feb 6, 2018

I'll be pushing the fix for the format specifier to master soon so I'm closing this. I will look into suppressions again for static code analysis in the future...

@onqtam onqtam closed this as completed Feb 6, 2018
onqtam added a commit that referenced this issue Feb 6, 2018
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

No branches or pull requests

2 participants