changeset 21235:b48d65c5df5b stable

Disable char/int8_t function overloads where not permitted (bug #45411) * configure.ac (HAVE_OVERLOAD_CHAR_INT8_TYPES): Add test and conditional on whether the system allows overloads with char, int8_t, and uint8_t (e.g. Solaris does not). * oct_inttypes.h, oct-stream.cc: Use HAVE_OVERLOAD_CHAR_INT8_TYPES.
author Mike Miller <mtmiller@octave.org>
date Tue, 09 Feb 2016 11:54:02 -0800
parents 6b0ded11d708
children 7fcad8bbf7fa
files configure.ac libinterp/corefcn/oct-stream.cc liboctave/util/oct-inttypes.h
diffstat 3 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Tue Feb 09 10:34:35 2016 -0800
+++ b/configure.ac	Tue Feb 09 11:54:02 2016 -0800
@@ -2222,6 +2222,25 @@
 
 AC_STRUCT_TIMEZONE
 
+## Check if C++ compiler allows overload of char, int8_t, and uint8_t.
+AC_CACHE_CHECK([whether ${CXX-g++} allows overload of char, int8_t, and uint8_t],
+  [octave_cv_overload_char_int8_t],
+  [AC_LANG_PUSH(C++)
+  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+    #include <stdint.h>
+    void somefunc(char x) {};
+    void somefunc(int8_t x) {};
+    void somefunc(uint8_t x) {};
+    ]])],
+    octave_cv_overload_char_int8_t=yes,
+    octave_cv_overload_char_int8_t=no)
+  AC_LANG_POP(C++)
+  ])
+if test $octave_cv_overload_char_int8_t = yes; then
+  AC_DEFINE(HAVE_OVERLOAD_CHAR_INT8_TYPES, 1,
+    [Define to 1 if C++ allows overload of char, int8_t, and uint8_t types.])
+fi
+
 ### Check compiler characteristics.
 
 ## Does compiler have support for new friend template declarations?
--- a/libinterp/corefcn/oct-stream.cc	Tue Feb 09 10:34:35 2016 -0800
+++ b/libinterp/corefcn/oct-stream.cc	Tue Feb 09 11:54:02 2016 -0800
@@ -3884,7 +3884,9 @@
 INSTANTIATE_WRITE (int64_t);
 INSTANTIATE_WRITE (uint64_t);
 INSTANTIATE_WRITE (bool);
+#if defined (HAVE_OVERLOAD_CHAR_INT8_TYPES)
 INSTANTIATE_WRITE (char);
+#endif
 INSTANTIATE_WRITE (float);
 INSTANTIATE_WRITE (double);
 
--- a/liboctave/util/oct-inttypes.h	Tue Feb 09 10:34:35 2016 -0800
+++ b/liboctave/util/oct-inttypes.h	Tue Feb 09 11:54:02 2016 -0800
@@ -837,10 +837,12 @@
 
   octave_int (T i) : ival (i) { }
 
+#if defined (HAVE_OVERLOAD_CHAR_INT8_TYPES)
   // Always treat characters as unsigned.
   octave_int (char c)
     : ival (octave_int_base<T>::truncate_int (static_cast<unsigned char> (c)))
   { }
+#endif
 
   octave_int (double d) : ival (octave_int_base<T>::convert_real (d)) { }