Bug 2253421 - std::stoi not declared for std::string in 32 bit mode
Summary: std::stoi not declared for std::string in 32 bit mode
Keywords:
Status: CLOSED DUPLICATE of bug 2246731
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 39
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-12-07 10:17 UTC by Tom Hughes
Modified: 2023-12-07 10:35 UTC (History)
11 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2023-12-07 10:35:05 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Tom Hughes 2023-12-07 10:17:42 UTC
Description of problem:

Overloads of std::stoi and related functions for std::string are not available when compiling with -m32 leading to errors when the compiler tries to use the std::wstring overload instead.

Version-Release number of selected component (if applicable):

gcc-13.2.1-4.fc39.x86_64


Steps to Reproduce:

Use "g++ -m32 -c test.cpp" to compile this test case:

#include <string>

int foo( std::string s )
{
    return std::stoi( s );
}

Actual results:

test.cpp: In function ‘int foo(std::string)’:
test.cpp:5:23: error: invalid initialization of reference of type ‘const std::wstring&’ {aka ‘const std::__cxx11::basic_string<wchar_t>&’} from expression of type ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’}
    5 |     return std::stoi( s );
      |                       ^
In file included from /usr/include/c++/13/string:54,
                 from test.cpp:1:
/usr/include/c++/13/bits/basic_string.h:4260:23: note: in passing argument 1 of ‘int std::__cxx11::stoi(const std::wstring&, std::size_t*, int)’
 4260 |   stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
      |        ~~~~~~~~~~~~~~~^~~~~

Expected results:

Code compiles.

Additional info:

This works with -m64 as expected - the problem appears to be that /usr/include/c++/13/x86_64-redhat-linux/32/bits/c++config.h defines _GLIBCXX11_USE_C99_STDLIB for 64 bit builds but not for 32 bit builds.

Comment 1 Tom Hughes 2023-12-07 10:20:13 UTC
Also this seems to work for both 32 and 64 bit with gcc 13.2 on godbolt so I'm guessing it's something specific to the Fedora build.

Comment 2 Jakub Jelinek 2023-12-07 10:35:05 UTC

*** This bug has been marked as a duplicate of bug 2246731 ***


Note You need to log in before you can comment on or make changes to this bug.