changeset 9201:472f0e22aa60

guard against implicit instantiation
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 15 May 2009 13:24:38 +0200
parents 72620af9cbaf
children 4b2147b25e8d
files liboctave/Array.cc liboctave/Array.h liboctave/ChangeLog
diffstat 3 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/Array.cc
+++ b/liboctave/Array.cc
@@ -2688,7 +2688,16 @@
   //     << prefix << "cols: " << cols () << "\n";
 }
 
+template <class T>
+void Array<T>::instantiation_guard ()
+{
+  // This guards against accidental implicit instantiations.
+  // Array<T> instances should always be explicit and use INSTANTIATE_ARRAY.
+  T::__xXxXx__();
+}
+
 #define INSTANTIATE_ARRAY(T, API) \
+  template <> void Array<T>::instantiation_guard () { } \
   template class API Array<T>
 
 /*
--- a/liboctave/Array.h
+++ b/liboctave/Array.h
@@ -629,6 +629,9 @@
   }
 
   template <class U> friend class Array;
+
+private:
+  static void instantiation_guard ();
 };
 
 #endif
--- a/liboctave/ChangeLog
+++ b/liboctave/ChangeLog
@@ -1,3 +1,9 @@
+2009-05-15  Jaroslav Hajek  <highegg@gmail.com>
+	
+	* Array.cc (Array<T>::instantiation_guard): New function
+	(INSTANTIATE_ARRAY): Always override it here.
+	* Array.h: Declare it.
+
 2009-05-15  Jaroslav Hajek  <highegg@gmail.com>
 
 	* ArrayN-idx.h: Remove file.