diff -r 51c1ec321aad libinterp/octave-value/ovl.h
--- a/libinterp/octave-value/ovl.h	Mon Feb 27 12:31:02 2023 -0500
+++ b/libinterp/octave-value/ovl.h	Mon Feb 27 13:12:50 2023 -0500
@@ -182,6 +182,11 @@ public:
     m_names = std::make_shared<string_vector> (nm);
   }
 
+  void stash_name_tags (std::shared_ptr<string_vector> nm)
+  {
+    m_names = nm;
+  }
+
   string_vector name_tags (void) const
   {
     return m_names ? *m_names : string_vector {};
diff -r 51c1ec321aad libinterp/parse-tree/pt-idx.cc
--- a/libinterp/parse-tree/pt-idx.cc	Mon Feb 27 12:31:02 2023 -0500
+++ b/libinterp/parse-tree/pt-idx.cc	Mon Feb 27 13:12:50 2023 -0500
@@ -82,7 +82,9 @@ tree_index_expression::append (tree_argu
 {
   m_args.push_back (lst);
   m_type.append (1, t);
-  m_arg_nm.push_back (lst ? lst->get_arg_names () : string_vector ());
+  m_arg_nm.push_back (lst ?
+                      std::make_shared<string_vector>(lst->get_arg_names ()) :
+                      std::make_shared<string_vector>(string_vector ()));
   m_dyn_field.push_back (static_cast<tree_expression *> (nullptr));
 
   if (lst && lst->has_magic_tilde ())
@@ -96,7 +98,7 @@ tree_index_expression::append (const std
 {
   m_args.push_back (static_cast<tree_argument_list *> (nullptr));
   m_type += '.';
-  m_arg_nm.push_back (n);
+  m_arg_nm.push_back (std::make_shared<string_vector>(n));
   m_dyn_field.push_back (static_cast<tree_expression *> (nullptr));
 
   return this;
@@ -107,7 +109,7 @@ tree_index_expression::append (tree_expr
 {
   m_args.push_back (static_cast<tree_argument_list *> (nullptr));
   m_type += '.';
-  m_arg_nm.push_back ("");
+  m_arg_nm.push_back (std::make_shared<string_vector>(""));
   m_dyn_field.push_back (df);
 
   return this;
@@ -143,11 +145,11 @@ tree_index_expression::name () const
 
 std::string
 tree_index_expression::get_struct_index
-(tree_evaluator& tw,
- std::list<string_vector>::const_iterator p_arg_nm,
- std::list<tree_expression *>::const_iterator p_dyn_field) const
+( tree_evaluator& tw,
+  std::list<std::shared_ptr<string_vector>>::const_iterator p_arg_nm,
+  std::list<tree_expression *>::const_iterator p_dyn_field) const
 {
-  std::string fn = (*p_arg_nm)(0);
+  std::string fn = (**p_arg_nm)(0);
 
   if (fn.empty ())
     {
@@ -197,7 +199,7 @@ tree_index_expression::lvalue (tree_eval
         {
         case '(':
           {
-            octave_value_list tidx = tw.make_value_list (*p_args, *p_arg_nm);
+            octave_value_list tidx = tw.make_value_list (*p_args, **p_arg_nm);
 
             tw.append_index_list ('(', tidx);
             idx.push_back (tidx);
@@ -206,7 +208,7 @@ tree_index_expression::lvalue (tree_eval
 
         case '{':
           {
-            octave_value_list tidx = tw.make_value_list (*p_args, *p_arg_nm);
+            octave_value_list tidx = tw.make_value_list (*p_args, **p_arg_nm);
 
             tw.append_index_list ('{', tidx);
             idx.push_back (tidx);
@@ -399,11 +401,9 @@ tree_index_expression::evaluate_n (tree_
 
               tw.set_lvalue_list (nullptr);
 
-              string_vector anm = *p_arg_nm;
-
               first_args = tw.convert_to_const_vector (al);
 
-              first_args.stash_name_tags (anm);
+              first_args.stash_name_tags (*p_arg_nm);
             }
 
           interpreter& interp = tw.get_interpreter ();
@@ -556,7 +556,7 @@ tree_index_expression::evaluate_n (tree_
           {
           case '(':
             {
-              octave_value_list tmp = tw.make_value_list (*p_args, *p_arg_nm);
+              octave_value_list tmp = tw.make_value_list (*p_args, **p_arg_nm);
               tw.append_index_list ('(', tmp);
               idx_list.push_back (tmp);
             }
@@ -564,7 +564,7 @@ tree_index_expression::evaluate_n (tree_
 
           case '{':
             {
-              octave_value_list tmp = tw.make_value_list (*p_args, *p_arg_nm);
+              octave_value_list tmp = tw.make_value_list (*p_args, **p_arg_nm);
               tw.append_index_list ('{', tmp);
               idx_list.push_back (tmp);
             }
diff -r 51c1ec321aad libinterp/parse-tree/pt-idx.h
--- a/libinterp/parse-tree/pt-idx.h	Mon Feb 27 12:31:02 2023 -0500
+++ b/libinterp/parse-tree/pt-idx.h	Mon Feb 27 13:12:50 2023 -0500
@@ -83,7 +83,7 @@ public:
 
   std::string type_tags () { return m_type; }
 
-  std::list<string_vector> arg_names () { return m_arg_nm; }
+  std::list<std::shared_ptr<string_vector>> arg_names () { return m_arg_nm; }
 
   std::list<tree_expression *> dyn_fields () { return m_dyn_field; }
 
@@ -115,8 +115,9 @@ public:
 
   std::string
   get_struct_index
-  (tree_evaluator& tw, std::list<string_vector>::const_iterator p_arg_nm,
-   std::list<tree_expression *>::const_iterator p_dyn_field) const;
+  ( tree_evaluator& tw,
+    std::list<std::shared_ptr<string_vector>>::const_iterator p_arg_nm,
+    std::list<tree_expression *>::const_iterator p_dyn_field) const;
 
 private:
 
@@ -131,7 +132,7 @@ private:
 
   // The names of the arguments.  Used for constant struct element
   // references.
-  std::list<string_vector> m_arg_nm;
+  std::list<std::shared_ptr<string_vector>> m_arg_nm;
 
   // The list of dynamic field names, if any.
   std::list<tree_expression *> m_dyn_field;
diff -r 51c1ec321aad libinterp/parse-tree/pt-pr-code.cc
--- a/libinterp/parse-tree/pt-pr-code.cc	Mon Feb 27 12:31:02 2023 -0500
+++ b/libinterp/parse-tree/pt-pr-code.cc	Mon Feb 27 13:12:50 2023 -0500
@@ -550,7 +550,7 @@ tree_print_code::visit_index_expression 
 
   std::list<tree_argument_list *> arg_lists = expr.arg_lists ();
   std::string type_tags = expr.type_tags ();
-  std::list<string_vector> arg_names = expr.arg_names ();
+  std::list<std::shared_ptr<string_vector>> arg_names = expr.arg_names ();
   std::list<tree_expression *> dyn_fields = expr.dyn_fields ();
 
   int n = type_tags.length ();
@@ -603,7 +603,7 @@ tree_print_code::visit_index_expression 
 
         case '.':
           {
-            std::string fn = (*p_arg_names)(0);
+            std::string fn = (**p_arg_names)(0);
             if (fn.empty ())
               {
                 tree_expression *df = *p_dyn_fields;
diff -r 51c1ec321aad libinterp/parse-tree/pt-walk.cc
--- a/libinterp/parse-tree/pt-walk.cc	Mon Feb 27 12:31:02 2023 -0500
+++ b/libinterp/parse-tree/pt-walk.cc	Mon Feb 27 13:12:50 2023 -0500
@@ -376,7 +376,7 @@ void tree_walker::visit_index_expression
     e->accept (*this);
 
   std::list<tree_argument_list *> arg_lists = expr.arg_lists ();
-  std::list<string_vector> arg_names = expr.arg_names ();
+  std::list<std::shared_ptr<string_vector>> arg_names = expr.arg_names ();
   std::list<tree_expression *> dyn_fields = expr.dyn_fields ();
 
   auto p_arg_lists = arg_lists.begin ();
@@ -401,7 +401,7 @@ void tree_walker::visit_index_expression
 
         case '.':
           {
-            std::string fn = (*p_arg_names)(0);
+            std::string fn = (**p_arg_names)(0);
             if (fn.empty ())
               {
                 tree_expression *df = *p_dyn_fields;
