Re: Peculiar bug when converting int's to std::strings using MSVC 2015
Arash Partow <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <CACS6Y7JR44xgYwHW0fpMBLtWD+VHfOHtF0hAip8+9G5bkCQCQQ@mail.gmail.com> |
On Thu, Mar 9, 2017, Seth wrote:
>
> Oh. You mean not just the ones shown. I had assumed you listed only the
> failing cases.
Yes every value conversion attempt in that loop fails.
> Because that's the output of the program. So, to clarify even
> more, do you mean, the following program fails too?
> http://coliru.stacked-crooked.com/a/2715e11d1592fd07
>
> #include <boost/spirit/include/karma.hpp>
>
> inline std::string karma_int_to_string(int value) {
> namespace k = boost::spirit::karma;
> std::string str;
> k::generate(back_inserter(str), k::int_, value);
> return str;
> }
>
> int main() {
> assert(std::to_string(42) == karma_int_to_string(42));
> }
>
Your example works fine on all the compilers I tested - including
MSVC2015 U3 which was the only compiler giving the erroneous result.
>
> If so, there's obviously some kind of UB involved. But it's not very clear
> to me what could cause it (barring MSVC bugs)
>
I've been using the originally described routine, as it was the one
recommended by Joel and Hartmut back in 2009 for inclusion in a string
processing benchmark.
Now given that this 'new' version functions correctly even using the
'buggy' compiler - do you recommend it be used?
I ask because I reran the benchmark (using MSVC2017) and the new
routine is considerably slower than the original routine.
https://gist.github.com/anonymous/c1d91acd1bf8ac7f4fdfbeecbd102639
Similar results are obtained when using GCC/Clang.
The benchmark code:
https://github.com/ArashPartow/strtk/blob/master/strtk_tokenizer_cmp.cpp#L901
Arash
------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford