all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Erik Garrison <erik.garrison@gmail.com>
To: guix-devel@gnu.org
Subject: gcc-10 toolchain does not include string to numeric conversion functions like std::stoull
Date: Tue, 9 Jun 2020 11:45:52 +0200	[thread overview]
Message-ID: <CALykB6=bDEqr53SRTD82z4kO4u+kkYHh1f8=C0AiCWHodL5Eww@mail.gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2020-06-09 11:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-09  9:45 Erik Garrison [this message]
2020-06-10 15:18 ` gcc-10 toolchain does not include string to numeric conversion functions like std::stoull 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALykB6=bDEqr53SRTD82z4kO4u+kkYHh1f8=C0AiCWHodL5Eww@mail.gmail.com' \
    --to=erik.garrison@gmail.com \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.