Fix empty vector argument array construction - #218
Merged
Conversation
kalvdans
approved these changes
Jul 7, 2026
Comment on lines
+1560
to
+1561
| if (n > 0) | ||
| heap.copy<T>(a,aa.data(),n); |
There was a problem hiding this comment.
Nit: aa.data() is fine to call on an empty std::vector (might or might not return nullptr). do we need the if (n > 0) then?
Member
Author
There was a problem hiding this comment.
Good point, and thanks for noting that. I still decided to keep the redundant if, as it shouldn't cost anything at runtime, and I like that it is explicit and not relying on API promises.
There was a problem hiding this comment.
The canonical way is
if (!aa.empty())
heap.copy<T>(a,aa.data(),n);
zayenz
force-pushed
the
feature/empty-vector-args
branch
3 times, most recently
from
July 11, 2026 05:22
4b0a8c4 to
ba29920
Compare
zayenz
marked this pull request as ready for review
July 11, 2026 06:13
zayenz
force-pushed
the
feature/empty-vector-args
branch
from
July 11, 2026 08:23
ba29920 to
8dd3af4
Compare
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.
Summary
std::vectorinstances by avoiding&aa[0]when the vector is empty.IntArgs,IntVarArgs, andBoolVarArgs.Fixes #205.
Validation
cmake -S . -B /tmp/gecode-empty-vector-args-build -DCMAKE_BUILD_TYPE=Debug -DGECODE_ENABLE_EXAMPLES=OFF -DGECODE_ENABLE_GIST=OFF -DGECODE_ENABLE_QT=OFFcmake --build /tmp/gecode-empty-vector-args-build --target gecode-test -j 8/tmp/gecode-empty-vector-args-build/bin/gecode-test -test Array::Vector::Emptygit diff --check