From 98da514e23f8709348ddf377eba96aff85ebfc4b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Fri, 15 Apr 2022 14:16:13 +0200
Subject: [PATCH] Octave 7 compatibility fix: suppress spurious warnings
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In this version of Octave, “warning on” really enables all warnings (while this
was not the case in Octave 6, suprisingly; I think this used to be different
with even older Octave releases).

We must therefore avoid to reenable all warnings after having disabled a
problematic one.

(manually cherry picked from commit 43d4bafa36380e99f6ae4b3d3a3160fb9f1699c0)
---
 src/@page/page.m                   | 10 +++++++---
 src/@paragraph/paragraph.m         | 10 +++++++---
 src/@report/report.m               | 10 +++++++---
 src/@report_data/report_data.m     | 10 +++++++---
 src/@report_graph/report_graph.m   | 10 +++++++---
 src/@report_series/report_series.m | 10 +++++++---
 src/@report_table/report_table.m   | 10 +++++++---
 src/@section/section.m             | 10 +++++++---
 src/@vspace/vspace.m               | 10 +++++++---
 9 files changed, 63 insertions(+), 27 deletions(-)

diff --git a/src/@page/page.m b/src/@page/page.m
index 565c34e..efbac23 100644
--- a/src/@page/page.m
+++ b/src/@page/page.m
@@ -1,7 +1,7 @@
 classdef page < handle
     % page Class
     %
-    % Copyright (C) 2013-2019 Dynare Team
+    % Copyright (C) 2013-2022 Dynare Team
     %
     % This file is part of Dynare.
     %
@@ -65,9 +65,13 @@ classdef page < handle
             end
 
             % Octave 5.1.0 has not implemented `properties` and issues a warning when using `fieldnames`
-            warning('off')
+            if isoctave
+                warnstate = warning('off', 'Octave:classdef-to-struct');
+            end
             optNames = fieldnames(o);
-            warning('on')
+            if isoctave
+                warning(warnstate);
+            end
 
             % overwrite default values
             for pair = reshape(varargin, 2, [])
diff --git a/src/@paragraph/paragraph.m b/src/@paragraph/paragraph.m
index 85ff6b5..7ed293e 100644
--- a/src/@paragraph/paragraph.m
+++ b/src/@paragraph/paragraph.m
@@ -1,7 +1,7 @@
 classdef paragraph < handle
     % paragraph Class
     %
-    % Copyright (C) 2014-2019 Dynare Team
+    % Copyright (C) 2014-2022 Dynare Team
     %
     % This file is part of Dynare.
     %
@@ -54,9 +54,13 @@ classdef paragraph < handle
             end
 
             % Octave 5.1.0 has not implemented `properties` and issues a warning when using `fieldnames`
-            warning('off')
+            if isoctave
+                warnstate = warning('off', 'Octave:classdef-to-struct');
+            end
             optNames = fieldnames(o);
-            warning('on')
+            if isoctave
+                warning(warnstate);
+            end
 
             for pair = reshape(varargin, 2, [])
                 ind = find(strcmpi(optNames, pair{1}));
diff --git a/src/@report/report.m b/src/@report/report.m
index 858d686..e97eb30 100644
--- a/src/@report/report.m
+++ b/src/@report/report.m
@@ -1,7 +1,7 @@
 classdef report < handle
     % report Class
     %
-    % Copyright (C) 2013-2019 Dynare Team
+    % Copyright (C) 2013-2022 Dynare Team
     %
     % This file is part of Dynare.
     %
@@ -64,9 +64,13 @@ classdef report < handle
             end
 
             % Octave 5.1.0 has not implemented `properties` and issues a warning when using `fieldnames`
-            warning('off')
+            if isoctave
+                warnstate = warning('off', 'Octave:classdef-to-struct');
+            end
             optNames = fieldnames(o);
-            warning('on')
+            if isoctave
+                warning(warnstate);
+            end
 
             % overwrite default values
             for pair = reshape(varargin, 2, [])
diff --git a/src/@report_data/report_data.m b/src/@report_data/report_data.m
index bdc0b8f..9e8d63d 100644
--- a/src/@report_data/report_data.m
+++ b/src/@report_data/report_data.m
@@ -1,7 +1,7 @@
 classdef report_data < handle
     % report_data Class to write a page to the report
     %
-    % Copyright (C) 2019 Dynare Team
+    % Copyright (C) 2019-2022 Dynare Team
     %
     % This file is part of Dynare.
     %
@@ -57,9 +57,13 @@ classdef report_data < handle
             end
 
             % Octave 5.1.0 has not implemented `properties` and issues a warning when using `fieldnames`
-            warning('off')
+            if isoctave
+                warnstate = warning('off', 'Octave:classdef-to-struct');
+            end
             optNames = fieldnames(o);
-            warning('on')
+            if isoctave
+                warning(warnstate);
+            end
 
             % overwrite default values
             for pair = reshape(varargin, 2, [])
