Bug #2734

c++11 is missing stoi

Added by phma about 5 years ago. Updated almost 5 years ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:


$ g++ --std=c++11 -o stoitest stoitest.cpp
stoitest.cpp: In function 'int main(int, char**)':
stoitest.cpp:18:15: error: 'stoi' was not declared in this scope

This program compiles and runs on Ubuntu Linux, using g++ 4.8.2. It produces the above error on DragonFly BSD, both using the g++ 4.7.4 in world and using g++ 4.8.3 installed as a package.


stoitest.cpp (359 Bytes) stoitest.cpp phma, 11/12/2014 03:56 PM



Updated by phma about 5 years ago


Updated by phma about 5 years ago

  • File deleted (stoitest.cpp)

Updated by swildner about 5 years ago


I don't have a fix but here's why.

In contrib/gcc-4.7/libstdc++-v3/include/bits/basic_string.h we find:

#if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99) \

#include <ext/string_conversions.h>

namespace std _GLIBCXX_VISIBILITY(default)

// 21.4 Numeric Conversions [string.conversions].
inline int
stoi(const string& __str, size_t* __idx = 0, int __base = 10)
{ return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
__idx, __base); }

} // namespace

#endif /* __GXX_EXPERIMENTAL_CXX0X__ && _GLIBCXX_USE_C99 ... */

__GXX_EXPERIMENTAL_CXX0X__ is defined, _GLIBCXX_HAVE_BROKEN_VSWPRINTF isn't, so we're clear regarding those two. However, _GLIBCXX_USE_C99 isn't defined, but it's needed for stoi() and various other functions.

From libstdc++-v3's configure output:

checking for ISO C99 support in <complex.h>... no
checking for ISO C99 support in <stdio.h>... yes
checking for ISO C99 support in <stdlib.h>... yes
checking for ISO C99 support in <wchar.h>... yes
checking for fully enabled ISO C99 support... no

Compiling the associated conftest for complex.h gives this:

complex.c:(.text+0x19b): undefined reference to `clogf'
complex.c:(.text+0x3e6): undefined reference to `cpowf'
complex.c:(.text+0x65d): undefined reference to `clog'
complex.c:(.text+0x8db): undefined reference to `cpow'
complex.c:(.text+0xa0c): undefined reference to `ccosl'
complex.c:(.text+0xa7c): undefined reference to `ccoshl'
complex.c:(.text+0xaec): undefined reference to `cexpl'
complex.c:(.text+0xb5c): undefined reference to `clogl'
complex.c:(.text+0xbcc): undefined reference to `csinl'
complex.c:(.text+0xc3c): undefined reference to `csinhl'
complex.c:(.text+0xd1c): undefined reference to `ctanl'
complex.c:(.text+0xd8c): undefined reference to `ctanhl'
complex.c:(.text+0xe2a): undefined reference to `cpowl'

So it seems we need these functions first before we could enable _GLIBCXX_USE_C99 which would then cause stoi() to be present.



Updated by swildner about 5 years ago

And in fact, using

g++ -D_GLIBCXX_USE_C99 --std=c++11 -o stoitest stoitest.cpp

it will compile.


Updated by marino almost 5 years ago

  • Assignee set to marino

Updated by marino almost 5 years ago

gcc has the missing functions built in, although I don't know yet if this includes gcc 4.7. A failed conftest doesn't mean there's no C99, it just means it needs to use builtin intead of libc I think.


Updated by marino almost 5 years ago

The ISO C99 functions _Exit, acoshf, acoshl, acosh, asinhf, asinhl, asinh, atanhf, atanhl, atanh, cabsf, cabsl, cabs, cacosf, cacoshf, cacoshl, cacosh, cacosl, cacos, cargf, cargl, carg, casinf, casinhf, casinhl, casinh, casinl, casin, catanf, catanhf, catanhl, catanh, catanl, catan, cbrtf, cbrtl, cbrt, ccosf, ccoshf, ccoshl, ccosh, ccosl, ccos, cexpf, cexpl, cexp, cimagf, cimagl, cimag, clogf, clogl, clog, conjf, conjl, conj, copysignf, copysignl, copysign, cpowf, cpowl, cpow, cprojf, cprojl, cproj, crealf, creall, creal, csinf, csinhf, csinhl, csinh, csinl, csin, csqrtf, csqrtl, csqrt, ctanf, ctanhf, ctanhl, ctanh, ctanl, ctan, erfcf, erfcl, erfc, erff, erfl, erf, exp2f, exp2l, exp2, expm1f, expm1l, expm1, fdimf, fdiml, fdim, fmaf, fmal, fmaxf, fmaxl, fmax, fma, fminf, fminl, fmin, hypotf, hypotl, hypot, ilogbf, ilogbl, ilogb, imaxabs, isblank, iswblank, lgammaf, lgammal, lgamma, llabs, llrintf, llrintl, llrint, llroundf, llroundl, llround, log1pf, log1pl, log1p, log2f, log2l, log2, logbf, logbl, logb, lrintf, lrintl, lrint, lroundf, lroundl, lround, nearbyintf, nearbyintl, nearbyint, nextafterf, nextafterl, nextafter, nexttowardf, nexttowardl, nexttoward, remainderf, remainderl, remainder, remquof, remquol, remquo, rintf, rintl, rint, roundf, roundl, round, scalblnf, scalblnl, scalbln, scalbnf, scalbnl, scalbn, snprintf, tgammaf, tgammal, tgamma, truncf, truncl, trunc, vfscanf, vscanf, vsnprintf and vsscanf are handled as built-in functions except in strict ISO C90 mode (-ansi or -std=c90).


Updated by marino almost 5 years ago

early research of mine indicates swildner is correct and the missing obscure complex functions are causing dragonfly to be declared C99 incapable even though it could handle stoi and other functions.

Maybe it's best just to add the functions from NetBSD into libm.


Updated by marino almost 5 years ago

  • Status changed from New to Closed

I've imported 16 complex functions into libm from NetBSD.
From this point, any gcc built from dports on master will be capable of c++11.

In addition, I update the config.h header for the gcc47 base compiler and it can also build the test case in this bug report (latest master of course).

closing the report...

Also available in: Atom PDF