changeset 31818:758de955caca

Deprecate octave_base_value::count member variable. * NEWS.9.md: Announce deprecation of octave_base_value::count. * ov-base.h (count): Declare member variable "count" as a reference to true member variable "m_count". Use OCTAVE_DEPRECATED macro to mark "count" as deprecated for compiler. * ov-base.h (octave_base_value): Use #pragma to turn off warnings about deprecated declarations for the octave_base_value () constructor which initializes obsolete member variable "count".
author Rik <rik@octave.org>
date Tue, 07 Feb 2023 08:18:54 -0800
parents 90ce081eb281
children 4db921b57ace
files etc/NEWS.9.md libinterp/octave-value/ov-base.h
diffstat 2 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/etc/NEWS.9.md	Sat Feb 04 17:49:58 2023 -0800
+++ b/etc/NEWS.9.md	Tue Feb 07 08:18:54 2023 -0800
@@ -47,6 +47,8 @@
 is obsolete and always returns true.  Any uses can simply be removed from
 existing code with no loss of function.
 
+    * The member variable `octave_base_value::count` is deprecated and will be removed from Octave 11.  Replace all instances with the new name `m_count`.
+
 The following features were deprecated in Octave 7 and have been removed
 from Octave 9.
 
--- a/libinterp/octave-value/ov-base.h	Sat Feb 04 17:49:58 2023 -0800
+++ b/libinterp/octave-value/ov-base.h	Tue Feb 07 08:18:54 2023 -0800
@@ -262,9 +262,21 @@
 
   friend class octave_value;
 
-  octave_base_value () : m_count (1) { }
+#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
+   // Disable this warning for the use of the "count" member variable in
+   // the default constructor.  Push the current state so we can restore
+   // the warning state.
+#  pragma GCC diagnostic push
+#  pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
 
-  octave_base_value (const octave_base_value&) : m_count (1) { }
+  octave_base_value () : m_count (1), count (m_count) { }
+
+#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
+#  pragma GCC diagnostic pop
+#endif
+
+  octave_base_value (const octave_base_value&) : octave_base_value () { }
 
   virtual ~octave_base_value () = default;
 
@@ -915,6 +927,11 @@
   // (think of an empty cell array with >2G elements).
   octave::refcount<octave_idx_type> m_count;
 
+  // FIXME: Create an alias "count" to the real member variable m_count.
+  // This name is deprecated in Octave 9 and will be removed in Octave 11.
+  OCTAVE_DEPRECATED (9, "use octave_base_value::m_count instead")
+  octave::refcount<octave_idx_type>& count;
+
   OCTINTERP_API static const char * get_umap_name (unary_mapper_t);
 
   OCTINTERP_API void warn_load (const char *type) const;