all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* gcc-10 toolchain does not include string to numeric conversion functions like std::stoull
@ 2020-06-09  9:45 Erik Garrison
  2020-06-10 15:18 ` Ludovic Courtès
  0 siblings, 1 reply; 6+ messages in thread
From: Erik Garrison @ 2020-06-09  9:45 UTC (permalink / raw)
  To: guix-devel

[-- Attachment #1: Type: text/plain, Size: 3340 bytes --]

Hello guix-devel,

I've run into a quirk in the various gcc toolchains that seems somewhat
unique to guix builds of them. I'd like to understand if this is
intentional.

Initially, I found that string to numeric conversion functions that are
enabled by _GLIBCXX_USE_C99_STDLIB are not available on guix gcc toolchains
for gcc 8, 9, and 10.

This is a minimal test case to reproduce the problem:

Code:

#include <iostream>
#include <string>

uint64_t _parse_number(std::string::const_iterator& c, const
std::string::const_iterator& end) {
    std::string::const_iterator s = c;
    while (c != end and isdigit(*c)) ++c;
    if (c > s) {
        return std::stoull(std::string(s,c));
    } else {
        return 0;
    }
}

int main(int argc, char** argv) {
    std::string s(argv[1]);
    std::string::const_iterator b = s.begin();
    std::string::const_iterator e = s.end();
    std::cout << _parse_number(b, e) << std::endl;
    return 0;
}

Compiling with (g++ --version == 10.1.0),
/gnu/store/3kvnslc16sy7kwi2c5r7r5k6bbv2p03f-gcc-toolchain-10.1.0/bin/g++

g++ test-stoull.cpp -o test-stoull

Yields this error:

test-stoull.cpp: In function ‘uint64_t
_parse_number(std::__cxx11::basic_string<char>::const_iterator&, const
const_iterator&)’:
test-stoull.cpp:13:33: error: invalid initialization of reference of type
‘const wstring&’ {aka ‘const std::__cxx11::basic_string<wchar_t>&’} from
expression of type ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’}
   13 |         return std::stoull(std::string(s,c));
      |                                 ^~~~~~~~~~~
In file included from /home/erikg/.guix-profile/include/c++/string:55,
                 from
/home/erikg/.guix-profile/include/c++/bits/locale_classes.h:40,
                 from
/home/erikg/.guix-profile/include/c++/bits/ios_base.h:41,
                 from /home/erikg/.guix-profile/include/c++/ios:42,
                 from /home/erikg/.guix-profile/include/c++/ostream:38,
                 from /home/erikg/.guix-profile/include/c++/iostream:39,
                 from test-stoull.cpp:1:
/home/erikg/.guix-profile/include/c++/bits/basic_string.h:6697:25: note: in
passing argument 1 of ‘long long unsigned int std::__cxx11::stoull(const
wstring&, std::size_t*, int)’
 6697 |   stoull(const wstring& __str, size_t* __idx = 0, int __base = 10)
      |          ~~~~~~~~~~~~~~~^~~~~

I understand that there might be concern about my particular .guix-profile,
but it's possible to reproduce this in containers. I can provide more test
cases if needed, but I just wanted to clarify in general what I'm seeing.

This behavior appears to be similar to this issue:
http://freebsd.1045724.x6.nabble.com/base-gcc-and-GLIBCXX-USE-C99-td5781697.html.
It's also similar to this report,
https://stackoverflow.com/questions/40779611/g-compile-error-invalid-initialization-of-reference-of-type-stdstod
.

It may be more correct to require wstring in these kinds of conversions.
However, I'm concerned that if gcc is built differently in guix than it
typically is in other distributions, we will need to patch many libraries
when building them on guix. It's probably better to match typical
expectations of developers about the behavior of gcc.

Thanks in advance,

Erik

[-- Attachment #2: Type: text/html, Size: 4107 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-07-15  6:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-09  9:45 gcc-10 toolchain does not include string to numeric conversion functions like std::stoull Erik Garrison
2020-06-10 15:18 ` Ludovic Courtès
2020-07-11 11:30   ` Erik Garrison
2020-07-13 14:21     ` Ludovic Courtès
2020-07-13 16:37       ` Ekaitz Zarraga
2020-07-15  6:48       ` Pjotr Prins

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.