Repository navigation
[liveness] do not report objects kept for the side effects of their constructor - #2314
Open
VladimirMakaev wants to merge 1 commit into
Open
VladimirMakaev wants to merge 1 commit into
VladimirMakaev wants to merge 1 commit into
Conversation
…onstructor
A local that is only constructed was always reported as a dead store, even when its constructor
has effects outside the object.
void register_object();
struct Registrar {
Registrar() { register_object(); }
};
int f(int x) {
Registrar r; // DEAD_STORE reported before, but constructing r is the point
return x * 2;
}
Report such a local only when its constructor writes nothing but the object and its own locals,
following calls to other constructors up to three levels deep. A constructor without a body is
assumed to have side effects unless it is compiler-generated. Copies and moves, from an object of
the same class passed by reference, are still reported whatever their constructor does.
Limitations: a constructor calling a function other than a constructor is assumed to have side
effects.
## Test plan
New `_ok`, `_bad` and `FN_` tests in `cpp/liveness/dead_stores.cpp`; the existing expectations do
not change.
VladimirMakaev
force-pushed
the
liveness-constructor-side-effects
branch
from
November 20, 2026 16:23
ee2dafe to
def33a7
Compare
This branch has not been deployed
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.
A local that is only constructed was always reported as a dead store, even when its constructor
has effects outside the object.
Report such a local only when its constructor writes nothing but the object and its own locals,
following calls to other constructors up to three levels deep. A constructor without a body is
assumed to have side effects unless it is compiler-generated. Copies and moves, from an object of
the same class passed by reference, are still reported whatever their constructor does.
Limitations: a constructor calling a function other than a constructor is assumed to have side
effects.
Test plan
New
_ok,_badandFN_tests incpp/liveness/dead_stores.cpp; the existing expectations donot change.