Project

General

Profile

Actions

Bug #2734

closed

c++11 is missing stoi

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

Status:
Closed
Priority:
Normal
Assignee:
Category:
Build
Target version:
Start date:
11/12/2014
Due date:
% Done:

0%

Estimated time:

Description

$ 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.


Files

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

Updated by phma about 10 years ago

Actions #2

Updated by phma about 10 years ago

  • File deleted (stoitest.cpp)
Actions #3

Updated by swildner about 10 years ago

Pierre,

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) \
&& !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))

#include <ext/string_conversions.h>

namespace std _GLIBCXX_VISIBILITY(default) {
_GLIBCXX_BEGIN_NAMESPACE_VERSION

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

_GLIBCXX_END_NAMESPACE_VERSION
} // 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.

Regards,
Sascha

Actions #4

Updated by swildner about 10 years ago

And in fact, using

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

it will compile.

Actions #5

Updated by marino almost 10 years ago

  • Assignee set to marino
Actions #6

Updated by marino almost 10 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.

Actions #7

Updated by marino almost 10 years ago

https://gcc.gnu.org/onlinedocs/gcc-4.7.4/gcc/Other-Builtins.html

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).

Actions #8

Updated by marino almost 10 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.

Actions #9

Updated by marino almost 10 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...

Actions

Also available in: Atom PDF