@@ -56,22 +56,16 @@ using namespace std::placeholders;
5656namespace xcpp
5757{
5858 struct StreamRedirectRAII {
59- std::string& out;
60- std::string& err;
61-
62- StreamRedirectRAII (std::string& o, std::string& e)
63- : out(o)
64- , err(e)
65- {
66- Cpp::BeginStdStreamCapture (Cpp::kStdOut );
67- Cpp::BeginStdStreamCapture (Cpp::kStdErr );
68- }
69-
70- ~StreamRedirectRAII ()
71- {
72- err = Cpp::EndStdStreamCapture ();
73- out = Cpp::EndStdStreamCapture ();
74- }
59+ std::string &err;
60+ StreamRedirectRAII (std::string &e) : err(e) {
61+ Cpp::BeginStdStreamCapture (Cpp::kStdErr );
62+ Cpp::BeginStdStreamCapture (Cpp::kStdOut );
63+ }
64+ ~StreamRedirectRAII () {
65+ std::string out = Cpp::EndStdStreamCapture ();
66+ err = Cpp::EndStdStreamCapture ();
67+ std::cout << out;
68+ }
7569 };
7670
7771 void interpreter::configure_impl ()
@@ -169,12 +163,11 @@ __get_cxx_version ()
169163 }
170164
171165 std::string err;
172- std::string out;
173166
174167 // Attempt normal evaluation
175168 try
176169 {
177- StreamRedirectRAII R (out, err);
170+ StreamRedirectRAII R (err);
178171 compilation_result = Cpp::Process (code.c_str ());
179172 }
180173 catch (std::exception& e)
@@ -189,12 +182,11 @@ __get_cxx_version ()
189182 ename = " Error: " ;
190183 }
191184
192- if (!out.empty ())
193- {
194- std::cout << out;
195- }
196- if (!err.empty ())
185+ if (compilation_result)
197186 {
187+ errorlevel = 1 ;
188+ ename = " Error: " ;
189+ evalue = " Compilation error! " + err;
198190 std::cerr << err;
199191 }
200192
@@ -209,13 +201,6 @@ __get_cxx_version ()
209201 std::cerr.rdbuf (cerr_strbuf);
210202 }
211203
212- if (compilation_result)
213- {
214- errorlevel = 1 ;
215- ename = " Error: " ;
216- evalue = " Compilation error! " + err;
217- }
218-
219204 // Depending of error level, publish execution result or execution
220205 // error, and compose execute_reply message.
221206 if (errorlevel)
0 commit comments