strtof is not defined anymore in std=c++11
Jon TURNEY
jon.turney@dronecode.org.uk
Tue Apr 9 14:18:00 GMT 2013
On 02/04/2013 20:19, Corinna Vinschen wrote:
> On Apr 2 20:10, Jon TURNEY wrote:
>> On 02/04/2013 13:00, Corinna Vinschen wrote:
>>> On Apr 2 12:37, Laurent Alfonsi wrote:
>>>> The strtof function is now rejected when selecting the gcc C++11
>>>> standard option.
>>>> This regression has been introduced in this patch
>>>> http://sourceware.org/ml/newlib/2012/msg00425.html
>>>>
>>>> J.Turney patch is fine regarding the C standard side, but when using
>>>> from C++ :
>>>> $ cat a.cpp
>>>> #include <cstdlib>
>>>>
>>>> float f(const char *s, char **endptr) {
>>>> return strtof(s, endptr);
>>>> }
>>>>
>>>> It fails with the message :
>>>> $ g++ -std=c++11 a.cpp
>>>> a.cpp: In function 'float f(const char*, char**)':
>>>> a.cpp:3:30: error: 'strtof' was not declared in this scope
>>>>
>>>> Whereas this function strtof is well included in the cstdlib header
>>>> file defined in C++11 ISO.
>>>>
>>>> Please advice.
>>>
>>> Not sure. Enabling c++11 implies defining __STRICT_ANSI__ with gcc.
>>> Maybe we have to add something like this to the #if's guarding the
>>> declarations:
>>>
>>> || (defined (__cplusplus) && __cplusplus >= 201103L)
>>
>> Yes. I think that all of the protoypes I touched: strtof(), strtoll(),
>> strtoull() and strtold() need this attention.
>>
>> As currently written, it doesn't test if __STDC_VERSION__ is defined (and so
>> uses the assumed value of 0 when compiling C++), so do we actually need to
>> test if __cplusplus is defined?
>>
>> Would you like me to write a patch?
>
> That would be nice!
Attached.
$ g++ c99-stdlib-test.cpp -std=c++03 -Werror=implicit-function-declaration
c99-stdlib-test.cpp: In function âint main()â:
c99-stdlib-test.cpp:5:27: error: âstrtollâ was not declared in this scope
strtoll("1234", NULL , 0);
^
c99-stdlib-test.cpp:6:27: error: âstrtoullâ was not declared in this scope
strtoull("1234", NULL, 0);
^
c99-stdlib-test.cpp:7:22: error: âstrtofâ was not declared in this scope
strtof("1234", NULL);
^
$ g++ c99-stdlib-test.cpp -std=c++11 -Werror=implicit-function-declaration
newlib/ChangeLog:
2013-04-09 Jon TURNEY <jon.turney@dronecode.org.uk>
* libc/include/stdlib.h (strtof, strtoll, strtoull, strtold): Also
prototype if C++11 or later
-------------- next part --------------
Index: newlib/libc/include/stdlib.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdlib.h,v
retrieving revision 1.42
diff -u -p -r1.42 stdlib.h
--- newlib/libc/include/stdlib.h 1 Nov 2012 11:51:11 -0000 1.42
+++ newlib/libc/include/stdlib.h 9 Apr 2013 14:11:34 -0000
@@ -122,7 +122,7 @@ _PTR _EXFUN(reallocf,(_PTR __r, size_t _
_VOID _EXFUN(srand,(unsigned __seed));
double _EXFUN(strtod,(const char *__n, char **__end_PTR));
double _EXFUN(_strtod_r,(struct _reent *,const char *__n, char **__end_PTR));
-#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)
+#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L)
float _EXFUN(strtof,(const char *__n, char **__end_PTR));
#endif
#ifndef __STRICT_ANSI__
@@ -186,13 +186,13 @@ long long _EXFUN(_atoll_r,(struct _reent
long long _EXFUN(llabs,(long long));
lldiv_t _EXFUN(lldiv,(long long __numer, long long __denom));
#endif /* ! __STRICT_ANSI__ */
-#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)
+#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L)
long long _EXFUN(strtoll,(const char *__n, char **__end_PTR, int __base));
#endif
#ifndef __STRICT_ANSI__
long long _EXFUN(_strtoll_r,(struct _reent *, const char *__n, char **__end_PTR, int __base));
#endif /* ! __STRICT_ANSI__ */
-#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)
+#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L)
unsigned long long _EXFUN(strtoull,(const char *__n, char **__end_PTR, int __base));
#endif
#ifndef __STRICT_ANSI__
@@ -224,7 +224,7 @@ _VOID _EXFUN(__eprintf,(const char *, co
/* On platforms where long double equals double. */
#ifdef _LDBL_EQ_DBL
-#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)
+#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L)
extern long double strtold (const char *, char **);
#endif
extern long double wcstold (const wchar_t *, wchar_t **);
More information about the Newlib
mailing list