From 4ecb7fe5981dba35fa0fd1032087858d7cd117fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Wed, 20 Nov 2024 14:18:11 +0100
Subject: [PATCH] Bump to clang-format 16
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

– enable new options InsertNewlineAtEOF and RemoveSemicolon
– reformat the code accordingly
---
 .clang-format                                        | 2 ++
 mex/sources/k_order_welfare/approximation_welfare.cc | 2 +-
 mex/sources/libkorder/dynamic_dll.cc                 | 3 +++
 mex/sources/libkorder/kord/kord_exception.hh         | 8 ++++----
 mex/sources/libkorder/tl/permutation.hh              | 2 +-
 mex/sources/libkorder/tl/tl_exception.hh             | 4 ++--
 6 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/.clang-format b/.clang-format
index b2ce7c0e6..d617cd54e 100644
--- a/.clang-format
+++ b/.clang-format
@@ -19,9 +19,11 @@ BreakInheritanceList: AfterColon
 Cpp11BracedListStyle: true
 DeriveLineEnding: false
 IndentPPDirectives: AfterHash
+InsertNewlineAtEOF: true
 PackConstructorInitializers: NextLine
 PPIndentWidth: 1
 PointerAlignment: Left
+RemoveSemicolon: true
 SpaceAfterTemplateKeyword: false
 SpaceBeforeParens: ControlStatements
 SpaceBeforeCpp11BracedList: true
diff --git a/mex/sources/k_order_welfare/approximation_welfare.cc b/mex/sources/k_order_welfare/approximation_welfare.cc
index bb56d6e49..da65f4d82 100644
--- a/mex/sources/k_order_welfare/approximation_welfare.cc
+++ b/mex/sources/k_order_welfare/approximation_welfare.cc
@@ -71,4 +71,4 @@ void
 ApproximationWelfare::saveRuleDerivs(const FGSContainer& W)
 {
   cond_ders = std::make_unique<FGSContainer>(W);
-}
\ No newline at end of file
+}
diff --git a/mex/sources/libkorder/dynamic_dll.cc b/mex/sources/libkorder/dynamic_dll.cc
index 32d1cbe78..a50116d07 100644
--- a/mex/sources/libkorder/dynamic_dll.cc
+++ b/mex/sources/libkorder/dynamic_dll.cc
@@ -46,7 +46,10 @@ DynamicModelDLL::DynamicModelDLL(const std::string& modName, int order_arg,
         "./"s +
 #endif
             "+"s + modName + "/+sparse/" + func_name + MEXEXT
+        // clang-format off
+        // As of Clang 16, the RemoveSemicolon option incorrectly removes the following semicolon
       };
+      // clang-format on
 
       mex_handle_t handle {load_mex(mex_filename)};
       if (handle)
diff --git a/mex/sources/libkorder/kord/kord_exception.hh b/mex/sources/libkorder/kord/kord_exception.hh
index 83508ab92..da2ddefd3 100644
--- a/mex/sources/libkorder/kord/kord_exception.hh
+++ b/mex/sources/libkorder/kord/kord_exception.hh
@@ -31,14 +31,14 @@
 #define KORD_RAISE(mes) throw KordException(__FILE__, __LINE__, mes);
 
 #define KORD_RAISE_IF(expr, mes)                                                                   \
- if (expr)                                                                                         \
-  throw KordException(__FILE__, __LINE__, mes);
+  if (expr)                                                                                        \
+    throw KordException(__FILE__, __LINE__, mes);
 
 #define KORD_RAISE_X(mes, c) throw KordException(__FILE__, __LINE__, mes, c);
 
 #define KORD_RAISE_IF_X(expr, mes, c)                                                              \
- if (expr)                                                                                         \
-  throw KordException(__FILE__, __LINE__, mes, c);
+  if (expr)                                                                                        \
+    throw KordException(__FILE__, __LINE__, mes, c);
 
 class KordException
 {
diff --git a/mex/sources/libkorder/tl/permutation.hh b/mex/sources/libkorder/tl/permutation.hh
index a41075e28..43d40087a 100644
--- a/mex/sources/libkorder/tl/permutation.hh
+++ b/mex/sources/libkorder/tl/permutation.hh
@@ -87,7 +87,7 @@ public:
   explicit Permutation(const IntSequence& s) : permap(s.size())
   {
     computeSortingMap(s);
-  };
+  }
   Permutation(const Permutation& p1, const Permutation& p2) : permap(p2.permap)
   {
     p1.apply(permap);
diff --git a/mex/sources/libkorder/tl/tl_exception.hh b/mex/sources/libkorder/tl/tl_exception.hh
index ff5adc806..3c920e86c 100644
--- a/mex/sources/libkorder/tl/tl_exception.hh
+++ b/mex/sources/libkorder/tl/tl_exception.hh
@@ -62,8 +62,8 @@
 #define TL_RAISE(mes) throw TLException(__FILE__, __LINE__, mes)
 
 #define TL_RAISE_IF(expr, mes)                                                                     \
- if (TL_DEBUG >= TL_DEBUG_EXCEPTION && (expr))                                                     \
-  throw TLException(__FILE__, __LINE__, mes);
+  if (TL_DEBUG >= TL_DEBUG_EXCEPTION && (expr))                                                    \
+    throw TLException(__FILE__, __LINE__, mes);
 
 /* Primitive exception class containing file name, line number and message. */
 
-- 
GitLab