[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
stdlib: Avoid syntax errors in libstdc++ header files
From: |
Bruno Haible |
Subject: |
stdlib: Avoid syntax errors in libstdc++ header files |
Date: |
Sun, 14 Jul 2024 20:49:39 +0200 |
After yesterday's correction of stdlib.h in C++ mode, the CI reports a
compilation error on Solaris 11 OmniOS:
g++ -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -I. -I../../gltests -I..
-DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I..
-I../../gltests/.. -I../gllib -I../../gltests/../gllib
-I/home/bruno/prefix64/include -I/opt/ooce/include -Wall -D_REENTRANT
-Wno-error -g -O2 -MT test-nullptr-c++.o -MD -MP -MF $depbase.Tpo -c -o
test-nullptr-c++.o ../../gltests/test-nullptr-c++.cc &&\
mv -f $depbase.Tpo $depbase.Po
In file included from ../gllib/pthread.h:62,
from
/opt/gcc-9/include/c++/9.3.0/x86_64-pc-solaris2.11/bits/gthr-default.h:35,
from
/opt/gcc-9/include/c++/9.3.0/x86_64-pc-solaris2.11/bits/gthr.h:148,
from /opt/gcc-9/include/c++/9.3.0/ext/atomicity.h:35,
from /opt/gcc-9/include/c++/9.3.0/bits/ios_base.h:39,
from /opt/gcc-9/include/c++/9.3.0/ios:42,
from /opt/gcc-9/include/c++/9.3.0/ostream:38,
from /opt/gcc-9/include/c++/9.3.0/iostream:39,
from ../../gltests/test-nullptr-c++.cc:25:
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h: In function 'int
std::__cxx11::stoi(const string&, std::size_t*, int)':
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h:6504:47: error: 'rpl_strtol'
is not a member of 'std'; did you mean 'strtol'?
6504 | { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi",
__str.c_str(),
| ^~~~~~
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h: In function 'long int
std::__cxx11::stol(const string&, std::size_t*, int)':
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h:6509:36: error: 'rpl_strtol'
is not a member of 'std'; did you mean 'strtol'?
6509 | { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
| ^~~~~~
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h: In function 'long unsigned
int std::__cxx11::stoul(const string&, std::size_t*, int)':
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h:6514:36: error: 'rpl_strtoul'
is not a member of 'std'; did you mean 'strtoul'?
6514 | { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
| ^~~~~~~
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h: In function 'long long int
std::__cxx11::stoll(const string&, std::size_t*, int)':
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h:6519:36: error: 'rpl_strtoll'
is not a member of 'std'; did you mean 'rpl_strtoll'?
6519 | { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
| ^~~~~~~
In file included from /usr/include/sys/time.h:489,
from ../gllib/sys/time.h:46,
from /usr/include/sys/select.h:53,
from ../gllib/sys/select.h:43,
from /usr/include/sys/types.h:640,
from ../gllib/sys/types.h:46,
from ../gllib/stdio.h:83,
from /usr/include/iso/wchar_iso.h:54,
from
/opt/gcc-9/lib/gcc/x86_64-pc-solaris2.11/9.3.0/include-fixed/wchar.h:40,
from ../gllib/wchar.h:80,
from /opt/gcc-9/include/c++/9.3.0/cwchar:44,
from /opt/gcc-9/include/c++/9.3.0/bits/postypes.h:40,
from /opt/gcc-9/include/c++/9.3.0/iosfwd:40,
from /opt/gcc-9/include/c++/9.3.0/ios:38,
from /opt/gcc-9/include/c++/9.3.0/ostream:38,
from /opt/gcc-9/include/c++/9.3.0/iostream:39,
from ../../gltests/test-nullptr-c++.cc:25:
../gllib/stdlib.h:2309:1: note: 'rpl_strtoll' declared here
2309 | _GL_FUNCDECL_RPL (strtoll, long long,
| ^~~~~~~~~~~~~~~~
In file included from ../gllib/pthread.h:62,
from
/opt/gcc-9/include/c++/9.3.0/x86_64-pc-solaris2.11/bits/gthr-default.h:35,
from
/opt/gcc-9/include/c++/9.3.0/x86_64-pc-solaris2.11/bits/gthr.h:148,
from /opt/gcc-9/include/c++/9.3.0/ext/atomicity.h:35,
from /opt/gcc-9/include/c++/9.3.0/bits/ios_base.h:39,
from /opt/gcc-9/include/c++/9.3.0/ios:42,
from /opt/gcc-9/include/c++/9.3.0/ostream:38,
from /opt/gcc-9/include/c++/9.3.0/iostream:39,
from ../../gltests/test-nullptr-c++.cc:25:
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h: In function 'long long
unsigned int std::__cxx11::stoull(const string&, std::size_t*, int)':
/opt/gcc-9/include/c++/9.3.0/bits/basic_string.h:6524:36: error: 'rpl_strtoull'
is not a member of 'std'; did you mean 'rpl_strtoull'?
6524 | { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
| ^~~~~~~~
In file included from /usr/include/sys/time.h:489,
from ../gllib/sys/time.h:46,
from /usr/include/sys/select.h:53,
from ../gllib/sys/select.h:43,
from /usr/include/sys/types.h:640,
from ../gllib/sys/types.h:46,
from ../gllib/stdio.h:83,
from /usr/include/iso/wchar_iso.h:54,
from
/opt/gcc-9/lib/gcc/x86_64-pc-solaris2.11/9.3.0/include-fixed/wchar.h:40,
from ../gllib/wchar.h:80,
from /opt/gcc-9/include/c++/9.3.0/cwchar:44,
from /opt/gcc-9/include/c++/9.3.0/bits/postypes.h:40,
from /opt/gcc-9/include/c++/9.3.0/iosfwd:40,
from /opt/gcc-9/include/c++/9.3.0/ios:38,
from /opt/gcc-9/include/c++/9.3.0/ostream:38,
from /opt/gcc-9/include/c++/9.3.0/iostream:39,
from ../../gltests/test-nullptr-c++.cc:25:
../gllib/stdlib.h:2392:1: note: 'rpl_strtoull' declared here
2392 | _GL_FUNCDECL_RPL (strtoull, unsigned long long,
| ^~~~~~~~~~~~~~~~
gmake[4]: *** [Makefile:27303: test-nullptr-c++.o] Error 1
This patch fixes it.
2024-07-14 Bruno Haible <bruno@clisp.org>
stdlib: Avoid syntax errors in libstdc++ header files.
* lib/stdlib.in.h: Include <string> before strtol, strtoll, strtoul, or
strtoull gets defined as a macro.
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index 47a8856dc7..ac328eb5e7 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -117,6 +117,16 @@ struct random_data
# include <unistd.h>
#endif
+#if ((@GNULIB_STRTOL@ && @REPLACE_STRTOL@) || (@GNULIB_STRTOLL@ &&
@REPLACE_STRTOLL@) || (@GNULIB_STRTOUL@ && @REPLACE_STRTOUL@) ||
(@GNULIB_STRTOULL@ && @REPLACE_STRTOULL@)) && defined __cplusplus && !defined
GNULIB_NAMESPACE && defined __GNUG__
+/* When strtol, strtoll, strtoul, or strtoull is going to be defined as a macro
+ below, this may cause compilation errors later in the libstdc++ header files
+ (that are part of GCC), such as:
+ error: 'rpl_strtol' is not a member of 'std'
+ To avoid this, include the relevant header files here, before these symbols
+ get defined as macros. */
+# include <string>
+#endif
+
/* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
that can be freed by passing them as the Ith argument to the
function F. */
- stdlib: Avoid syntax errors in libstdc++ header files,
Bruno Haible <=