Repository navigation
Fix -Wmaybe-uninitialized for Vec of a shared struct - #1770
Open
tonycoder-hub wants to merge 1 commit into
Open
tonycoder-hub wants to merge 1 commit into
tonycoder-hub wants to merge 1 commit into
Conversation
Generated cxxbridge1$rust_vec$...$new took a const pointer, but the Rust shim writes a new Vec through that pointer. GCC treats the uninitialized this inside Vec<T>::Vec() as a read and warns, so -Werror fails the build when a shared struct is used as a Vec element. Declare the pointer mutable, matching the builtin specializations in cxx.cc. Fixes dtolnay#1769 Signed-off-by: Tony Coder <407243179@qq.com>
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.
rust::Vec<T>::Vec()for a shared struct value-initializes throughcxxbridge1$rust_vec$...$new(this). The Rust shim writes a new vector through that pointer, but the generated C++ declaration tookconst rust::Vec<T> *. GCC treats the uninitializedthisas a read and emits-Wmaybe-uninitialized. With-Werror, a normalVecof a shared struct fails to build.The builtin specializations in
src/cxx.ccalready declare this pointer withoutconst. The generated declaration now matches.Fixes #1769
Test plan
CXX=g++ cargo test --test cpp_ui_tests test_vec_of_shared_struct_constructorfails before the change with-Werror=maybe-uninitializedand passes afterCXX=g++ cargo test --workspace --exclude democargo fmt --all -- --checkRUSTFLAGS=-Dwarnings cargo clippy --workspace --tests --exclude demo -- -Dclippy::all -Dclippy::pedanticRUSTFLAGS=-Dwarnings cargo clippy --manifest-path demo/Cargo.toml -- -Dclippy::allThis change was prepared with AI assistance and verified by the tests above.