-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC] Fix uninitialized scalar field in constructor. #118324
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
Conversation
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clangd Author: Zahira Ammarguellat (zahiraam) ChangesNon-static class field is not initialized in constructor. Full diff: https://github.com/llvm/llvm-project/pull/118324.diff 2 Files Affected:
diff --git a/clang-tools-extra/clangd/index/MemIndex.h b/clang-tools-extra/clangd/index/MemIndex.h
index fba2c1a7120a2b..879d7750ac0480 100644
--- a/clang-tools-extra/clangd/index/MemIndex.h
+++ b/clang-tools-extra/clangd/index/MemIndex.h
@@ -43,6 +43,7 @@ class MemIndex : public SymbolIndex {
KeepAlive = std::shared_ptr<void>(
std::make_shared<Payload>(std::move(BackingData)), nullptr);
this->BackingDataSize = BackingDataSize;
+ this->IdxContents = IndexContents::All;
}
template <typename SymbolRange, typename RefRange, typename RelationRange,
diff --git a/clang-tools-extra/clangd/index/dex/Dex.h b/clang-tools-extra/clangd/index/dex/Dex.h
index 69e161d51135b6..f907c9a55b935b 100644
--- a/clang-tools-extra/clangd/index/dex/Dex.h
+++ b/clang-tools-extra/clangd/index/dex/Dex.h
@@ -58,6 +58,7 @@ class Dex : public SymbolIndex {
KeepAlive = std::shared_ptr<void>(
std::make_shared<Payload>(std::move(BackingData)), nullptr);
this->BackingDataSize = BackingDataSize;
+ this->IdxContents = IndexContents::All;
}
template <typename SymbolRange, typename RefsRange, typename RelationsRange,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you decide on IndexContents::All
as the default initialization value. I would be more inclined towards IndexContents::None
.
I think it would be preferred to use a member initializer in the declaration of IdxContents
. That will ensure an initialization is performed if additional constructors are added.
Actually that makes more sense and it will obviously be assigned to |
Seems like It's a bit suspicious to me that the other |
idxcontents is only used when we have a set of file names available. hence this was only set via relevant constructors and rest of the runtime doesn't use the field. but we don't construct tons of new index instances every second. so it's totally fine to just initialize them to |
I could also initialize all the others to |
Thanks for the explanation. |
@HighCommander4 Is that good as a change? Do you still want an issue to be opened? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, lgtm!
I sent out a follow-up PR at #118906 to add a comment describing the situations in which |
Non-static class field is not initialized in constructor.