bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* math: Fix compilation errors in C++ mode on Android
@ 2023-01-10  9:03 Bruno Haible
  0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2023-01-10  9:03 UTC (permalink / raw)
  To: bug-gnulib

In a testdir on Android, I see many compilation errors here:

clang++ -ferror-limit=0 -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/data/data/com.termux/files/home/local/include -Wall  -Wno-error -g -O2 -c -o test-math-c++2.o ../../gltests/test-math-c++2.cc
In file included from ../../gltests/test-math-c++2.cc:20:
In file included from /data/data/com.termux/files/usr/include/c++/v1/cmath:304:
In file included from /data/data/com.termux/files/usr/include/c++/v1/math.h:301:
In file included from ../gllib/stdlib.h:36:
In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:20:
In file included from /data/data/com.termux/files/usr/include/stdlib.h:34:
In file included from ../gllib/malloc.h:42:
In file included from /data/data/com.termux/files/usr/include/malloc.h:30:
In file included from ../gllib/stdio.h:71:
In file included from ../gllib/sys/stat.h:44:
In file included from ../gllib/time.h:47:
In file included from /data/data/com.termux/files/usr/include/time.h:33:
In file included from ../gllib/sys/time.h:39:
In file included from /data/data/com.termux/files/usr/include/sys/time.h:37:
In file included from ../gllib/sys/select.h:102:
In file included from /data/data/com.termux/files/usr/include/sys/select.h:40:
In file included from ../gllib/signal.h:75:
In file included from ../gllib/pthread.h:56:
In file included from ../gllib/stdlib.h:28:
In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:100:
../gllib/math.h:773:19: error: no member named 'acosf' in the global namespace
_GL_CXXALIAS_SYS (acosf, float, (float x));
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
...

The problem is that
  - /usr/include/c++/v1/math.h indirectly includes gllib/math.h before
    /usr/include/math.h has been included,
  - The line '#include_next <math.h>' in gllib/math.h includes
    /usr/include/c++/v1/math.h, which expands to empty since it is being
    included.

This patch fixes it.


2023-01-10  Bruno Haible  <bruno@clisp.org>

	math: Fix compilation errors in C++ mode on Android.
	* lib/math.in.h: Declare nothing if this file gets included from
	/usr/include/c++/v1/math.h too early.

diff --git a/lib/math.in.h b/lib/math.in.h
index f3d58afc0d..a1cb22936b 100644
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -15,6 +15,11 @@
    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
+/* On Android, in C++ mode, when /usr/include/c++/v1/math.h is being included
+   and /usr/include/math.h has not yet been included, skip this file, since it
+   would lead to many syntax errors.  */
+#if !(defined __ANDROID__ && defined _LIBCPP_MATH_H && !defined INFINITY)
+
 #ifndef _@GUARD_PREFIX@_MATH_H
 
 #if __GNUC__ >= 3
@@ -2725,3 +2730,4 @@ _GL_INLINE_HEADER_END
 #endif /* _@GUARD_PREFIX@_MATH_H */
 #endif /* _GL_INCLUDING_MATH_H */
 #endif /* _@GUARD_PREFIX@_MATH_H */
+#endif





^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-10  9:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-10  9:03 math: Fix compilation errors in C++ mode on Android Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).