diff --git a/src/@report_graph/report_graph.m b/src/@report_graph/report_graph.m
index 0cddf17..ad6143e 100644
--- a/src/@report_graph/report_graph.m
+++ b/src/@report_graph/report_graph.m
@@ -1,7 +1,7 @@
 classdef report_graph < handle
     % report_graph Class
     %
-    % Copyright (C) 2013-2020 Dynare Team
+    % Copyright (C) 2013-2022 Dynare Team
     %
     % This file is part of Dynare.
     %
@@ -91,9 +91,13 @@ classdef report_graph < handle
                 end
 
                 % Octave 5.1.0 has not implemented `properties` and issues a warning when using `fieldnames`
-                warning('off')
+                if isoctave
+                    warnstate = warning('off', 'Octave:classdef-to-struct');
+                end
                 optNames = fieldnames(o);
-                warning('on')
+                if isoctave
+                    warning(warnstate);
+                end
 
                 % overwrite default values
                 for pair = reshape(varargin, 2, [])
diff --git a/src/@report_series/report_series.m b/src/@report_series/report_series.m
index bbd02fd..daedc5b 100644
--- a/src/@report_series/report_series.m
+++ b/src/@report_series/report_series.m
@@ -1,7 +1,7 @@
 classdef report_series < handle
     % report_series Class to write a page to the report
     %
-    % Copyright (C) 2013-2019 Dynare Team
+    % Copyright (C) 2013-2022 Dynare Team
     %
     % This file is part of Dynare.
     %
@@ -79,9 +79,13 @@ classdef report_series < handle
             end
 
             % Octave 5.1.0 has not implemented `properties` and issues a warning when using `fieldnames`
-            warning('off')
+            if isoctave
+                warnstate = warning('off', 'Octave:classdef-to-struct');
+            end
             optNames = fieldnames(o);
-            warning('on')
+            if isoctave
+                warning(warnstate);
+            end
 
             % overwrite default values
             for pair = reshape(varargin, 2, [])
diff --git a/src/@report_table/report_table.m b/src/@report_table/report_table.m
index 3df72d5..f6a334d 100644
--- a/src/@report_table/report_table.m
+++ b/src/@report_table/report_table.m
@@ -1,7 +1,7 @@
 classdef report_table < handle
     % report_table Class
     %
-    % Copyright (C) 2013-2019 Dynare Team
+    % Copyright (C) 2013-2022 Dynare Team
     %
     % This file is part of Dynare.
     %
@@ -73,9 +73,13 @@ classdef report_table < handle
             end
 
             % Octave 5.1.0 has not implemented `properties` and issues a warning when using `fieldnames`
-            warning('off')
+            if isoctave
+                warnstate = warning('off', 'Octave:classdef-to-struct');
+            end
             optNames = fieldnames(o);
-            warning('on')
+            if isoctave
+                warning(warnstate);
+            end
 
             % overwrite default values
             for pair = reshape(varargin, 2, [])
diff --git a/src/@section/section.m b/src/@section/section.m
index cfd70af..52bfd45 100644
--- a/src/@section/section.m
+++ b/src/@section/section.m
@@ -1,7 +1,7 @@
 classdef section < handle
     % section Class
     %
-    % Copyright (C) 2013-2019 Dynare Team
+    % Copyright (C) 2013-2022 Dynare Team
     %
     % This file is part of Dynare.
     %
@@ -53,9 +53,13 @@ classdef section < handle
             end
 
             % Octave 5.1.0 has not implemented `properties` and issues a warning when using `fieldnames`
-            warning('off')
+            if isoctave
+                warnstate = warning('off', 'Octave:classdef-to-struct');
+            end
             optNames = fieldnames(o);
-            warning('on')
+            if isoctave
+                warning(warnstate);
+            end
 
             % overwrite default values
             for pair = reshape(varargin, 2, [])
diff --git a/src/@vspace/vspace.m b/src/@vspace/vspace.m
index 009a22d..73b6707 100644
--- a/src/@vspace/vspace.m
+++ b/src/@vspace/vspace.m
@@ -1,7 +1,7 @@
 classdef vspace < handle
     % vspace Class
     %
-    % Copyright (C) 2013-2019 Dynare Team
+    % Copyright (C) 2013-2022 Dynare Team
     %
     % This file is part of Dynare.
     %
@@ -50,9 +50,13 @@ classdef vspace < handle
             end
 
             % Octave 5.1.0 has not implemented `properties` and issues a warning when using `fieldnames`
-            warning('off')
+            if isoctave
+                warnstate = warning('off', 'Octave:classdef-to-struct');
+            end
             optNames = fieldnames(o);
-            warning('on')
+            if isoctave
+                warning(warnstate);
+            end
 
             % overwrite default values
             for pair = reshape(varargin, 2, [])
-- 
GitLab