Skip to content

Commit 6840136

Browse files
committed
Be compatible with C++98, C++11, and C++14.
This fixes the gcc 6 build and also fixes an existing bug in passing. The code in timer::stream() would set s_ to &cout if the file could not be opened, then immediately overwrite s_ with (unopened) &file_.
1 parent 3f6ed8c commit 6840136

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

libsrc/newforms.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ void newforms::createfromolddata()
13361336
ifstream intdatafile(intdataname.str().c_str());
13371337
if(!intdatafile.is_open())
13381338
{
1339-
cout<<"Unable to open data file "<<intdataname<<" for data input"<<endl;
1339+
cout<<"Unable to open data file "<<intdataname.str()<<" for data input"<<endl;
13401340
abort();
13411341
return;
13421342
}

libsrc/timer.cc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ timer::~timer() {
7474
// Close file, if ever opened
7575
// Do not reference s_ _ever_. We do not
7676
// want to close std::cout nonetheless.
77-
if( file_ != NULL ) {
77+
if( file_.is_open() ) {
7878
file_.close();
7979
}
8080
}
@@ -101,15 +101,13 @@ void timer::stream( string filename ) {
101101
file_.open(filename.c_str(),ios::out|ios::trunc);
102102

103103
// Check is file successfully opened
104-
if( file_ == NULL ) {
105-
{
106-
cout << "File " << filename << " could not be opened ... using stout" << endl;
107-
s_ = &cout;
108-
}
104+
if( !file_.is_open() ) {
105+
cout << "File " << filename << " could not be opened ... using stout" << endl;
106+
s_ = &cout;
107+
} else {
108+
// Point main reference to newly opened file
109+
s_ = &file_;
109110
}
110-
111-
// Point main reference to newly opened file
112-
s_ = &file_;
113111
}
114112
}
115113

0 commit comments

Comments
 (0)