changeset 31400:e7fc6251b698

Use more specialized API flags for template classes (bug #61711). * oct-conf-post-public.in.h: Add more specific attributes for exporting (specialized) template class instantiations. * liboctave/array/Array.h (Array<T>): Also dllexport member function definitions (on Windows). * Array-*.cc: Move extern template class declarations to before including "Array-base.cc" to avoid some implicit instantiations. * all files: Use new macros for visibility attributes.
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 05 Nov 2022 19:15:13 +0100
parents 4dc9230db992
children 21fd38c1f825 0783418ac443
files libinterp/template-inst/Array-tc.cc libinterp/template-inst/Array.cc liboctave/array/Array-C.cc liboctave/array/Array-b.cc liboctave/array/Array-base.cc liboctave/array/Array-ch.cc liboctave/array/Array-d.cc liboctave/array/Array-f.cc liboctave/array/Array-fC.cc liboctave/array/Array-fwd.h liboctave/array/Array-i.cc liboctave/array/Array-idx-vec.cc liboctave/array/Array-oct.cc liboctave/array/Array-s.cc liboctave/array/Array-str.cc liboctave/array/Array-voidp.cc liboctave/array/Array.h liboctave/array/MArray-C.cc liboctave/array/MArray-d.cc liboctave/array/MArray-f.cc liboctave/array/MArray-fC.cc liboctave/array/MArray-fwd.h liboctave/array/MArray-i.cc liboctave/array/MArray-s.cc liboctave/array/MArray.cc liboctave/array/Sparse-fwd.h liboctave/numeric/sparse-qr.h liboctave/util/oct-cmplx.h liboctave/util/oct-inttypes-fwd.h liboctave/util/oct-inttypes.cc liboctave/util/oct-inttypes.h liboctave/util/oct-sort.h oct-conf-post-public.in.h
diffstat 33 files changed, 418 insertions(+), 251 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/template-inst/Array-tc.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/libinterp/template-inst/Array-tc.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -29,7 +29,6 @@
 #  include "config.h"
 #endif
 
-#include "Array.h"
 #include "Array-oct.cc"
 
 #include "ov.h"
@@ -45,13 +44,13 @@
 #endif
 
 NO_INSTANTIATE_ARRAY_SORT_API (octave_value, OCTINTERP_API);
-INSTANTIATE_ARRAY (octave_value, OCTINTERP_API);
+INSTANTIATE_ARRAY (octave_value, OCTINTERP_CLASS_TEMPLATE_INSTANTIATION_API);
 
 NO_INSTANTIATE_ARRAY_SORT_API (octave_value *, OCTINTERP_API);
-INSTANTIATE_ARRAY (octave_value *, OCTINTERP_API);
+INSTANTIATE_ARRAY (octave_value *, OCTINTERP_CLASS_TEMPLATE_INSTANTIATION_API);
 
 NO_INSTANTIATE_ARRAY_SORT_API (octave::cdef_object, OCTINTERP_API);
-INSTANTIATE_ARRAY (octave::cdef_object, OCTINTERP_API);
+INSTANTIATE_ARRAY (octave::cdef_object, OCTINTERP_CLASS_TEMPLATE_INSTANTIATION_API);
 
 #if defined (HAVE_PRAGMA_GCC_VISIBILITY)
 #  pragma GCC visibility pop
--- a/libinterp/template-inst/Array.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/libinterp/template-inst/Array.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -33,6 +33,6 @@
 // being implicitly instantiated in compilation units including this file.
 
 // instantiated in Array-tc.cc
-extern template class Array<octave_value>;
-extern template class Array<octave_value *>;
-extern template class Array<octave::cdef_object>;
+extern template class OCTINTERP_EXTERN_TEMPLATE_API Array<octave_value>;
+extern template class OCTINTERP_EXTERN_TEMPLATE_API Array<octave_value *>;
+extern template class OCTINTERP_EXTERN_TEMPLATE_API Array<octave::cdef_object>;
--- a/liboctave/array/Array-C.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Array-C.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -33,15 +33,16 @@
 #include "lo-mappers.h"
 
 #include "Array.h"
-#include "Array-base.cc"
-#include "oct-sort.cc"
 
 // Prevent implicit instantiations on some systems (Windows, others?)
 // that can lead to duplicate definitions of static data members.
 
-extern template class Array<octave::idx_vector>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
 extern template class Array<octave_idx_type>;
 
+#include "Array-base.cc"
+#include "oct-sort.cc"
+
 template <>
 inline bool
 sort_isnan<Complex> (const Complex& x)
@@ -94,7 +95,7 @@
 
 template class octave_sort<Complex>;
 
-INSTANTIATE_ARRAY (Complex, OCTAVE_API);
+INSTANTIATE_ARRAY (Complex, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
 
 template OCTAVE_API std::ostream& operator << (std::ostream&,
                                                const Array<Complex>&);
--- a/liboctave/array/Array-b.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Array-b.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -30,18 +30,19 @@
 // Instantiate Arrays of bool values.
 
 #include "Array.h"
+
+// Prevent implicit instantiations on some systems (Windows, others?)
+// that can lead to duplicate definitions of static data members.
+
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
+extern template class Array<octave_idx_type>;
+
 #include "Array-base.cc"
 
 #define INLINE_ASCENDING_SORT 1
 #define INLINE_DESCENDING_SORT 1
 #include "oct-sort.cc"
 
-// Prevent implicit instantiations on some systems (Windows, others?)
-// that can lead to duplicate definitions of static data members.
-
-extern template class Array<octave::idx_vector>;
-extern template class Array<octave_idx_type>;
-
 // Specialize bool sorting (aka stable partitioning).
 
 template <bool desc>
@@ -120,7 +121,7 @@
 
 template class octave_sort<bool>;
 
-INSTANTIATE_ARRAY (bool, OCTAVE_API);
+INSTANTIATE_ARRAY (bool, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
 
 template OCTAVE_API std::ostream& operator << (std::ostream&,
                                                const Array<bool>&);
--- a/liboctave/array/Array-base.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Array-base.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -2792,19 +2792,11 @@
   T::__xXxXx__ ();
 }
 
-#if defined (__clang__)
-#  define INSTANTIATE_ARRAY(T, API)             \
+#define INSTANTIATE_ARRAY(T, API)               \
   template <> API void                          \
   Array<T>::instantiation_guard () { }          \
                                                 \
   template class API Array<T>
-#else
-#  define INSTANTIATE_ARRAY(T, API)             \
-  template <> API void                          \
-  Array<T>::instantiation_guard () { }          \
-                                                \
-  template class Array<T>
-#endif
 
 // FIXME: is this used?
 
--- a/liboctave/array/Array-ch.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Array-ch.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -30,21 +30,22 @@
 // Instantiate Arrays of char values.
 
 #include "Array.h"
+
+// Prevent implicit instantiations on some systems (Windows, others?)
+// that can lead to duplicate definitions of static data members.
+
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
+extern template class Array<octave_idx_type>;
+
 #include "Array-base.cc"
 
 #define INLINE_ASCENDING_SORT 1
 #define INLINE_DESCENDING_SORT 1
 #include "oct-sort.cc"
 
-// Prevent implicit instantiations on some systems (Windows, others?)
-// that can lead to duplicate definitions of static data members.
-
-extern template class Array<octave::idx_vector>;
-extern template class Array<octave_idx_type>;
-
 template class octave_sort<char>;
 
-INSTANTIATE_ARRAY (char, OCTAVE_API);
+INSTANTIATE_ARRAY (char, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
 
 template OCTAVE_API std::ostream& operator << (std::ostream&,
                                                const Array<char>&);
--- a/liboctave/array/Array-d.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Array-d.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -31,6 +31,13 @@
 
 #include "lo-mappers.h"
 #include "Array.h"
+
+// Prevent implicit instantiations on some systems (Windows, others?)
+// that can lead to duplicate definitions of static data members.
+
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
+extern template class Array<octave_idx_type>;
+
 #include "Array-base.cc"
 #include "oct-locbuf.h"
 
@@ -38,12 +45,6 @@
 #define INLINE_DESCENDING_SORT 1
 #include "oct-sort.cc"
 
-// Prevent implicit instantiations on some systems (Windows, others?)
-// that can lead to duplicate definitions of static data members.
-
-extern template class Array<octave::idx_vector>;
-extern template class Array<octave_idx_type>;
-
 template <>
 inline bool
 sort_isnan<double> (double x)
@@ -165,7 +166,7 @@
 
 template class octave_sort<double>;
 
-INSTANTIATE_ARRAY (double, OCTAVE_API);
+INSTANTIATE_ARRAY (double, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
 
 template OCTAVE_API std::ostream& operator << (std::ostream&,
                                                const Array<double>&);
--- a/liboctave/array/Array-f.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Array-f.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -31,6 +31,13 @@
 
 #include "lo-mappers.h"
 #include "Array.h"
+
+// Prevent implicit instantiations on some systems (Windows, others?)
+// that can lead to duplicate definitions of static data members.
+
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
+extern template class Array<octave_idx_type>;
+
 #include "Array-base.cc"
 #include "oct-locbuf.h"
 
@@ -38,12 +45,6 @@
 #define INLINE_DESCENDING_SORT 1
 #include "oct-sort.cc"
 
-// Prevent implicit instantiations on some systems (Windows, others?)
-// that can lead to duplicate definitions of static data members.
-
-extern template class Array<octave::idx_vector>;
-extern template class Array<octave_idx_type>;
-
 template <>
 inline bool
 sort_isnan<float> (float x)
@@ -165,7 +166,7 @@
 
 template class octave_sort<float>;
 
-INSTANTIATE_ARRAY (float, OCTAVE_API);
+INSTANTIATE_ARRAY (float, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
 
 template OCTAVE_API std::ostream& operator << (std::ostream&,
                                                const Array<float>&);
--- a/liboctave/array/Array-fC.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Array-fC.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -33,15 +33,16 @@
 #include "lo-mappers.h"
 
 #include "Array.h"
-#include "Array-base.cc"
-#include "oct-sort.cc"
 
 // Prevent implicit instantiations on some systems (Windows, others?)
 // that can lead to duplicate definitions of static data members.
 
-extern template class Array<octave::idx_vector>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
 extern template class Array<octave_idx_type>;
 
+#include "Array-base.cc"
+#include "oct-sort.cc"
+
 template <>
 inline bool
 sort_isnan<FloatComplex> (const FloatComplex& x)
@@ -94,7 +95,7 @@
 
 template class octave_sort<FloatComplex>;
 
-INSTANTIATE_ARRAY (FloatComplex, OCTAVE_API);
+INSTANTIATE_ARRAY (FloatComplex, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
 
 template OCTAVE_API std::ostream& operator << (std::ostream&,
                                                const Array<FloatComplex>&);
--- a/liboctave/array/Array-fwd.h	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Array-fwd.h	Sat Nov 05 19:15:13 2022 +0100
@@ -32,13 +32,13 @@
 #  include <memory_resource>
 
 template <typename T, typename Alloc = std::pmr::polymorphic_allocator<T>>
-class OCTARRAY_API Array;
+class OCTAVE_TEMPLATE_API Array;
 
 #else
 #  include <memory>
 
 template <typename T, typename Alloc = std::allocator<T>>
-class OCTARRAY_API Array;
+class OCTAVE_TEMPLATE_API Array;
 
 #endif
 
--- a/liboctave/array/Array-i.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Array-i.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -32,17 +32,18 @@
 // Instantiate Arrays of integer values.
 
 #include "Array.h"
+
+// Prevent implicit instantiations on some systems (Windows, others?)
+// that can lead to duplicate definitions of static data members.
+
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
+
 #include "Array-base.cc"
 
 #define INLINE_ASCENDING_SORT 1
 #define INLINE_DESCENDING_SORT 1
 #include "oct-sort.cc"
 
-// Prevent implicit instantiations on some systems (Windows, others?)
-// that can lead to duplicate definitions of static data members.
-
-extern template class Array<octave::idx_vector>;
-
 template class octave_sort<signed char>;
 //template class octave_sort<short>;
 template class octave_sort<int>;
@@ -51,12 +52,12 @@
 template class octave_sort<long long>;
 #endif
 
-INSTANTIATE_ARRAY (signed char, OCTAVE_API);
-//INSTANTIATE_ARRAY (short, OCTAVE_API);
-INSTANTIATE_ARRAY (int, OCTAVE_API);
-INSTANTIATE_ARRAY (long, OCTAVE_API);
+INSTANTIATE_ARRAY (signed char, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
+//INSTANTIATE_ARRAY (short, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_ARRAY (int, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_ARRAY (long, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
 #if defined (OCTAVE_HAVE_LONG_LONG_INT)
-INSTANTIATE_ARRAY (long long, OCTAVE_API);
+INSTANTIATE_ARRAY (long long, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
 #endif
 
 template class octave_sort<unsigned char>;
@@ -67,12 +68,12 @@
 template class octave_sort<unsigned long long>;
 #endif
 
-INSTANTIATE_ARRAY (unsigned char, OCTAVE_API);
-INSTANTIATE_ARRAY (unsigned short, OCTAVE_API);
-INSTANTIATE_ARRAY (unsigned int, OCTAVE_API);
-INSTANTIATE_ARRAY (unsigned long, OCTAVE_API);
+INSTANTIATE_ARRAY (unsigned char, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_ARRAY (unsigned short, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_ARRAY (unsigned int, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_ARRAY (unsigned long, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
 #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
-INSTANTIATE_ARRAY (unsigned long long, OCTAVE_API);
+INSTANTIATE_ARRAY (unsigned long long, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
 #endif
 
 template class octave_sort<octave_int8>;
@@ -80,20 +81,20 @@
 template class octave_sort<octave_int32>;
 template class octave_sort<octave_int64>;
 
-INSTANTIATE_ARRAY (octave_int8, OCTAVE_API);
-INSTANTIATE_ARRAY (octave_int16, OCTAVE_API);
-INSTANTIATE_ARRAY (octave_int32, OCTAVE_API);
-INSTANTIATE_ARRAY (octave_int64, OCTAVE_API);
+INSTANTIATE_ARRAY (octave_int8, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_ARRAY (octave_int16, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_ARRAY (octave_int32, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_ARRAY (octave_int64, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
 
 template class octave_sort<octave_uint8>;
 template class octave_sort<octave_uint16>;
 template class octave_sort<octave_uint32>;
 template class octave_sort<octave_uint64>;
 
-INSTANTIATE_ARRAY (octave_uint8, OCTAVE_API);
-INSTANTIATE_ARRAY (octave_uint16, OCTAVE_API);
-INSTANTIATE_ARRAY (octave_uint32, OCTAVE_API);
-INSTANTIATE_ARRAY (octave_uint64, OCTAVE_API);
+INSTANTIATE_ARRAY (octave_uint8, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_ARRAY (octave_uint16, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_ARRAY (octave_uint32, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_ARRAY (octave_uint64, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
 
 #include "DiagArray2.h"
 #include "DiagArray2.cc"
--- a/liboctave/array/Array-idx-vec.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Array-idx-vec.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -32,13 +32,14 @@
 #include "idx-vector.h"
 
 #include "Array.h"
-#include "Array-base.cc"
 
 // Prevent implicit instantiations on some systems (Windows, others?)
 // that can lead to duplicate definitions of static data members.
 
 extern template class Array<octave_idx_type>;
 
+#include "Array-base.cc"
+
 NO_INSTANTIATE_ARRAY_SORT_API (octave::idx_vector, OCTAVE_API);
 
-INSTANTIATE_ARRAY (octave::idx_vector, OCTAVE_API);
+INSTANTIATE_ARRAY (octave::idx_vector, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
--- a/liboctave/array/Array-oct.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Array-oct.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -27,49 +27,57 @@
 // Include this file when instantiating the Array class with new types in
 // projects linking to "liboctave" but not to "liboctinterp".
 
-#include "Array-base.cc"
+#include "Array.h"
+
+// FIXME: Including "Array.h" will have implicitly instantiated
+// Array<octave_idx_type>.  Could that be an issue?
 
-// "Protect" Array<T> instantiations that are exported by liboctave from being
-// implicitly instantiated in compilation units including this file.
+// "Protect" Array<T> instantiations that are exported by liboctave from
+// being implicitly instantiated in compilation units including this file.
+
+// Declare extern templates before including "Array-base.cc" to avoid
+// implicitly instantiating Array<octave::idx_vector>.
 
 // instantiated in Array-C.cc
-extern template class Array<Complex>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<Complex>;
 // instantiated in Array-b.cc
-extern template class Array<bool>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<bool>;
 // instantiated in Array-ch.cc
-extern template class Array<char>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<char>;
 // instantiated in Array-d.cc
-extern template class Array<double>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<double>;
 // instantiated in Array-f.cc
-extern template class Array<float>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<float>;
 // instantiated in Array-fC.cc
-extern template class Array<FloatComplex>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<FloatComplex>;
 // instantiated in Array-i.cc
-extern template class Array<signed char>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<signed char>;
 // extern template class Array<short>;
-extern template class Array<int>;
-extern template class Array<long>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<int>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<long>;
 #if defined (OCTAVE_HAVE_LONG_LONG_INT)
-extern template class Array<long long>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<long long>;
 #endif
-extern template class Array<unsigned char>;
-extern template class Array<unsigned short>;
-extern template class Array<unsigned int>;
-extern template class Array<unsigned long>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<unsigned char>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<unsigned short>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<unsigned int>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<unsigned long>;
 #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
-extern template class Array<unsigned long long>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<unsigned long long>;
 #endif
-extern template class Array<octave_int8>;
-extern template class Array<octave_int16>;
-extern template class Array<octave_int32>;
-extern template class Array<octave_int64>;
-extern template class Array<octave_uint8>;
-extern template class Array<octave_uint16>;
-extern template class Array<octave_uint32>;
-extern template class Array<octave_uint64>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave_int8>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave_int16>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave_int32>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave_int64>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave_uint8>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave_uint16>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave_uint32>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave_uint64>;
 // instantiated in Array-idx-vec.cc
-extern template class Array<octave::idx_vector>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
 // instantiated in Array-s.cc
-extern template class Array<short>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<short>;
 // instantiated in Array-str.cc
-extern template class Array<std::string>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<std::string>;
+
+#include "Array-base.cc"
--- a/liboctave/array/Array-s.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Array-s.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -30,21 +30,22 @@
 // Instantiate Arrays of short int values.
 
 #include "Array.h"
+
+// Prevent implicit instantiations on some systems (Windows, others?)
+// that can lead to duplicate definitions of static data members.
+
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
+extern template class Array<octave_idx_type>;
+
 #include "Array-base.cc"
 
 #define INLINE_ASCENDING_SORT 1
 #define INLINE_DESCENDING_SORT 1
 #include "oct-sort.cc"
 
-// Prevent implicit instantiations on some systems (Windows, others?)
-// that can lead to duplicate definitions of static data members.
-
-extern template class Array<octave::idx_vector>;
-extern template class Array<octave_idx_type>;
-
 template class octave_sort<short>;
 
-INSTANTIATE_ARRAY (short, OCTAVE_API);
+INSTANTIATE_ARRAY (short, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
 
 #include "DiagArray2.h"
 #include "DiagArray2.cc"
--- a/liboctave/array/Array-str.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Array-str.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -32,16 +32,17 @@
 // Instantiate Arrays of strings.
 
 #include "Array.h"
-#include "Array-base.cc"
-
-#include "oct-sort.cc"
 
 // Prevent implicit instantiations on some systems (Windows, others?)
 // that can lead to duplicate definitions of static data members.
 
-extern template class Array<octave::idx_vector>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
 extern template class Array<octave_idx_type>;
 
+#include "Array-base.cc"
+
+#include "oct-sort.cc"
+
 template class octave_sort<std::string>;
 
-INSTANTIATE_ARRAY (std::string, OCTAVE_API);
+INSTANTIATE_ARRAY (std::string, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
--- a/liboctave/array/Array-voidp.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Array-voidp.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -32,14 +32,15 @@
 // Instantiate Arrays of void *.
 
 #include "Array.h"
-#include "Array-base.cc"
 
 // Prevent implicit instantiations on some systems (Windows, others?)
 // that can lead to duplicate definitions of static data members.
 
-extern template class Array<octave::idx_vector>;
+extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
 extern template class Array<octave_idx_type>;
 
+#include "Array-base.cc"
+
 NO_INSTANTIATE_ARRAY_SORT_API (void *, OCTAVE_API);
 
-INSTANTIATE_ARRAY (void *, OCTAVE_API);
+INSTANTIATE_ARRAY (void *, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
--- a/liboctave/array/Array.h	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Array.h	Sat Nov 05 19:15:13 2022 +0100
@@ -125,6 +125,7 @@
 
 template <typename T, typename Alloc>
 class
+OCTARRAY_TEMPLATE_API
 Array
 {
 protected:
@@ -212,7 +213,7 @@
 
 public:
 
-  void make_unique (void)
+  OCTARRAY_OVERRIDABLE_FUNC_API void make_unique (void)
   {
     if (m_rep->m_count > 1)
       {
@@ -403,11 +404,14 @@
   { clear (dim_vector (r, c)); }
 
   //! Number of elements in the array.
-  octave_idx_type numel (void) const { return m_slice_len; }
+  OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type
+  numel (void) const
+  { return m_slice_len; }
   //@}
 
   //! Return the array as a column vector.
-  Array<T, Alloc> as_column (void) const
+  OCTARRAY_OVERRIDABLE_FUNC_API Array<T, Alloc>
+  as_column (void) const
   {
     Array<T, Alloc> retval (*this);
     if (m_dimensions.ndims () != 2 || m_dimensions(1) != 1)
@@ -417,7 +421,8 @@
   }
 
   //! Return the array as a row vector.
-  Array<T, Alloc> as_row (void) const
+  OCTARRAY_OVERRIDABLE_FUNC_API Array<T, Alloc>
+  as_row (void) const
   {
     Array<T, Alloc> retval (*this);
     if (m_dimensions.ndims () != 2 || m_dimensions(0) != 1)
@@ -427,7 +432,8 @@
   }
 
   //! Return the array as a matrix.
-  Array<T, Alloc> as_matrix (void) const
+  OCTARRAY_OVERRIDABLE_FUNC_API Array<T, Alloc>
+  as_matrix (void) const
   {
     Array<T, Alloc> retval (*this);
     if (m_dimensions.ndims () != 2)
@@ -440,25 +446,34 @@
   //!
   //! Get the first dimension of the array (number of rows)
   //@{
-  octave_idx_type dim1 (void) const { return m_dimensions(0); }
-  octave_idx_type rows (void) const { return dim1 (); }
+  OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type
+  dim1 (void) const
+  { return m_dimensions(0); }
+  OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type
+  rows (void) const
+  { return dim1 (); }
   //@}
 
   //! @name Second dimension
   //!
   //! Get the second dimension of the array (number of columns)
   //@{
-  octave_idx_type dim2 (void) const { return m_dimensions(1); }
-  octave_idx_type cols (void) const { return dim2 (); }
-  octave_idx_type columns (void) const { return dim2 (); }
+  OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type dim2 (void) const
+  { return m_dimensions(1); }
+  OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type cols (void) const
+  { return dim2 (); }
+  OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type columns (void) const
+  { return dim2 (); }
   //@}
 
   //! @name Third dimension
   //!
   //! Get the third dimension of the array (number of pages)
   //@{
-  octave_idx_type dim3 (void) const { return m_dimensions(2); }
-  octave_idx_type pages (void) const { return dim3 (); }
+  OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type dim3 (void) const
+  { return m_dimensions(2); }
+  OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type pages (void) const
+  { return dim3 (); }
   //@}
 
   //! Size of the specified dimension.
@@ -468,51 +483,63 @@
   //!
   //! Equivalent to Octave's 'size (A, DIM)'
 
-  size_type size (const size_type d) const
+  OCTARRAY_OVERRIDABLE_FUNC_API size_type size (const size_type d) const
   {
     // Should we throw for negative values?
     // Should >= ndims () be handled by dim_vector operator() instead ?
     return d >= ndims () ? 1 : m_dimensions(d);
   }
 
-  std::size_t byte_size (void) const
+  OCTARRAY_OVERRIDABLE_FUNC_API std::size_t byte_size (void) const
   { return static_cast<std::size_t> (numel ()) * sizeof (T); }
 
   //! Return a const-reference so that dims ()(i) works efficiently.
-  const dim_vector& dims (void) const { return m_dimensions; }
+  OCTARRAY_OVERRIDABLE_FUNC_API const dim_vector& dims (void) const
+  { return m_dimensions; }
 
   //! Chop off leading singleton dimensions
   OCTARRAY_API Array<T, Alloc> squeeze (void) const;
 
-  OCTARRAY_API octave_idx_type compute_index (octave_idx_type i, octave_idx_type j) const;
-  OCTARRAY_API octave_idx_type compute_index (octave_idx_type i, octave_idx_type j,
-                                 octave_idx_type k) const;
-  OCTARRAY_API octave_idx_type compute_index (const Array<octave_idx_type>& ra_idx) const;
+  OCTARRAY_API octave_idx_type
+  compute_index (octave_idx_type i, octave_idx_type j) const;
+  OCTARRAY_API octave_idx_type
+  compute_index (octave_idx_type i, octave_idx_type j, octave_idx_type k) const;
+  OCTARRAY_API octave_idx_type
+  compute_index (const Array<octave_idx_type>& ra_idx) const;
 
-  octave_idx_type compute_index_unchecked (const Array<octave_idx_type>& ra_idx) const
+  OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type
+  compute_index_unchecked (const Array<octave_idx_type>& ra_idx) const
   {
     return m_dimensions.compute_index (ra_idx.data (), ra_idx.numel ());
   }
 
   // No checking, even for multiple references, ever.
 
-  T& xelem (octave_idx_type n) { return m_slice_data[n]; }
-  crefT xelem (octave_idx_type n) const { return m_slice_data[n]; }
+  OCTARRAY_OVERRIDABLE_FUNC_API T& xelem (octave_idx_type n)
+  { return m_slice_data[n]; }
+  OCTARRAY_OVERRIDABLE_FUNC_API crefT xelem (octave_idx_type n) const
+  { return m_slice_data[n]; }
 
-  T& xelem (octave_idx_type i, octave_idx_type j)
+  OCTARRAY_OVERRIDABLE_FUNC_API T&
+  xelem (octave_idx_type i, octave_idx_type j)
   { return xelem (dim1 ()*j+i); }
-  crefT xelem (octave_idx_type i, octave_idx_type j) const
+  OCTARRAY_OVERRIDABLE_FUNC_API crefT
+  xelem (octave_idx_type i, octave_idx_type j) const
   { return xelem (dim1 ()*j+i); }
 
-  T& xelem (octave_idx_type i, octave_idx_type j, octave_idx_type k)
+  OCTARRAY_OVERRIDABLE_FUNC_API T&
+  xelem (octave_idx_type i, octave_idx_type j, octave_idx_type k)
   { return xelem (i, dim2 ()*k+j); }
-  crefT xelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const
+  OCTARRAY_OVERRIDABLE_FUNC_API crefT
+  xelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const
   { return xelem (i, dim2 ()*k+j); }
 
-  T& xelem (const Array<octave_idx_type>& ra_idx)
+  OCTARRAY_OVERRIDABLE_FUNC_API T&
+  xelem (const Array<octave_idx_type>& ra_idx)
   { return xelem (compute_index_unchecked (ra_idx)); }
 
-  crefT xelem (const Array<octave_idx_type>& ra_idx) const
+  OCTARRAY_OVERRIDABLE_FUNC_API crefT
+  xelem (const Array<octave_idx_type>& ra_idx) const
   { return xelem (compute_index_unchecked (ra_idx)); }
 
   // FIXME: would be nice to fix this so that we don't unnecessarily force
@@ -526,25 +553,28 @@
 
   OCTARRAY_API T& checkelem (const Array<octave_idx_type>& ra_idx);
 
-  T& elem (octave_idx_type n)
+  OCTARRAY_OVERRIDABLE_FUNC_API T& elem (octave_idx_type n)
   {
     make_unique ();
     return xelem (n);
   }
 
-  T& elem (octave_idx_type i, octave_idx_type j) { return elem (dim1 ()*j+i); }
+  OCTARRAY_OVERRIDABLE_FUNC_API T& elem (octave_idx_type i, octave_idx_type j)
+  { return elem (dim1 ()*j+i); }
 
-  T& elem (octave_idx_type i, octave_idx_type j, octave_idx_type k)
+  OCTARRAY_OVERRIDABLE_FUNC_API T& elem (octave_idx_type i, octave_idx_type j, octave_idx_type k)
   { return elem (i, dim2 ()*k+j); }
 
-  T& elem (const Array<octave_idx_type>& ra_idx)
+  OCTARRAY_OVERRIDABLE_FUNC_API T& elem (const Array<octave_idx_type>& ra_idx)
   { return Array<T, Alloc>::elem (compute_index_unchecked (ra_idx)); }
 
-  T& operator () (octave_idx_type n) { return elem (n); }
-  T& operator () (octave_idx_type i, octave_idx_type j) { return elem (i, j); }
-  T& operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k)
+  OCTARRAY_OVERRIDABLE_FUNC_API T& operator () (octave_idx_type n)
+  { return elem (n); }
+  OCTARRAY_OVERRIDABLE_FUNC_API T& operator () (octave_idx_type i, octave_idx_type j)
+  { return elem (i, j); }
+  OCTARRAY_OVERRIDABLE_FUNC_API T& operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k)
   { return elem (i, j, k); }
-  T& operator () (const Array<octave_idx_type>& ra_idx)
+  OCTARRAY_OVERRIDABLE_FUNC_API T& operator () (const Array<octave_idx_type>& ra_idx)
   { return elem (ra_idx); }
 
   OCTARRAY_API crefT checkelem (octave_idx_type n) const;
@@ -556,24 +586,31 @@
 
   OCTARRAY_API crefT checkelem (const Array<octave_idx_type>& ra_idx) const;
 
-  crefT elem (octave_idx_type n) const { return xelem (n); }
+  OCTARRAY_OVERRIDABLE_FUNC_API crefT elem (octave_idx_type n) const
+  { return xelem (n); }
 
-  crefT elem (octave_idx_type i, octave_idx_type j) const
+  OCTARRAY_OVERRIDABLE_FUNC_API crefT
+  elem (octave_idx_type i, octave_idx_type j) const
   { return xelem (i, j); }
 
-  crefT elem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const
+  OCTARRAY_OVERRIDABLE_FUNC_API crefT
+  elem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const
   { return xelem (i, j, k); }
 
-  crefT elem (const Array<octave_idx_type>& ra_idx) const
+  OCTARRAY_OVERRIDABLE_FUNC_API crefT
+  elem (const Array<octave_idx_type>& ra_idx) const
   { return Array<T, Alloc>::xelem (compute_index_unchecked (ra_idx)); }
 
-  crefT operator () (octave_idx_type n) const { return elem (n); }
-  crefT operator () (octave_idx_type i, octave_idx_type j) const
+  OCTARRAY_OVERRIDABLE_FUNC_API crefT
+  operator () (octave_idx_type n) const { return elem (n); }
+  OCTARRAY_OVERRIDABLE_FUNC_API crefT
+  operator () (octave_idx_type i, octave_idx_type j) const
   { return elem (i, j); }
-  crefT operator () (octave_idx_type i, octave_idx_type j,
-                     octave_idx_type k) const
+  OCTARRAY_OVERRIDABLE_FUNC_API crefT
+  operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) const
   { return elem (i, j, k); }
-  crefT operator () (const Array<octave_idx_type>& ra_idx) const
+  OCTARRAY_OVERRIDABLE_FUNC_API crefT
+  operator () (const Array<octave_idx_type>& ra_idx) const
   { return elem (ra_idx); }
 
   // Fast extractors.  All of these produce shallow copies.
@@ -585,41 +622,54 @@
 
   //! Extract a slice from this array as a column vector: A(:)(lo+1:up).
   //! Must be 0 <= lo && up <= numel.  May be up < lo.
-  OCTARRAY_API Array<T, Alloc> linear_slice (octave_idx_type lo, octave_idx_type up) const;
+  OCTARRAY_API Array<T, Alloc>
+  linear_slice (octave_idx_type lo, octave_idx_type up) const;
 
-  Array<T, Alloc> reshape (octave_idx_type nr, octave_idx_type nc) const
+  OCTARRAY_OVERRIDABLE_FUNC_API Array<T, Alloc>
+  reshape (octave_idx_type nr, octave_idx_type nc) const
   { return Array<T, Alloc> (*this, dim_vector (nr, nc)); }
 
-  Array<T, Alloc> reshape (const dim_vector& new_dims) const
+  OCTARRAY_OVERRIDABLE_FUNC_API Array<T, Alloc> 
+  reshape (const dim_vector& new_dims) const
   { return Array<T, Alloc> (*this, new_dims); }
 
-  OCTARRAY_API Array<T, Alloc> permute (const Array<octave_idx_type>& vec, bool inv = false) const;
-  Array<T, Alloc> ipermute (const Array<octave_idx_type>& vec) const
+  OCTARRAY_API Array<T, Alloc>
+  permute (const Array<octave_idx_type>& vec, bool inv = false) const;
+  OCTARRAY_OVERRIDABLE_FUNC_API Array<T, Alloc>
+  ipermute (const Array<octave_idx_type>& vec) const
   { return permute (vec, true); }
 
-  bool issquare (void) const { return (dim1 () == dim2 ()); }
+  OCTARRAY_OVERRIDABLE_FUNC_API bool issquare (void) const
+  { return (dim1 () == dim2 ()); }
 
-  bool isempty (void) const { return numel () == 0; }
+  OCTARRAY_OVERRIDABLE_FUNC_API bool isempty (void) const
+  { return numel () == 0; }
 
-  bool isvector (void) const { return m_dimensions.isvector (); }
+  OCTARRAY_OVERRIDABLE_FUNC_API bool isvector (void) const
+  { return m_dimensions.isvector (); }
 
-  bool is_nd_vector (void) const { return m_dimensions.is_nd_vector (); }
+  OCTARRAY_OVERRIDABLE_FUNC_API bool is_nd_vector (void) const
+  { return m_dimensions.is_nd_vector (); }
 
   OCTARRAY_API Array<T, Alloc> transpose (void) const;
   OCTARRAY_API Array<T, Alloc> hermitian (T (*fcn) (const T&) = nullptr) const;
 
-  const T * data (void) const { return m_slice_data; }
+  OCTARRAY_OVERRIDABLE_FUNC_API const T * data (void) const
+  { return m_slice_data; }
 
 #if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS)
   OCTAVE_DEPRECATED (7, "for read-only access, use 'data' method instead")
-  const T * fortran_vec (void) const { return data (); }
+  OCTARRAY_OVERRIDABLE_FUNC_API const T * fortran_vec (void) const
+  { return data (); }
 #endif
 
   OCTARRAY_API T * fortran_vec (void);
 
-  bool is_shared (void) { return m_rep->m_count > 1; }
+  OCTARRAY_OVERRIDABLE_FUNC_API bool is_shared (void)
+  { return m_rep->m_count > 1; }
 
-  int ndims (void) const { return m_dimensions.ndims (); }
+  OCTARRAY_OVERRIDABLE_FUNC_API int ndims (void) const
+  { return m_dimensions.ndims (); }
 
   //@{
   //! Indexing without resizing.
@@ -635,16 +685,18 @@
   //@{
   //! Resizing (with fill).
   OCTARRAY_API void resize2 (octave_idx_type nr, octave_idx_type nc, const T& rfv);
-  void resize2 (octave_idx_type nr, octave_idx_type nc)
+  OCTARRAY_OVERRIDABLE_FUNC_API void resize2 (octave_idx_type nr, octave_idx_type nc)
   {
     resize2 (nr, nc, resize_fill_value ());
   }
 
   OCTARRAY_API void resize1 (octave_idx_type n, const T& rfv);
-  void resize1 (octave_idx_type n) { resize1 (n, resize_fill_value ()); }
+  OCTARRAY_OVERRIDABLE_FUNC_API void resize1 (octave_idx_type n)
+  { resize1 (n, resize_fill_value ()); }
 
   OCTARRAY_API void resize (const dim_vector& dv, const T& rfv);
-  void resize (const dim_vector& dv) { resize (dv, resize_fill_value ()); }
+  OCTARRAY_OVERRIDABLE_FUNC_API void resize (const dim_vector& dv)
+  { resize (dv, resize_fill_value ()); }
   //@}
 
   //@{
@@ -653,24 +705,29 @@
   // FIXME: this is really a corner case, that should better be
   // handled directly in liboctinterp.
 
-  OCTARRAY_API Array<T, Alloc> index (const octave::idx_vector& i, bool resize_ok, const T& rfv) const;
-  Array<T, Alloc> index (const octave::idx_vector& i, bool resize_ok) const
+  OCTARRAY_API Array<T, Alloc>
+  index (const octave::idx_vector& i, bool resize_ok, const T& rfv) const;
+  OCTARRAY_OVERRIDABLE_FUNC_API Array<T, Alloc>
+  index (const octave::idx_vector& i, bool resize_ok) const
   {
     return index (i, resize_ok, resize_fill_value ());
   }
 
-  OCTARRAY_API Array<T, Alloc> index (const octave::idx_vector& i, const octave::idx_vector& j,
-                               bool resize_ok,
-                               const T& rfv) const;
-  Array<T, Alloc> index (const octave::idx_vector& i, const octave::idx_vector& j,
-                  bool resize_ok) const
+  OCTARRAY_API Array<T, Alloc>
+  index (const octave::idx_vector& i, const octave::idx_vector& j,
+         bool resize_ok, const T& rfv) const;
+  OCTARRAY_OVERRIDABLE_FUNC_API Array<T, Alloc>
+  index (const octave::idx_vector& i, const octave::idx_vector& j,
+         bool resize_ok) const
   {
     return index (i, j, resize_ok, resize_fill_value ());
   }
 
-  OCTARRAY_API Array<T, Alloc> index (const Array<octave::idx_vector>& ia, bool resize_ok,
-                               const T& rfv) const;
-  Array<T, Alloc> index (const Array<octave::idx_vector>& ia, bool resize_ok) const
+  OCTARRAY_API Array<T, Alloc>
+  index (const Array<octave::idx_vector>& ia, bool resize_ok,
+         const T& rfv) const;
+  OCTARRAY_OVERRIDABLE_FUNC_API Array<T, Alloc>
+  index (const Array<octave::idx_vector>& ia, bool resize_ok) const
   {
     return index (ia, resize_ok, resize_fill_value ());
   }
@@ -678,22 +735,28 @@
 
   //@{
   //! Indexed assignment (always with resize & fill).
-  OCTARRAY_API void assign (const octave::idx_vector& i, const Array<T, Alloc>& rhs, const T& rfv);
-  void assign (const octave::idx_vector& i, const Array<T, Alloc>& rhs)
+  OCTARRAY_API void
+  assign (const octave::idx_vector& i, const Array<T, Alloc>& rhs, const T& rfv);
+  OCTARRAY_OVERRIDABLE_FUNC_API void
+  assign (const octave::idx_vector& i, const Array<T, Alloc>& rhs)
   {
     assign (i, rhs, resize_fill_value ());
   }
 
-  OCTARRAY_API void assign (const octave::idx_vector& i, const octave::idx_vector& j,
-                            const Array<T, Alloc>& rhs,
-                            const T& rfv);
-  void assign (const octave::idx_vector& i, const octave::idx_vector& j, const Array<T, Alloc>& rhs)
+  OCTARRAY_API void
+  assign (const octave::idx_vector& i, const octave::idx_vector& j,
+          const Array<T, Alloc>& rhs, const T& rfv);
+  OCTARRAY_OVERRIDABLE_FUNC_API void
+  assign (const octave::idx_vector& i, const octave::idx_vector& j,
+          const Array<T, Alloc>& rhs)
   {
     assign (i, j, rhs, resize_fill_value ());
   }
 
-  OCTARRAY_API void assign (const Array<octave::idx_vector>& ia, const Array<T, Alloc>& rhs, const T& rfv);
-  void assign (const Array<octave::idx_vector>& ia, const Array<T, Alloc>& rhs)
+  OCTARRAY_API void
+  assign (const Array<octave::idx_vector>& ia, const Array<T, Alloc>& rhs, const T& rfv);
+  OCTARRAY_OVERRIDABLE_FUNC_API void
+  assign (const Array<octave::idx_vector>& ia, const Array<T, Alloc>& rhs)
   {
     assign (ia, rhs, resize_fill_value ());
   }
@@ -716,12 +779,14 @@
   //! size (a) is [d1 d2 ... dN] and idx is [i1 i2 ... iN], this
   //! method is equivalent to x(i1:i1+d1-1, i2:i2+d2-1, ... ,
   //! iN:iN+dN-1) = a.
-  OCTARRAY_API Array<T, Alloc>& insert (const Array<T, Alloc>& a, const Array<octave_idx_type>& idx);
+  OCTARRAY_API Array<T, Alloc>&
+  insert (const Array<T, Alloc>& a, const Array<octave_idx_type>& idx);
 
   //! This is just a special case for idx = [r c 0 ...]
-  OCTARRAY_API Array<T, Alloc>& insert (const Array<T, Alloc>& a, octave_idx_type r, octave_idx_type c);
+  OCTARRAY_API Array<T, Alloc>&
+  insert (const Array<T, Alloc>& a, octave_idx_type r, octave_idx_type c);
 
-  void maybe_economize (void)
+  OCTARRAY_OVERRIDABLE_FUNC_API void maybe_economize (void)
   {
     if (m_rep->m_count == 1 && m_slice_len != m_rep->m_len)
       {
@@ -754,7 +819,7 @@
   //! Ditto, but for an array of values, specializing on the case when values
   //! are sorted.  NaNs get the value N.
   OCTARRAY_API Array<octave_idx_type> lookup (const Array<T, Alloc>& values,
-                                                sortmode mode = UNSORTED) const;
+                                              sortmode mode = UNSORTED) const;
 
   //! Count nonzero elements.
   OCTARRAY_API octave_idx_type nnz (void) const;
@@ -762,7 +827,7 @@
   //! Find indices of (at most n) nonzero elements.  If n is specified,
   //! backward specifies search from backward.
   OCTARRAY_API Array<octave_idx_type> find (octave_idx_type n = -1,
-                                              bool backward = false) const;
+                                            bool backward = false) const;
 
   //! Returns the n-th element in increasing order, using the same
   //! ordering as used for sort.  n can either be a scalar index or a
--- a/liboctave/array/MArray-C.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/MArray-C.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -34,7 +34,7 @@
 #include "MArray.h"
 #include "MArray.cc"
 
-INSTANTIATE_MARRAY (Complex, OCTAVE_API);
+INSTANTIATE_MARRAY (Complex, OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API);
 
 INSTANTIATE_MARRAY_FRIENDS (Complex, OCTAVE_API)
 
--- a/liboctave/array/MArray-d.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/MArray-d.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -32,7 +32,7 @@
 #include "MArray.h"
 #include "MArray.cc"
 
-INSTANTIATE_MARRAY (double, OCTAVE_API);
+INSTANTIATE_MARRAY (double, OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API);
 
 INSTANTIATE_MARRAY_FRIENDS (double, OCTAVE_API)
 
--- a/liboctave/array/MArray-f.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/MArray-f.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -32,7 +32,7 @@
 #include "MArray.h"
 #include "MArray.cc"
 
-INSTANTIATE_MARRAY (float, OCTAVE_API);
+INSTANTIATE_MARRAY (float, OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API);
 
 INSTANTIATE_MARRAY_FRIENDS (float, OCTAVE_API)
 
--- a/liboctave/array/MArray-fC.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/MArray-fC.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -34,7 +34,7 @@
 #include "MArray.h"
 #include "MArray.cc"
 
-INSTANTIATE_MARRAY (FloatComplex, OCTAVE_API);
+INSTANTIATE_MARRAY (FloatComplex, OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API);
 
 INSTANTIATE_MARRAY_FRIENDS (FloatComplex, OCTAVE_API)
 
--- a/liboctave/array/MArray-fwd.h	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/MArray-fwd.h	Sat Nov 05 19:15:13 2022 +0100
@@ -28,6 +28,6 @@
 
 #include "octave-config.h"
 
-template <typename T> class OCTARRAY_API MArray;
+template <typename T> class OCTAVE_TEMPLATE_API MArray;
 
 #endif
--- a/liboctave/array/MArray-i.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/MArray-i.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -34,9 +34,9 @@
 #include "MArray.h"
 #include "MArray.cc"
 
-INSTANTIATE_MARRAY (int, OCTAVE_API);
+INSTANTIATE_MARRAY (int, OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API);
 #if defined (OCTAVE_ENABLE_64)
-INSTANTIATE_MARRAY (int64_t, OCTAVE_API);
+INSTANTIATE_MARRAY (int64_t, OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API);
 #endif
 
 INSTANTIATE_MARRAY_FRIENDS (int, OCTAVE_API)
@@ -44,20 +44,20 @@
 INSTANTIATE_MARRAY_FRIENDS (int64_t, OCTAVE_API)
 #endif
 
-INSTANTIATE_MARRAY (octave_int8, OCTAVE_API);
-INSTANTIATE_MARRAY (octave_int16, OCTAVE_API);
-INSTANTIATE_MARRAY (octave_int32, OCTAVE_API);
-INSTANTIATE_MARRAY (octave_int64, OCTAVE_API);
+INSTANTIATE_MARRAY (octave_int8, OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_MARRAY (octave_int16, OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_MARRAY (octave_int32, OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_MARRAY (octave_int64, OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API);
 
 INSTANTIATE_MARRAY_FRIENDS (octave_int8, OCTAVE_API)
 INSTANTIATE_MARRAY_FRIENDS (octave_int16, OCTAVE_API)
 INSTANTIATE_MARRAY_FRIENDS (octave_int32, OCTAVE_API)
 INSTANTIATE_MARRAY_FRIENDS (octave_int64, OCTAVE_API)
 
-INSTANTIATE_MARRAY (octave_uint8, OCTAVE_API);
-INSTANTIATE_MARRAY (octave_uint16, OCTAVE_API);
-INSTANTIATE_MARRAY (octave_uint32, OCTAVE_API);
-INSTANTIATE_MARRAY (octave_uint64, OCTAVE_API);
+INSTANTIATE_MARRAY (octave_uint8, OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_MARRAY (octave_uint16, OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_MARRAY (octave_uint32, OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API);
+INSTANTIATE_MARRAY (octave_uint64, OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API);
 
 INSTANTIATE_MARRAY_FRIENDS (octave_uint8, OCTAVE_API)
 INSTANTIATE_MARRAY_FRIENDS (octave_uint16, OCTAVE_API)
--- a/liboctave/array/MArray-s.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/MArray-s.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -32,7 +32,7 @@
 #include "MArray.h"
 #include "MArray.cc"
 
-INSTANTIATE_MARRAY (short, OCTAVE_API);
+INSTANTIATE_MARRAY (short, OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API);
 
 INSTANTIATE_MARRAY_FRIENDS (short, OCTAVE_API)
 
--- a/liboctave/array/MArray.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/MArray.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -380,16 +380,8 @@
   T::__xXxXx__ ();
 }
 
-#if defined (__clang__)
-#  define INSTANTIATE_MARRAY(T, API)            \
+#define INSTANTIATE_MARRAY(T, API)            \
   template <> API void                          \
   MArray<T>::instantiation_guard () { }         \
                                                 \
   template class API MArray<T>
-#else
-#  define INSTANTIATE_MARRAY(T, API)            \
-  template <> API void                          \
-  MArray<T>::instantiation_guard () { }         \
-                                                \
-  template class MArray<T>
-#endif
--- a/liboctave/array/Sparse-fwd.h	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/array/Sparse-fwd.h	Sat Nov 05 19:15:13 2022 +0100
@@ -32,12 +32,12 @@
 #  include <memory_resource>
 
 template <typename T, typename Alloc = std::pmr::polymorphic_allocator<T>>
-class OCTAVE_API Sparse;
+class OCTAVE_TEMPLATE_API Sparse;
 
 #else
 
 template <typename T, typename Alloc = std::allocator<T>>
-class OCTARRAY_API Sparse;
+class OCTAVE_TEMPLATE_API Sparse;
 
 #endif
 
--- a/liboctave/numeric/sparse-qr.h	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/numeric/sparse-qr.h	Sat Nov 05 19:15:13 2022 +0100
@@ -111,13 +111,11 @@
       std::shared_ptr<sparse_qr_rep> m_rep;
     };
 
-#if defined (__clang__) || defined (_WIN32)
     // extern instantiations with set visibility/export/import attribute
 
-    extern template class OCTAVE_API sparse_qr<SparseMatrix>;
+    extern template class OCTAVE_EXTERN_TEMPLATE_API sparse_qr<SparseMatrix>;
 
-    extern template class OCTAVE_API sparse_qr<SparseComplexMatrix>;
-#endif
+    extern template class OCTAVE_EXTERN_TEMPLATE_API sparse_qr<SparseComplexMatrix>;
 
     // Provide qrsolve for backward compatibility.
 
--- a/liboctave/util/oct-cmplx.h	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/util/oct-cmplx.h	Sat Nov 05 19:15:13 2022 +0100
@@ -47,11 +47,11 @@
 
 // extern template instantiations
 # define EXT_INST_COMPLEXR_COMP(OP, T)                                       \
-    extern template OCTAVE_API                                               \
+    extern template OCTAVE_EXTERN_TEMPLATE_API                               \
     bool operator OP (const std::complex<T>& a, const std::complex<T>& b);   \
-    extern template OCTAVE_API                                               \
+    extern template OCTAVE_EXTERN_TEMPLATE_API                               \
     bool operator OP (const std::complex<T>& a, T b);                        \
-    extern template OCTAVE_API                                               \
+    extern template OCTAVE_EXTERN_TEMPLATE_API                               \
     bool operator OP (T a, const std::complex<T>& b);
 
 EXT_INST_COMPLEXR_COMP(>, double)
--- a/liboctave/util/oct-inttypes-fwd.h	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/util/oct-inttypes-fwd.h	Sat Nov 05 19:15:13 2022 +0100
@@ -28,7 +28,7 @@
 
 #include "octave-config.h"
 
-template <typename T> class OCTAVE_API octave_int;
+template <typename T> class OCTAVE_TEMPLATE_API octave_int;
 
 typedef octave_int<int8_t> octave_int8;
 typedef octave_int<int16_t> octave_int16;
--- a/liboctave/util/oct-inttypes.cc	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/util/oct-inttypes.cc	Sat Nov 05 19:15:13 2022 +0100
@@ -819,7 +819,7 @@
 }
 
 #define INSTANTIATE_INTTYPE(T)                                          \
-  template class octave_int<T>;                                         \
+  template class OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API octave_int<T>; \
                                                                         \
   template OCTAVE_API octave_int<T>                                     \
   pow (const octave_int<T>&, const octave_int<T>&);                     \
--- a/liboctave/util/oct-inttypes.h	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/util/oct-inttypes.h	Sat Nov 05 19:15:13 2022 +0100
@@ -779,7 +779,9 @@
 { };
 
 template <typename T>
-class octave_int : public octave_int_base<T>
+class
+OCTAVE_TEMPLATE_API
+octave_int : public octave_int_base<T>
 {
 public:
 
--- a/liboctave/util/oct-sort.h	Sun Nov 06 12:18:37 2022 +0100
+++ b/liboctave/util/oct-sort.h	Sat Nov 05 19:15:13 2022 +0100
@@ -98,7 +98,7 @@
 
 template <typename T>
 class
-OCTARRAY_API
+OCTAVE_TEMPLATE_API
 octave_sort
 {
 public:
@@ -348,7 +348,7 @@
 
 template <typename T>
 class
-OCTARRAY_API
+OCTAVE_TEMPLATE_API
 vec_index
 {
 public:
--- a/oct-conf-post-public.in.h	Sun Nov 06 12:18:37 2022 +0100
+++ b/oct-conf-post-public.in.h	Sat Nov 05 19:15:13 2022 +0100
@@ -134,39 +134,139 @@
 #  define OCTAVE_IMPORT
 #endif
 
-/* API macro for liboctave */
+/* API macros for liboctave */
 #if defined (OCTAVE_DLL)
 #  define OCTAVE_API OCTAVE_EXPORT
+#  if defined (_WIN32) || defined (__CYGWIN__)
+#    define OCTAVE_TEMPLATE_API
+#    if defined(__MINGW32__)
+#      define OCTAVE_EXTERN_TEMPLATE_API OCTAVE_EXPORT
+#      define OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API
+#    else
+#      define OCTAVE_EXTERN_TEMPLATE_API
+#      define OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API OCTAVE_EXPORT
+#    endif
+#    define OCTAVE_OVERRIDABLE_FUNC_API OCTAVE_EXPORT
+#  else
+#    define OCTAVE_TEMPLATE_API OCTAVE_EXPORT
+#    define OCTAVE_EXTERN_TEMPLATE_API OCTAVE_EXPORT
+#    define OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API
+#    define OCTAVE_OVERRIDABLE_FUNC_API
+#  endif
 #else
 #  define OCTAVE_API OCTAVE_IMPORT
+#  define OCTAVE_TEMPLATE_API
+#  define OCTAVE_EXTERN_TEMPLATE_API OCTAVE_IMPORT
+#  define OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API
+#  define OCTAVE_OVERRIDABLE_FUNC_API
 #endif
 
-/* API macro for liboctinterp */
+/* API macros for liboctinterp */
 #if defined (OCTINTERP_DLL)
 #  define OCTINTERP_API OCTAVE_EXPORT
+#  if defined (_WIN32) || defined (__CYGWIN__)
+#    define OCTINTERP_TEMPLATE_API
+#    if defined(__MINGW32__)
+#      define OCTINTERP_EXTERN_TEMPLATE_API OCTAVE_EXPORT
+#      define OCTINTERP_CLASS_TEMPLATE_INSTANTIATION_API
+#    else
+#      define OCTINTERP_EXTERN_TEMPLATE_API
+#      define OCTINTERP_CLASS_TEMPLATE_INSTANTIATION_API OCTAVE_EXPORT
+#    endif
+#    define OCTINTERP_OVERRIDABLE_FUNC_API OCTAVE_EXPORT
+#  else
+#    define OCTINTERP_TEMPLATE_API OCTAVE_EXPORT
+#    define OCTINTERP_EXTERN_TEMPLATE_API OCTAVE_EXPORT
+#    define OCTINTERP_CLASS_TEMPLATE_INSTANTIATION_API
+#    define OCTINTERP_OVERRIDABLE_FUNC_API
+#  endif
 #else
 #  define OCTINTERP_API OCTAVE_IMPORT
+#  define OCTINTERP_TEMPLATE_API
+#  define OCTINTERP_EXTERN_TEMPLATE_API OCTAVE_IMPORT
+#  define OCTINTERP_CLASS_TEMPLATE_INSTANTIATION_API
+#  define OCTINTERP_OVERRIDABLE_FUNC_API
 #endif
 
-/* API macro for the Array class in liboctave and liboctinterp */
+/* API macros for the Array class in liboctave and liboctinterp */
 #if (defined (OCTAVE_DLL) || defined (OCTINTERP_DLL))
 #  define OCTARRAY_API OCTAVE_EXPORT
+#  if defined (_WIN32) || defined (__CYGWIN__)
+#    define OCTARRAY_TEMPLATE_API
+#    if defined(__MINGW32__)
+#      define OCTARRAY_EXTERN_TEMPLATE_API OCTAVE_EXPORT
+#      define OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API
+#    else
+#      define OCTARRAY_EXTERN_TEMPLATE_API
+#      define OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API OCTAVE_EXPORT
+#    endif
+#    define OCTARRAY_OVERRIDABLE_FUNC_API OCTAVE_EXPORT
+#  else
+#    define OCTARRAY_TEMPLATE_API OCTAVE_EXPORT
+#    define OCTARRAY_EXTERN_TEMPLATE_API OCTAVE_EXPORT
+#    define OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API
+#    define OCTARRAY_OVERRIDABLE_FUNC_API
+#  endif
 #else
 #  define OCTARRAY_API OCTAVE_IMPORT
+#  define OCTARRAY_TEMPLATE_API
+#  define OCTARRAY_EXTERN_TEMPLATE_API OCTAVE_IMPORT
+#  define OCTARRAY_CLASS_TEMPLATE_INSTANTIATION_API
+#  define OCTARRAY_OVERRIDABLE_FUNC_API
 #endif
 
-/* API macro for libinterp/graphics */
+/* API macros for libinterp/graphics */
 #if defined (OCTGRAPHICS_DLL)
 #  define OCTGRAPHICS_API OCTAVE_EXPORT
+#  if defined (_WIN32) || defined (__CYGWIN__)
+#    define OCTGRAPHICS_TEMPLATE_API
+#    if defined(__MINGW32__)
+#      define OCTGRAPHICS_EXTERN_TEMPLATE_API OCTAVE_EXPORT
+#      define OCTGRAPHICS_CLASS_TEMPLATE_INSTANTIATION_API
+#    else
+#      define OCTGRAPHICS_EXTERN_TEMPLATE_API
+#      define OCTGRAPHICS_CLASS_TEMPLATE_INSTANTIATION_API OCTAVE_EXPORT
+#    endif
+#    define OCTGRAPHICS_OVERRIDABLE_FUNC_API OCTAVE_EXPORT
+#  else
+#    define OCTGRAPHICS_TEMPLATE_API OCTAVE_EXPORT
+#    define OCTGRAPHICS_EXTERN_TEMPLATE_API OCTAVE_EXPORT
+#    define OCTGRAPHICS_CLASS_TEMPLATE_INSTANTIATION_API
+#    define OCTGRAPHICS_OVERRIDABLE_FUNC_API
+#  endif
 #else
 #  define OCTGRAPHICS_API OCTAVE_IMPORT
+#  define OCTGRAPHICS_TEMPLATE_API
+#  define OCTGRAPHICS_EXTERN_TEMPLATE_API OCTAVE_IMPORT
+#  define OCTGRAPHICS_CLASS_TEMPLATE_INSTANTIATION_API
+#  define OCTGRAPHICS_OVERRIDABLE_FUNC_API
 #endif
 
-/* API macro for libgui */
+/* API macros for libgui */
 #if defined (OCTGUI_DLL)
 #  define OCTGUI_API OCTAVE_EXPORT
+#  if defined (_WIN32) || defined (__CYGWIN__)
+#    define OCTGUI_TEMPLATE_API
+#    if defined(__MINGW32__)
+#      define OCTGUI_EXTERN_TEMPLATE_API OCTAVE_EXPORT
+#      define OCTGUI_CLASS_TEMPLATE_INSTANTIATION_API
+#    else
+#      define OCTGUI_EXTERN_TEMPLATE_API
+#      define OCTGUI_CLASS_TEMPLATE_INSTANTIATION_API OCTAVE_EXPORT
+#    endif
+#    define OCTGUI_OVERRIDABLE_FUNC_API OCTAVE_EXPORT
+#  else
+#    define OCTGUI_TEMPLATE_API OCTAVE_EXPORT
+#    define OCTGUI_EXTERN_TEMPLATE_API OCTAVE_EXPORT
+#    define OCTGUI_CLASS_TEMPLATE_INSTANTIATION_API
+#    define OCTGUI_OVERRIDABLE_FUNC_API
+#  endif
 #else
 #  define OCTGUI_API OCTAVE_IMPORT
+#  define OCTGUI_TEMPLATE_API
+#  define OCTGUI_EXTERN_TEMPLATE_API OCTAVE_IMPORT
+#  define OCTGUI_CLASS_TEMPLATE_INSTANTIATION_API
+#  define OCTGUI_OVERRIDABLE_FUNC_API
 #endif
 
 #if defined (OCTAVE_ENABLE_64)