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

Wmissing variable declaration #4676

Conversation

andrei-sandor
Copy link
Contributor

@andrei-sandor andrei-sandor commented May 16, 2024

COMP: Fix missing declarations of unused variables.

This is to fix the -Wmissing-variable-declarations warning of clang.

This is simply related that the variable in question is not used in the file


COMP: Fix missing variables declaration (static)

This is a fix about -Wmissing-variable-declarations warning of clang

This is about the static case. A lot of variables were marked as warning due to non declaration. The static keyword was added when it makes sense that the variable is used internally.

@github-actions github-actions bot added area:Examples Demonstration of the use of classes type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:IO Issues affecting the IO module area:Video Issues affecting the Video module area:Numerics Issues affecting the Numerics module labels May 16, 2024
Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

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

You can apply Niels' suggestion if you wish, but the proper formatting has to be followed to satisfy the CI.

@seanm
Copy link
Contributor

seanm commented May 17, 2024

...proper formatting has to be followed to satisfy the CI.

Yeah, we haven't found a way to install old clang-format version 8, so we keep skipping the commit hooks. And newer clang-format makes unrelated changes. There's no magic "Do: reformat" command like with VTK's gitlab?

@dzenanz
Copy link
Member

dzenanz commented May 17, 2024

Normally, ITK builds the correct version of clang-format, and puts it e.g. here: C:\Dev\ITK-vs22\ClangFormat-prefix\src\ClangFormat\clang-format.exe. You should be able to copy that executable into a more suitable location, if you like. But also pre-commit hooks should be using it?

@seanm
Copy link
Contributor

seanm commented May 17, 2024

Normally, ITK builds the correct version of clang-format, and puts it e.g. here: C:\Dev\ITK-vs22\ClangFormat-prefix\src\ClangFormat\clang-format.exe. You should be able to copy that executable into a more suitable location, if you like. But also pre-commit hooks should be using it?

I have ITK_USE_CLANG_FORMAT=ON but I don't find any such thing built. That gets built in the bin directory?, or do you have to make install?

sean@hobgoblin ITK-bin % find . -iname "*clang*"
./KWStyle/Utilities/boost/config/compiler/clang_version.hpp
./KWStyle/Utilities/boost/config/compiler/clang.hpp
./KWStyle/Utilities/boost/predef/compiler/clang.h
./ITKClangFormatConfig.cmake

@dzenanz
Copy link
Member

dzenanz commented May 17, 2024

Here is the output on my Linux build:

dzenan@corista:~/ITK-git-rel$ find . -iname "clang*"
./temp/clang-format-Linux
./Wrapping/Generators/CastXML/castxml/share/castxml/clang
./Wrapping/Generators/CastXML/castxml-prefix/src/castxml/share/castxml/clang
./clang-format-Linux
./ClangFormat-prefix
./ClangFormat-prefix/src/ClangFormat-stamp
./ClangFormat-prefix/src/ClangFormat-stamp/ClangFormat-update
./ClangFormat-prefix/src/ClangFormat-stamp/ClangFormat-download-err.log
./ClangFormat-prefix/src/ClangFormat-stamp/ClangFormat-download-Release-impl.cmake
./ClangFormat-prefix/src/ClangFormat-stamp/ClangFormat-patch
./ClangFormat-prefix/src/ClangFormat-stamp/ClangFormat-mkdir
./ClangFormat-prefix/src/ClangFormat-stamp/ClangFormat-done
./ClangFormat-prefix/src/ClangFormat-stamp/ClangFormat-install
./ClangFormat-prefix/src/ClangFormat-stamp/ClangFormat-download-out.log
./ClangFormat-prefix/src/ClangFormat-stamp/ClangFormat-configure
./ClangFormat-prefix/src/ClangFormat-stamp/ClangFormat-patch-info.txt
./ClangFormat-prefix/src/ClangFormat-stamp/ClangFormat-download
./ClangFormat-prefix/src/ClangFormat-stamp/ClangFormat-build
./ClangFormat-prefix/src/ClangFormat-stamp/ClangFormat-urlinfo.txt
./ClangFormat-prefix/src/ClangFormat-stamp/ClangFormat-update-info.txt
./ClangFormat-prefix/src/ClangFormat-stamp/ClangFormat-download-Release.cmake
./ClangFormat-prefix/src/ClangFormat
./ClangFormat-prefix/src/ClangFormat/clang-format
./ClangFormat-prefix/src/ClangFormat-build
./ClangFormat-prefix/tmp/ClangFormat-cfgcmd.txt
./ClangFormat-prefix/tmp/ClangFormat-mkdirs.cmake
./KWStyle/Utilities/boost/config/compiler/clang.hpp
./KWStyle/Utilities/boost/predef/compiler/clang.h
./CMakeFiles/ClangFormat.dir
./CMakeFiles/ClangFormat-complete
dzenan@corista:~/ITK-git-rel$

@dzenanz
Copy link
Member

dzenanz commented May 17, 2024

Yes, it gets build in the bin directory, under name clang-format-Linux (see above listing). It should be similar for Mac.

@seanm
Copy link
Contributor

seanm commented May 17, 2024

Yes, it gets build in the bin directory, under name clang-format-Linux (see above listing). It should be similar for Mac.

I've just built with VERBOSE=1 make and tried searching for keywords like clang and format but not found any evidence of it trying to build that. Do you have an exact string I might search for to see what's (not) happening?

@dzenanz
Copy link
Member

dzenanz commented May 17, 2024

Target is called ClangFormat, so maybe try make ClangFormat? Here are the relevant entries from my cache:
Screenshot 2024-05-17 16 52 02

@seanm
Copy link
Contributor

seanm commented May 17, 2024

sean@hobgoblin ITK-big-bin % make ClangFormat
make: *** No rule to make target `ClangFormat'.  Stop.

But grepping ClangFormat in the ITK codebase I found this URL: https://data.kitware.com/api/v1/file/5d274e88877dfcc902effc47/download which appears to be the Mac clang-format8 executable! so I just downloaded that, copied it somewhere, did chmod +x and then git config clangFormat.binary /Users/sean/Downloads/clang-format8 and presto the ITK git hooks are now happy!

@github-actions github-actions bot removed the area:IO Issues affecting the IO module label May 21, 2024
@andrei-sandor andrei-sandor force-pushed the WmissingVariableDeclaration branch 3 times, most recently from ece4013 to acb3c5d Compare May 23, 2024 18:49
This is a fix about -Wmissing-variable-declarations warning of clang

This is about the static case. A lot of variables were marked as warning due to non declaration. The namespace blocks of code were added when possible to fix. Otherwise it is static.
This is to fix the -Wmissing-variable-declarations warning of clang.

This is simply related that the variable in question is not used in the file
@@ -194,7 +194,7 @@ class CallRecord
* Static list of CallRecord items representing the stack trace of
* calls to GenerateData and TemporalStreamingGenerateData
*/
std::vector<CallRecord> m_CallStack;
static std::vector<CallRecord> m_CallStack;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's orthogonal to this change, but this m_CallStack appears to be a plain old global variable, not a class instance variable. Should it have the m_ prefix?

Copy link
Member

Choose a reason for hiding this comment

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

I guess it should not.

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the naming convention for plain old global variables then? I don't see the answer here: https://itk.org/Wiki/ITK/Coding_Style_Guide#Naming_Conventions

Copy link
Member

Choose a reason for hiding this comment

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

It should not have the "m_" prefix. It should be included in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this one, I decided to keep it static since the variable that is static is used right after and there is no static to that one. I didn't want to let inside a big namespace to complicate more. Is it okay like this or I should create a large namespace?

Copy link
Member

@hjmjohnson hjmjohnson left a comment

Choose a reason for hiding this comment

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

@andrei-sandor Minor change needed. New static variable should have the m_ removed from the variable name. Will produce a followup PR to remove the m_

@hjmjohnson hjmjohnson merged commit 916e064 into InsightSoftwareConsortium:master May 31, 2024
14 checks passed
@andrei-sandor
Copy link
Contributor Author

@hjmjohnson Yes sure, that's good for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:Core Issues affecting the Core module area:Examples Demonstration of the use of classes area:Filtering Issues affecting the Filtering module area:Numerics Issues affecting the Numerics module area:Video Issues affecting the Video module type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants