Skip to content

COMP: Use value initialization to zero-initialize thread id variable#5419

Merged
jhlegarreta merged 1 commit intoInsightSoftwareConsortium:masterfrom
jhlegarreta:FixPtrConstantWarning
Jun 19, 2025
Merged

COMP: Use value initialization to zero-initialize thread id variable#5419
jhlegarreta merged 1 commit intoInsightSoftwareConsortium:masterfrom
jhlegarreta:FixPtrConstantWarning

Conversation

@jhlegarreta
Copy link
Member

@jhlegarreta jhlegarreta commented Jun 18, 2025

Use value initialization to zero-initialize thread id variable.

Fixes:

In file included from
 Core/Common/src/itkPlatformMultiThreader.cxx:35:
[CTest: warning matched]
 Core/Common/src/itkPlatformMultiThreaderPosix.cxx:172:28:
 warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
  172 |   pthread_t threadHandle = 0;
      |                            ^
      |                            nullptr
[CTest: warning suppressed] 1 warning generated.

raised for example in:
https://open.cdash.org/viewBuildError.php?type=1&buildid=10477917

and

ITK/Modules/Core/Common/include/itkThreadSupport.h:45:55:
 warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
   45 | constexpr ThreadProcessIdType ITK_DEFAULT_THREAD_ID = 0;
      |                                                       ^
      |                                                       nullptr

reported by a local build.

PR Checklist

This comment was marked as outdated.

@github-actions github-actions bot added type:Compiler Compiler support or related warnings area:Core Issues affecting the Core module labels Jun 18, 2025
@jhlegarreta jhlegarreta force-pushed the FixPtrConstantWarning branch 2 times, most recently from 61ae052 to 8d9bfb1 Compare June 19, 2025 00:17
@jhlegarreta jhlegarreta changed the title COMP: Prefer nullptr over zero for pointer initialization COMP: Explicitly cast zero value for thread id variable initialization Jun 19, 2025
@jhlegarreta jhlegarreta requested a review from Copilot June 19, 2025 00:18

This comment was marked as outdated.

@jhlegarreta jhlegarreta force-pushed the FixPtrConstantWarning branch from 8d9bfb1 to 51eded9 Compare June 19, 2025 00:20
@jhlegarreta jhlegarreta changed the title COMP: Explicitly cast zero value for thread id variable initialization COMP: Use value initialization to zero-initialize thread id variable Jun 19, 2025
@jhlegarreta jhlegarreta requested a review from Copilot June 19, 2025 00:21

This comment was marked as outdated.

Copy link
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

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

💯

@jhlegarreta jhlegarreta force-pushed the FixPtrConstantWarning branch from 51eded9 to 546c8fb Compare June 19, 2025 13:13
@jhlegarreta
Copy link
Member Author

Sorry, forgot to force push yesterday.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request addresses a warning triggered by the use of an integer literal for initializing a thread identifier by switching to value initialization.

  • Replace "pthread_t threadHandle = 0;" with "pthread_t threadHandle = {};" to zero-initialize the thread id variable and eliminate the warning.

@seanm
Copy link
Contributor

seanm commented Jun 19, 2025

IIRC pthread_t is not a pointer on all platforms, I remember fixing this myself once, then having to back out of it...

I have a branch where I started on #3136 which would fix the issue in a different way.

@jhlegarreta
Copy link
Member Author

@seanm thanks for this additional information; until your fixes land in the code base, can you please try building locally with this patch set? If the warning goes away, I would prefer to have this merged to lower the noise from the dashboard.

@seanm
Copy link
Contributor

seanm commented Jun 19, 2025

I've finally caught up on all my ITK github emails, and see only now that you changed this to not use nullptr. This new way is probably fine.

IIRC this was the last -Wzero-as-null-pointer-constant in ITK!

@seanm
Copy link
Contributor

seanm commented Jun 19, 2025

Tried locally, I see just one more (though of course I did not build every possible module or permutation):

ITK/Modules/Core/Common/include/itkThreadSupport.h:45:55: warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
   45 | constexpr ThreadProcessIdType ITK_DEFAULT_THREAD_ID = 0;
      |                                                       ^
      |                                                       nullptr

Want to amend this PR to fix that one too?

Use value initialization to zero-initialize thread id variable.

Fixes:
```
In file included from
 Core/Common/src/itkPlatformMultiThreader.cxx:35:
[CTest: warning matched]
 Core/Common/src/itkPlatformMultiThreaderPosix.cxx:172:28:
 warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
  172 |   pthread_t threadHandle = 0;
      |                            ^
      |                            nullptr
[CTest: warning suppressed] 1 warning generated.
```

raised for example in:
https://open.cdash.org/viewBuildError.php?type=1&buildid=10477917

and
```
ITK/Modules/Core/Common/include/itkThreadSupport.h:45:55:
 warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
   45 | constexpr ThreadProcessIdType ITK_DEFAULT_THREAD_ID = 0;
      |                                                       ^
      |                                                       nullptr
```

reported by a local build.
@jhlegarreta jhlegarreta force-pushed the FixPtrConstantWarning branch from 546c8fb to fa1a33e Compare June 19, 2025 15:00
@jhlegarreta
Copy link
Member Author

Re: #5419 (comment) commit amended, force pushed. Thanks for having tried this @seanm.

@jhlegarreta jhlegarreta reopened this Jun 19, 2025
@hjmjohnson
Copy link
Member

IIRC pthread_t is not a pointer on all platforms, I remember fixing this myself once, then having to back out of it...

I have a branch where I started on #3136 which would fix the issue in a different way.

I have the same recollection. I've had to back out that change in the past as well.

It would be great to have the proper #ifdef initializaitons for when it is needed to be 0 and when it should be nullptr.

@jhlegarreta
Copy link
Member Author

/azp run ITK.Windows

@jhlegarreta jhlegarreta merged commit f20640e into InsightSoftwareConsortium:master Jun 19, 2025
20 of 24 checks passed
@jhlegarreta jhlegarreta deleted the FixPtrConstantWarning branch June 19, 2025 20:47
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 type:Compiler Compiler support or related warnings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants