changeset 6:607e3be6bad8

Adjust to the moving target called the C++ standard. Apparently nowadays it's not allowed to define an explicit copy constructor but not an assignment operator. Consequently, defining the explicit copy constructor in terms of the implicit/automatic assignment operator for general convenience no longer works. Add assignment operators. Caution: not tested with the IBM compiler, but there's no particular reason it shouldn't work.
author David A. Holland
date Mon, 30 May 2022 23:46:22 -0400
parents 7661c1604e49
children 57b2cc9b87f7
files anagram/agcore/keyword.cpp anagram/agcore/keyword.h anagram/agcore/rpz.cpp anagram/agcore/rule.cpp anagram/agcore/rule.h anagram/agcore/symbol.cpp anagram/agcore/symbol.h anagram/agcore/token.cpp anagram/agcore/token.h anagram/agcore/tree.cpp anagram/agcore/tree.h anagram/support/agarray-imp.h anagram/support/agarray.h anagram/support/cint.h examples/dsl/redirect.cpp examples/dsl/redirect.h oldclasslib/README.txt oldclasslib/include/charsink.h oldclasslib/include/strdict.h oldclasslib/source/charsink.cpp oldclasslib/source/strdict.cpp
diffstat 21 files changed, 98 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/anagram/agcore/keyword.cpp	Mon May 30 23:32:56 2022 -0400
+++ b/anagram/agcore/keyword.cpp	Mon May 30 23:46:22 2022 -0400
@@ -332,6 +332,10 @@
   : KeyedObjectRegister<KeywordDescriptor>(t)
 {}
 
+void Keyword::operator = (const Keyword &t) {
+  KeyedObjectRegister<KeywordDescriptor>::operator = (t);
+}
+
 Keyword::Keyword(const char *x)
   : KeyedObjectRegister<KeywordDescriptor>(KeywordDescriptor(x))
 {}
--- a/anagram/agcore/keyword.h	Mon May 30 23:32:56 2022 -0400
+++ b/anagram/agcore/keyword.h	Mon May 30 23:46:22 2022 -0400
@@ -21,6 +21,7 @@
   Keyword(const char *x);
   Keyword(unsigned x);
   Keyword(const Keyword &t);
+  void operator = (const Keyword &t);
 
   static void reset();
   static Keyword create();
--- a/anagram/agcore/rpz.cpp	Mon May 30 23:32:56 2022 -0400
+++ b/anagram/agcore/rpz.cpp	Mon May 30 23:46:22 2022 -0400
@@ -319,7 +319,8 @@
     sis(tn);
     return;
   }
