ralna / spral

Sparse Parallel Robust Algorithms Library
https://ralna.github.io/spral/
Other
102 stars 27 forks source link

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

Closed mjacobse closed 8 months ago

mjacobse commented 8 months ago

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

barracuda156 commented 8 months ago

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