From 5b400b69f0ebcf82499cf1ea3142a8f46fd32eb1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Tue, 11 Oct 2022 11:00:50 +0200
Subject: [PATCH] Use std::filesystem::path::string() when writing paths to
 std::cout/std::cerr

Otherwise they will be quoted, which is not desirable, especially under
Windows (backslashes will be duplicated).
---
 src/DynamicModel.cc | 6 +++---
 src/ModelTree.cc    | 2 +-
 src/ModelTree.hh    | 2 +-
 src/StaticModel.cc  | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc
index 55f804cf..75a79827 100644
--- a/src/DynamicModel.cc
+++ b/src/DynamicModel.cc
@@ -372,7 +372,7 @@ DynamicModel::writeDynamicPerBlockCFiles(const string &basename, const string &m
       ofstream output{filename, ios::out | ios::binary};
       if (!output.is_open())
         {
-          cerr << "ERROR: Can't open file " << filename << " for writing" << endl;
+          cerr << "ERROR: Can't open file " << filename.string() << " for writing" << endl;
           exit(EXIT_FAILURE);
         }
 
@@ -543,7 +543,7 @@ DynamicModel::writeDynamicPerBlockCFiles(const string &basename, const string &m
       ofstream header_output{filename, ios::out | ios::binary};
       if (!header_output.is_open())
         {
-          cerr << "ERROR: Can't open file " << filename << " for writing" << endl;
+          cerr << "ERROR: Can't open file " << filename.string() << " for writing" << endl;
           exit(EXIT_FAILURE);
         }
       header_output << header.str() << ';' << endl;
@@ -4605,7 +4605,7 @@ DynamicModel::isChecksumMatching(const string &basename) const
   checksum_file.open(filename, ios::out | ios::binary);
   if (!checksum_file.is_open())
     {
-      cerr << "ERROR: Can't open file " << filename << endl;
+      cerr << "ERROR: Can't open file " << filename.string() << endl;
       exit(EXIT_FAILURE);
     }
   checksum_file << result;
diff --git a/src/ModelTree.cc b/src/ModelTree.cc
index 0bd70395..c2eb674c 100644
--- a/src/ModelTree.cc
+++ b/src/ModelTree.cc
@@ -1759,7 +1759,7 @@ ModelTree::compileMEX(const filesystem::path &output_dir, const string &output_b
   cmd << '"';
 #endif
 
-  cout << "Compiling " << output_filename << endl;
+  cout << "Compiling " << output_filename.string() << endl;
 
   // The prerequisites are the object files among the input files
   set<filesystem::path> prerequisites;
diff --git a/src/ModelTree.hh b/src/ModelTree.hh
index 08bf4d81..e2e28849 100644
--- a/src/ModelTree.hh
+++ b/src/ModelTree.hh
@@ -837,7 +837,7 @@ ModelTree::writeModelCFile(const string &basename, const string &mexext,
     output.open(p, ios::out | ios::binary);
     if (!output.is_open())
       {
-        cerr << "ERROR: Can't open file " << p << " for writing" << endl;
+        cerr << "ERROR: Can't open file " << p.string() << " for writing" << endl;
         exit(EXIT_FAILURE);
       }
   };
diff --git a/src/StaticModel.cc b/src/StaticModel.cc
index dde18cb9..b01230b5 100644
--- a/src/StaticModel.cc
+++ b/src/StaticModel.cc
@@ -167,7 +167,7 @@ StaticModel::writeStaticPerBlockCFiles(const string &basename, const string &mex
       ofstream output{filename, ios::out | ios::binary};
       if (!output.is_open())
         {
-          cerr << "ERROR: Can't open file " << filename << " for writing" << endl;
+          cerr << "ERROR: Can't open file " << filename.string() << " for writing" << endl;
           exit(EXIT_FAILURE);
         }
       output << "/* Block " << blk+1 << endl
-- 
GitLab