Unit literal constructed from integral 0 passed to to_string causes std::out_of_range
ts826848 opened this issue · comments
ts826848 commented
Passing a unit created using using a unit literal and 0
(e.g., 0_psi
) to to_string
causes std::out_of_range
to be thrown:
awang@rp units % cat test.cpp
#include <units/pressure.h>
int main() {
using namespace units::literals;
auto s = to_string(0_psi);
}
awang@rp units % /usr/local/opt/llvm/bin/clang++ -I include/ -std=c++17 -g test.cpp
awang@rp units % ./a.out
libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string
zsh: abort ./a.out
awang@rp units % /usr/local/opt/gcc/bin/g++-10 -I include/ -std=c++17 -g test.cpp
awang@rp units % ./a.out
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::erase: __pos (which is 18446744073709551615) > this->size() (which is 1)
zsh: abort ./a.out
awang@rp units % /usr/local/opt/llvm/bin/clang++ --version
clang version 11.0.0
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
awang@rp units % /usr/local/opt/gcc/bin/g++-10 --version
g++-10 (Homebrew GCC 10.2.0) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
An exception is also thrown for 00_psi
, 000_psi
, etc. Nothing bad appears to happen with with non-zero values or with 0.0_psi
.
This is using the latest version of the v3.x branch (791dab5).