Skip to content
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

Fix using constructor that is unavailable in C++11 #168

Merged
merged 2 commits into from
Oct 29, 2023

Conversation

mjacobse
Copy link
Collaborator

@mjacobse mjacobse commented Oct 29, 2023

According to cppreference.com, the vector constructor vector( size_type count, const Allocator& alloc = Allocator() ) without init value but with allocator that is used here was only introduced in C++14. Since we only compile with C++11, this was caught correctly by LLVM's libc++ (see #166). It only enables this constructor for C++14 and greater: https://github.com/llvm/llvm-project/blob/f39c38584eb762702a651e87e63162c9bc4842a3/libcxx/include/vector#L425-L427

Minimal example: https://godbolt.org/z/WqnWPdoK1 vs. https://godbolt.org/z/sq9srsb8P

GNUs stdlibc++ seems to just silently (and wrongfully) provide this constructor even on C++11, hiding this issue until now.

To fix this, provide the init value 0 explicitly to call the vector( size_type count, const T& value = T(), const Allocator& alloc = Allocator() ) constructor that is provided by C++11. Fixes #166

The version of the vector constructor without init value but with
allocator that is attempted to be used here was introduced only in
C++14. Since we are targeting C++11, we should not use this constructor.
So pass the init value of 0 explicitly. Fixes ralna#166
@barracuda156
Copy link

I can confirm it fixes the problem for me on Sonoma.

With ebbce3e the build should now work with C++11, see ralna#166
@amontoison amontoison merged commit c5c1d0b into ralna:master Oct 29, 2023
14 of 16 checks passed
@mjacobse mjacobse deleted the fix_vector_constructor branch October 30, 2023 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants