From 90a408e3c3bcce45738e27cb9189a6b18ce6b661 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Tue, 11 Apr 2023 14:46:04 +0200
Subject: [PATCH] Build system: enable the dangling else warning
 (-Wdangling-else)

Adapt the code accordingly.
---
 dynare++/kord/approximation.cc    | 12 +++---
 dynare++/kord/korder_stoch.hh     | 62 +++++++++++++++-----------
 dynare++/tl/cc/stack_container.hh | 72 ++++++++++++++++++-------------
 license.txt                       |  2 +-
 mex/build/matlab/mex.am           |  2 +-
 mex/build/octave/mex.am           |  2 +-
 preprocessor                      |  2 +-
 7 files changed, 91 insertions(+), 63 deletions(-)

diff --git a/dynare++/kord/approximation.cc b/dynare++/kord/approximation.cc
index 6934ec6d28..9c0efe7f2a 100644
--- a/dynare++/kord/approximation.cc
+++ b/dynare++/kord/approximation.cc
@@ -1,6 +1,6 @@
 /*
  * Copyright © 2005 Ondra Kamenik
- * Copyright © 2019-2021 Dynare Team
+ * Copyright © 2019-2023 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -40,10 +40,12 @@ ZAuxContainer::itype
 ZAuxContainer::getType(int i, const Symmetry &s) const
 {
   if (i == 0)
-    if (s[2] > 0)
-      return itype::zero;
-    else
-      return itype::matrix;
+    {
+      if (s[2] > 0)
+        return itype::zero;
+      else
+        return itype::matrix;
+    }
   return itype::zero;
 }
 
diff --git a/dynare++/kord/korder_stoch.hh b/dynare++/kord/korder_stoch.hh
index d4152d4f43..857bcc65db 100644
--- a/dynare++/kord/korder_stoch.hh
+++ b/dynare++/kord/korder_stoch.hh
@@ -1,6 +1,6 @@
 /*
  * Copyright © 2005 Ondra Kamenik
- * Copyright © 2019-2022 Dynare Team
+ * Copyright © 2019-2023 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -285,19 +285,23 @@ typename GXContainer<_Ttype>::itype
 GXContainer<_Ttype>::getType(int i, const Symmetry &s) const
 {
   if (i == 0)
-    if (s[2] > 0)
-      return itype::zero;
-    else
-      return itype::matrix;
+    {
+      if (s[2] > 0)
+        return itype::zero;
+      else
+        return itype::matrix;
+    }
   if (i == 1)
     return itype::zero;
   if (i == 2)
     return itype::zero;
   if (i == 3)
-    if (s == Symmetry{0, 0, 0, 1})
-      return itype::unit;
-    else
-      return itype::zero;
+    {
+      if (s == Symmetry{0, 0, 0, 1})
+        return itype::unit;
+      else
+        return itype::zero;
+    }
 
   KORD_RAISE("Wrong stack index in GXContainer::getType");
 }
@@ -331,25 +335,33 @@ typename ZXContainer<_Ttype>::itype
 ZXContainer<_Ttype>::getType(int i, const Symmetry &s) const
 {
   if (i == 0)
-    if (s[2] > 0)
-      return itype::zero;
-    else
-      return itype::matrix;
+    {
+      if (s[2] > 0)
+        return itype::zero;
+      else
+        return itype::matrix;
+    }
   if (i == 1)
-    if (s[2] > 0)
-      return itype::zero;
-    else
-      return itype::matrix;
+    {
+      if (s[2] > 0)
+        return itype::zero;
+      else
+        return itype::matrix;
+    }
   if (i == 2)
-    if (s == Symmetry{1, 0, 0, 0})
-      return itype::unit;
-    else
-      return itype::zero;
+    {
+      if (s == Symmetry{1, 0, 0, 0})
+        return itype::unit;
+      else
+        return itype::zero;
+    }
   if (i == 3)
-    if (s == Symmetry{0, 1, 0, 0})
-      return itype::unit;
-    else
-      return itype::zero;
+    {
+      if (s == Symmetry{0, 1, 0, 0})
+        return itype::unit;
+      else
+        return itype::zero;
+    }
 
   KORD_RAISE("Wrong stack index in ZXContainer::getType");
 }
diff --git a/dynare++/tl/cc/stack_container.hh b/dynare++/tl/cc/stack_container.hh
index dd0c327528..e5903a5509 100644
--- a/dynare++/tl/cc/stack_container.hh
+++ b/dynare++/tl/cc/stack_container.hh
@@ -1,6 +1,6 @@
 /*
  * Copyright © 2004 Ondra Kamenik
- * Copyright © 2019 Dynare Team
+ * Copyright © 2019-2023 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -365,10 +365,12 @@ public:
   getType(int i, const Symmetry &s) const override
   {
     if (i==0)
-      if (s[2] > 0)
-        return itype::zero;
-      else
-        return itype::matrix;
+      {
+        if (s[2] > 0)
+          return itype::zero;
+        else
+          return itype::matrix;
+      }
 
     TL_RAISE("Wrong stack index in XContainer::getType");
   }
@@ -433,20 +435,26 @@ public:
     if (i == 0)
       return itype::matrix;
     if (i == 1)
-      if (s[2] > 0)
-        return itype::zero;
-      else
-        return itype::matrix;
+      {
+        if (s[2] > 0)
+          return itype::zero;
+        else
+          return itype::matrix;
+      }
     if (i == 2)
-      if (s == Symmetry{1, 0, 0, 0})
-        return itype::unit;
-      else
-        return itype::zero;
+      {
+        if (s == Symmetry{1, 0, 0, 0})
+          return itype::unit;
+        else
+          return itype::zero;
+      }
     if (i == 3)
-      if (s == Symmetry{0, 1, 0, 0})
-        return itype::unit;
-      else
-        return itype::zero;
+      {
+        if (s == Symmetry{0, 1, 0, 0})
+          return itype::unit;
+        else
+          return itype::zero;
+      }
 
     TL_RAISE("Wrong stack index in ZContainer::getType");
   }
@@ -512,22 +520,28 @@ public:
   getType(int i, const Symmetry &s) const override
   {
     if (i == 0)
-      if (s[2] > 0 || s == Symmetry{0, 0, 0, 1})
-        return itype::zero;
-      else
-        return itype::matrix;
+      {
+        if (s[2] > 0 || s == Symmetry{0, 0, 0, 1})
+          return itype::zero;
+        else
+          return itype::matrix;
+      }
     if (i == 1)
-      if (s == Symmetry{0, 0, 1, 0})
-        return itype::unit;
-      else
-        return itype::zero;
+      {
+        if (s == Symmetry{0, 0, 1, 0})
+          return itype::unit;
+        else
+          return itype::zero;
+      }
     if (i == 2)
       return itype::zero;
     if (i == 3)
-      if (s == Symmetry{0, 0, 0, 1})
-        return itype::unit;
-      else
-        return itype::zero;
+      {
+        if (s == Symmetry{0, 0, 0, 1})
+          return itype::unit;
+        else
+          return itype::zero;
+      }
 
     TL_RAISE("Wrong stack index in GContainer::getType");
   }
diff --git a/license.txt b/license.txt
index e471efd484..d7d66d75db 100644
--- a/license.txt
+++ b/license.txt
@@ -280,7 +280,7 @@ License: GFDL-NIV-1.3+
 
 Files: dynare++/*
 Copyright: 2004-2011 Ondra Kamenik
-           2019-2022 Dynare Team
+           2019-2023 Dynare Team
 License: GPL-3+
 
 Files: m4/ax_compare_version.m4
diff --git a/mex/build/matlab/mex.am b/mex/build/matlab/mex.am
index 237762aec6..03bef38efa 100644
--- a/mex/build/matlab/mex.am
+++ b/mex/build/matlab/mex.am
@@ -9,7 +9,7 @@ DEFS += -DMEXEXT=\"$(MEXEXT)\"
 
 AM_CFLAGS = $(MATLAB_CFLAGS) -Wall -Wno-parentheses # TODO: use same warnings as C++
 AM_FCFLAGS = $(MATLAB_FCFLAGS) -Wall -Wimplicit-interface
-AM_CXXFLAGS = -std=gnu++20 $(MATLAB_CXXFLAGS) -Wall -Wno-dangling-else -Wextra -Wold-style-cast
+AM_CXXFLAGS = -std=gnu++20 $(MATLAB_CXXFLAGS) -Wall -Wextra -Wold-style-cast
 AM_LDFLAGS = $(MATLAB_LDFLAGS)
 LIBS += $(MATLAB_LIBS)
 
diff --git a/mex/build/octave/mex.am b/mex/build/octave/mex.am
index 2f8d713ef3..0e77872e78 100644
--- a/mex/build/octave/mex.am
+++ b/mex/build/octave/mex.am
@@ -5,7 +5,7 @@ DEFS += -DMEXEXT=\".mex\"
 
 AM_CFLAGS = $(shell $(MKOCTFILE) -p CPICFLAG) -Wall -Wno-parentheses # TODO: use same warnings as C++
 AM_FCFLAGS = $(shell $(MKOCTFILE) -p FPICFLAG) -Wall -Wimplicit-interface
-AM_CXXFLAGS = -std=gnu++20 $(shell $(MKOCTFILE) -p CXXPICFLAG) -Wall -Wno-dangling-else -Wextra -Wold-style-cast
+AM_CXXFLAGS = -std=gnu++20 $(shell $(MKOCTFILE) -p CXXPICFLAG) -Wall -Wextra -Wold-style-cast
 AM_LDFLAGS = $(shell $(MKOCTFILE) -p DL_LDFLAGS)
 
 # See the comments in configure.ac
diff --git a/preprocessor b/preprocessor
index 6caf8c6c59..1b7b70ec93 160000
--- a/preprocessor
+++ b/preprocessor
@@ -1 +1 @@
-Subproject commit 6caf8c6c59b0bf25a8154711c6db7817470b4f6f
+Subproject commit 1b7b70ec934a66ac6f7844dce670f17ba0b561a0
-- 
GitLab