Fix #15080 FP uninitMemberVarNoCtor for const and reference members - #8910
Open
autoantwort wants to merge 1 commit into
Open
autoantwort wants to merge 1 commit into
autoantwort wants to merge 1 commit into
Conversation
A class without constructor whose non-static const or reference member has no default member initializer is not default constructible (or, for a const class type with a default constructor, default constructs it), so the member can never be left uninitialized. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| if (var.typeScope() && var.typeScope()->numConstructors > 0) | ||
| continue; | ||
|
|
||
| // const and reference members without default initializer must be initialized by every instance |
Collaborator
There was a problem hiding this comment.
This check should be done in the loop above (see hasAnyDefaultInit etc.). A const/ref member should inhibit warnings for any other members as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://trac.cppcheck.net/ticket/15080
gives
Member variable 'S::it' has no initializer. [uninitMemberVarNoCtor], andstruct S { int a = 0; const int b; int& c; };warns forbandc.A non-static const or reference member without default member initializer can't stay uninitialized: for trivial types the implicit default constructor is deleted, so every instance must initialize it, and a const class type is default-constructed. These members are now skipped by the no-constructor check.
Since f90a76f (#15072) this also shows up for class templates whose member type is a
usingalias.This PR was created by Claude Code (an AI coding agent) on behalf of @autoantwort.
🤖 Generated with Claude Code