From: Wolfgang Bangerth Date: Mon, 5 May 2003 13:49:06 +0000 (+0000) Subject: Fix a problem that leads to a segfault at the end of the program with gcc3.4 and... X-Git-Tag: v8.0.0~16584 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ddcdf23c52c575df3a7f0496cb7d5f9652f2c1a3;p=dealii.git Fix a problem that leads to a segfault at the end of the program with gcc3.4 and icc. git-svn-id: https://svn.dealii.org/trunk@7560 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/base/reference.cc b/tests/base/reference.cc index 86a04515b9..114132dc0e 100644 --- a/tests/base/reference.cc +++ b/tests/base/reference.cc @@ -40,7 +40,27 @@ int main() std::ofstream logfile("reference.output"); deallog.attach(logfile); deallog.depth_console(0); + + // we do something rather weird in + // this file: bind the buffer of + // cerr to the log file, so that + // the output of the Assert* macros + // that are written to std::cerr + // end up in the logfiles. + // + // so make sure we store a pointer + // to the old buffer, switch to the + // buffer of the logfile, and at + // the end of main() switch + // back. note that if we don't + // switch back, we get a segfault + // later on in the destruction of + // std::cerr, since it tries to do + // something with its buffer, but + // that is already gone by then + std::basic_streambuf *old_cerr_buf = std::cerr.rdbuf(); std::cerr.rdbuf(logfile.rdbuf()); + Test a("A"); const Test b("B"); SmartPointer r=&a; @@ -71,5 +91,7 @@ int main() Test d("D"); r = &d; } + + std::cerr.rdbuf(old_cerr_buf); } diff --git a/tests/lac/block_vector.cc b/tests/lac/block_vector.cc index 67c3a72e86..09ffa9953f 100644 --- a/tests/lac/block_vector.cc +++ b/tests/lac/block_vector.cc @@ -154,6 +154,10 @@ int main () logfile.precision(3); deallog.attach(logfile); deallog.depth_console(0); + + // do the same weird stuff as in + // tests/base/reference.cc + std::basic_streambuf *old_cerr_buf = std::cerr.rdbuf(); std::cerr.rdbuf(logfile.rdbuf()); try @@ -185,7 +189,6 @@ int main () return 3; }; - - return 0; + std::cerr.rdbuf(old_cerr_buf); }