Bug 2253421

Summary: std::stoi not declared for std::string in 32 bit mode
Product: [Fedora] Fedora Reporter: Tom Hughes <tom>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED DUPLICATE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 39CC: dmalcolm, fweimer, jakub, jlaw, jwakely, mcermak, mpolacek, msebor, nickc, nixuser, sipoyare
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-12-07 10:35:05 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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 ***