From 43d4bafa36380e99f6ae4b3d3a3160fb9f1699c0 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.
---
 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 cbf2fa0..89ad9a5 100644
--- a/src/@page/page.m
+++ b/src/@page/page.m
@@ -1,7 +1,7 @@
 classdef page < handle
     % page Class
     %
-    % Copyright © 2013-2019 Dynare Team
+    % Copyright © 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 01dee6b..22ceffd 100644
--- a/src/@paragraph/paragraph.m
+++ b/src/@paragraph/paragraph.m
@@ -1,7 +1,7 @@
 classdef paragraph < handle
     % paragraph Class
     %
-    % Copyright © 2014-2019 Dynare Team
+    % Copyright © 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 29ae4af..9d8fb60 100644
--- a/src/@report/report.m
+++ b/src/@report/report.m
@@ -1,7 +1,7 @@
 classdef report < handle
     % report Class
     %
-    % Copyright © 2013-2019 Dynare Team
+    % Copyright © 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 7a0cb07..22bbdaf 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 © 2019 Dynare Team
+    % Copyright © 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 10e816e..6d81f4e 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 © 2013-2020 Dynare Team
+    % Copyright © 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 5eeff8e..15a882c 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 © 2013-2019 Dynare Team
+    % Copyright © 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 31f1f7c..af60e08 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 © 2013-2019 Dynare Team
+    % Copyright © 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 126e249..05a7fc0 100644
--- a/src/@section/section.m
+++ b/src/@section/section.m
@@ -1,7 +1,7 @@
 classdef section < handle
     % section Class
     %
-    % Copyright © 2013-2019 Dynare Team
+    % Copyright © 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 b605500..85a39b1 100644
--- a/src/@vspace/vspace.m
+++ b/src/@vspace/vspace.m
@@ -1,7 +1,7 @@
 classdef vspace < handle
     % vspace Class
     %
-    % Copyright © 2013-2019 Dynare Team
+    % Copyright © 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