From b7c70fd99e9b485d52a6f4f46b54fdc622d95a64 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Tue, 7 Jun 2022 17:39:04 +0200
Subject: [PATCH] Dynare++: add a few parentheses to make GCC happy with
 -Wparentheses
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

I’m not sure that the intent for the hash function was actually what is
currently in the code, but it’s not worth improving this given that we want to
get rid of Dynare++ and the performance impact is probably negligible.
---
 dynare++/parser/cc/tree.hh     | 8 ++++----
 dynare++/sylv/cc/Vector.cc     | 8 ++++----
 dynare++/sylv/testing/tests.cc | 4 ++--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/dynare++/parser/cc/tree.hh b/dynare++/parser/cc/tree.hh
index a125f8be85..88474b369e 100644
--- a/dynare++/parser/cc/tree.hh
+++ b/dynare++/parser/cc/tree.hh
@@ -1,6 +1,6 @@
 /*
  * Copyright © 2005-2011 Ondra Kamenik
- * Copyright © 2019 Dynare Team
+ * Copyright © 2019-2022 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -85,8 +85,8 @@ namespace ogp
     operator<(const Operation &op) const
     {
       return (code < op.code
-              || code == op.code
-              && (op1 < op.op1 || op1 == op.op1 && op2 < op.op2));
+              || (code == op.code
+                  && (op1 < op.op1 || (op1 == op.op1 && op2 < op.op2))));
     }
     /** Returns a number of operands. */
     int
@@ -98,7 +98,7 @@ namespace ogp
     size_t
     hashval() const
     {
-      return op2+1 + (op1+1)^15 + static_cast<int>(code)^30;
+      return (op2+1 + op1+1)^(15 + static_cast<int>(code))^30;
     }
 
     code_t
diff --git a/dynare++/sylv/cc/Vector.cc b/dynare++/sylv/cc/Vector.cc
index 33db2f9f9f..c84453d717 100644
--- a/dynare++/sylv/cc/Vector.cc
+++ b/dynare++/sylv/cc/Vector.cc
@@ -52,8 +52,8 @@ Vector::operator=(const Vector &v)
     throw SYLV_MES_EXCEPTION("Attempt to assign vectors with different lengths.");
 
   if (s == v.s
-      && (data <= v.data && v.data < data+len*s
-          || v.data <= data && data < v.data+v.len*v.s)
+      && ((data <= v.data && v.data < data+len*s)
+          || (v.data <= data && data < v.data+v.len*v.s))
       && (data-v.data) % s == 0)
     throw SYLV_MES_EXCEPTION("Attempt to assign overlapping vectors.");
 
@@ -67,8 +67,8 @@ Vector::operator=(const ConstVector &v)
   if (v.len != len)
     throw SYLV_MES_EXCEPTION("Attempt to assign vectors with different lengths.");
   if (s == v.s
-      && (data <= v.data && v.data < data+len*s
-          || v.data <= data && data < v.data+v.len*v.s)
+      && ((data <= v.data && v.data < data+len*s)
+          || (v.data <= data && data < v.data+v.len*v.s))
       && (data-v.data) % s == 0)
     throw SYLV_MES_EXCEPTION("Attempt to assign overlapping vectors.");
 
diff --git a/dynare++/sylv/testing/tests.cc b/dynare++/sylv/testing/tests.cc
index f283ee4cbe..b2e3628bae 100644
--- a/dynare++/sylv/testing/tests.cc
+++ b/dynare++/sylv/testing/tests.cc
@@ -186,8 +186,8 @@ TestRunnable::level_kron(bool trans, const std::string &mname, const std::string
   MMMatrixIn mmc(cname);
 
   int length = power(m, depth)*n;
-  if (level > 0 && mmt.row() != m
-      || level == 0 && mmt.row() != n
+  if ((level > 0 && mmt.row() != m)
+      || (level == 0 && mmt.row() != n)
       || mmv.row() != length
       || mmc.row() != length)
     {
-- 
GitLab