-  tn = n->token_number = Token::create();
+  n->token_number = Token::create();
+  tn = n->token_number;
   tn->token_name = n;
   tn->value_type = 0;
   if (!flag && n->parse_tree.isNotNull()) {
@@ -356,7 +357,8 @@
   rcs();
   LOGV((int) keyword->token_number);
   if (keyword->token_number.isNull()) {
-    Token token = keyword->token_number = Token::create();
+    keyword->token_number = Token::create();
+    Token token = keyword->token_number;
     LOGV((int) token);
     token->key = keyword;
     token->value_type = void_token_type;
--- a/anagram/agcore/rule.cpp	Mon May 30 23:32:56 2022 -0400
+++ b/anagram/agcore/rule.cpp	Mon May 30 23:46:22 2022 -0400
@@ -44,6 +44,9 @@
 Rule::Rule() : ObjectRegister<RuleDescriptor>() {}
 Rule::Rule(int x) : ObjectRegister<RuleDescriptor>(x) {}
 Rule::Rule(const Rule &t) : ObjectRegister<RuleDescriptor>(t) {}
+void Rule::operator = (const Rule &t) {
+   ObjectRegister<RuleDescriptor>::operator = (t);
+}
 
   
 RuleDescriptor &Rule::Map::operator [] (unsigned x) {
@@ -216,7 +219,7 @@
 int VpRuleDescriptor::operator < (const VpRuleDescriptor x) const {
   if (elementList < x.elementList) return 1;
   if (x.elementList < elementList) return 0;
-  return procedureName < procedureName;
+  return procedureName < x.procedureName;
 }
 
 VpRule::VpRule() : KeyedObjectRegister<VpRuleDescriptor>() {}
--- a/anagram/agcore/rule.h	Mon May 30 23:32:56 2022 -0400
+++ b/anagram/agcore/rule.h	Mon May 30 23:46:22 2022 -0400
@@ -24,6 +24,7 @@
   Rule();// {}
   Rule(int x);
   Rule(const Rule &t);
+  void operator = (const Rule &);
   Token &token(int) const;
 
   static Rule create();
--- a/anagram/agcore/symbol.cpp	Mon May 30 23:32:56 2022 -0400
+++ b/anagram/agcore/symbol.cpp	Mon May 30 23:46:22 2022 -0400
@@ -22,6 +22,10 @@
   // Nothing to do
 }
 
+void Symbol::operator = (const Symbol &t) {
+  KeyedObjectRegister<SymbolDescriptor>::operator = (t);
+}
+
 void Symbol::reset() {
   LOGSECTION("Symbol::reset");
   KeyedObjectRegister<SymbolDescriptor>::reset();
--- a/anagram/agcore/symbol.h	Mon May 30 23:32:56 2022 -0400
+++ b/anagram/agcore/symbol.h	Mon May 30 23:46:22 2022 -0400
@@ -20,6 +20,7 @@
   Symbol(const char *x);
   Symbol(unsigned x);
   Symbol(const Symbol &t);
+  void operator = (const Symbol &t);
   static void reset();
   static Symbol create();
   static Symbol sorted(int x);
--- a/anagram/agcore/token.cpp	Mon May 30 23:32:56 2022 -0400
+++ b/anagram/agcore/token.cpp	Mon May 30 23:46:22 2022 -0400
@@ -56,7 +56,9 @@
 
 Token::Token(int x) : ObjectRegister<token_number_map>(x) {}
 Token::Token(const Token &t) : ObjectRegister<token_number_map>(t) {}
-
+void Token::operator = (const Token &t) {
+   ObjectRegister<token_number_map>::operator = (t);
+}
 
 Token Token::create() {
   LOGSECTION("Token::create");
--- a/anagram/agcore/token.h	Mon May 30 23:32:56 2022 -0400
+++ b/anagram/agcore/token.h	Mon May 30 23:46:22 2022 -0400
@@ -20,6 +20,7 @@
   Token() {}
   Token(int x);
   Token(const Token &t);
+  void operator = (const Token &);
   static Token create();
   static const int first;
   static void reset();
--- a/anagram/agcore/tree.cpp	Mon May 30 23:32:56 2022 -0400
+++ b/anagram/agcore/tree.cpp	Mon May 30 23:46:22 2022 -0400
@@ -37,6 +37,10 @@
   : KeyedObjectRegister<parse_tree_map>(t)
 {}
 
+void ParseTree::operator = (const ParseTree &t) {
+  KeyedObjectRegister<parse_tree_map>::operator = (t);
+}
+
 ParseTree::ParseTree(CharSetExpression *x)
   : KeyedObjectRegister<parse_tree_map>(parse_tree_map(x))
 {
--- a/anagram/agcore/tree.h	Mon May 30 23:32:56 2022 -0400
+++ b/anagram/agcore/tree.h	Mon May 30 23:46:22 2022 -0400
@@ -21,6 +21,7 @@
   ParseTree(unsigned x);
   ParseTree(const ParseTree &t);
   ParseTree(CharSetExpression *x);
+  void operator = (const ParseTree &t);
   static void reset();
 
   class Map;
--- a/anagram/support/agarray-imp.h	Mon May 30 23:32:56 2022 -0400
+++ b/anagram/support/agarray-imp.h	Mon May 30 23:46:22 2022 -0400
@@ -91,6 +91,18 @@
 }
 
 template <class T>
+AgArray<T>::AgArray(const AgArray<T> &c)
+  : AgReferenceBase(c.size() ? new Kernel(c.size()) : 0)
+{
+  //LOGSECTION("AgArray::AgArray(AgArray)");
+  //LOGV(c.size());
+  int n = c.size();
+  for (int i = 0; i < n; i++) {
+    (*this)[i] = c[i];
+  }
+}
+
+template <class T>
 void AgArray<T>::copy(T *s, unsigned n) {
   T *data = kernel().data;
   assert(n <= kernel().length);
--- a/anagram/support/agarray.h	Mon May 30 23:32:56 2022 -0400
+++ b/anagram/support/agarray.h	Mon May 30 23:46:22 2022 -0400
@@ -47,6 +47,7 @@
   AgArray();
   inline AgArray(unsigned n) : AgReferenceBase(n ? new Kernel(n) : 0) {}
   AgArray(const AgIndexedContainer<T> &);
+  AgArray(const AgArray<T> &);
 
   void reset() { discardData(); }
 
--- a/anagram/support/cint.h	Mon May 30 23:32:56 2022 -0400
+++ b/anagram/support/cint.h	Mon May 30 23:46:22 2022 -0400
@@ -38,6 +38,12 @@
   }
 #endif
 
+  cint operator = (cint r) {
+     x = r.x;
+     y = r.y;
+     return r;
+  }
+
   int operator == (const cint r) const { return (x == r.x && y == r.y); }
   int operator != (const cint r) const { return (x != r.x || y != r.y); }
   cint operator + (cint r) const {
--- a/examples/dsl/redirect.cpp	Mon May 30 23:32:56 2022 -0400
+++ b/examples/dsl/redirect.cpp	Mon May 30 23:46:22 2022 -0400
@@ -64,7 +64,14 @@
   copy_flag = 0;                            // live
 }
 
-redirect::redirect(redirect &r) {
+void redirect::operator = (const redirect &r) {
+  handle = r.handle;
+  old_handle = r.old_handle;
+  strcpy(name, r.name);
+  copy_flag = r.copy_flag;
+}
+
+redirect::redirect(const redirect &r) {
   *this = r;
   copy_flag++;                              // memorex
 }
--- a/examples/dsl/redirect.h	Mon May 30 23:32:56 2022 -0400
+++ b/examples/dsl/redirect.h	Mon May 30 23:46:22 2022 -0400
@@ -59,7 +59,8 @@
 // Constructors
   redirect(int h);
   redirect(int h, char *file_name, int append_flag = 0);
-  redirect(redirect &);
+  redirect(const redirect &);
+  void operator = (const redirect &);
 
 // Reset
   friend redirect &reset(redirect &e) {
--- a/oldclasslib/README.txt	Mon May 30 23:32:56 2022 -0400
+++ b/oldclasslib/README.txt	Mon May 30 23:46:22 2022 -0400
@@ -31,3 +31,7 @@
 as well as using the provided operator[] directly. This seems stupid
 bordering on insane, but when compilers start citing the standard at
 you there isn't much choice but to go along.
+
+- Added explicit assignment operator definitions in places where gcc
+10.x now refuses to produce them automatically. Added missing "const"
+to some of the copy constructor arguments.
--- a/oldclasslib/include/charsink.h	Mon May 30 23:32:56 2022 -0400
+++ b/oldclasslib/include/charsink.h	Mon May 30 23:46:22 2022 -0400
@@ -67,7 +67,14 @@
     error_flag = copy_flag = 0;
   }
 
-  output_file(output_file &f) : character_sink() {
+  void operator = (const output_file &f) {
+     file = f.file;
+     name = f.name;
+     error_flag = f.error_flag;
+     copy_flag = f.copy_flag;
+  }
+
+  output_file(const output_file &f) : character_sink() {
     *this = f;
     copy_flag++;
   }
@@ -123,6 +130,7 @@
 
   string_accumulator(int nc, int nx = 1);
   string_accumulator(const string_accumulator &);
+  void operator = (const string_accumulator &);
 
 
 // Destructor
--- a/oldclasslib/include/strdict.h	Mon May 30 23:32:56 2022 -0400
+++ b/oldclasslib/include/strdict.h	Mon May 30 23:46:22 2022 -0400
@@ -45,8 +45,9 @@
 
   string_dictionary(unsigned size, unsigned word_length = 10);
 
-  string_dictionary(string_dictionary &);
+  string_dictionary(const string_dictionary &);
 
+  void operator = (const string_dictionary &);
 
 // Destructor
 
--- a/oldclasslib/source/charsink.cpp	Mon May 30 23:32:56 2022 -0400
+++ b/oldclasslib/source/charsink.cpp	Mon May 30 23:46:22 2022 -0400
@@ -63,6 +63,16 @@
 
 // Copy constructor
 
+void string_accumulator::operator = (const string_accumulator &s) {
+  cs = s.cs;
+  xs = s.xs;
+  csx = s.csx;
+  xsx = s.xsx;
+  csmax = s.csmax;
+  xsmax = s.xsmax;
+  copy_flag = s.copy_flag;
+}
+
 string_accumulator::string_accumulator(const string_accumulator &s) 
   : character_sink()
 {
--- a/oldclasslib/source/strdict.cpp	Mon May 30 23:32:56 2022 -0400
+++ b/oldclasslib/source/strdict.cpp	Mon May 30 23:46:22 2022 -0400
@@ -46,7 +46,22 @@
   copy_flag = 0;                           // live
 }
 
-string_dictionary::string_dictionary(string_dictionary &s) {
+void string_dictionary::operator = (const string_dictionary &s) {
+  sxs = s.sxs;
+  cs = s.cs;
+  csx = s.csx;
+  csxmax = s.csxmax;
+  ns = s.ns;
+  nsmax = s.nsmax;
+  ht = s.ht;
+  htl = s.htl;
+  htmask = s.htmask;
+  n_calls = s.n_calls;
+  n_collisions = s.n_collisions;
+  copy_flag = s.copy_flag;
+}
+
+string_dictionary::string_dictionary(const string_dictionary &s) {
   *this = s;
   copy_flag++;                             //memorex
 }