Skip to content

Commit 1b29369

Browse files
authored
Fix #335: object lifetime issue when reporting error (#336)
1 parent ea78f9a commit 1b29369

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

simplecpp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,14 @@ class StdIStream : public simplecpp::TokenList::Stream {
380380
class FileStream : public simplecpp::TokenList::Stream {
381381
public:
382382
// cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
383-
EXPLICIT FileStream(const std::string &filename)
383+
EXPLICIT FileStream(const std::string &filename, std::vector<std::string> &files)
384384
: file(fopen(filename.c_str(), "rb"))
385385
, lastCh(0)
386386
, lastStatus(0)
387387
{
388388
if (!file) {
389-
const std::vector<std::string> location;
390-
throw simplecpp::Output(location, simplecpp::Output::FILE_NOT_FOUND, "File is missing: " + filename);
389+
files.push_back(filename);
390+
throw simplecpp::Output(files, simplecpp::Output::FILE_NOT_FOUND, "File is missing: " + filename);
391391
}
392392
init();
393393
}
@@ -447,7 +447,7 @@ simplecpp::TokenList::TokenList(const std::string &filename, std::vector<std::st
447447
{
448448
try
449449
{
450-
FileStream stream(filename);
450+
FileStream stream(filename, filenames);
451451
readfile(stream,filename,outputList);
452452
}
453453
catch(const simplecpp::Output & e) // TODO handle extra type of errors

simplecpp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ namespace simplecpp {
183183
EXPLICIT_INCLUDE_NOT_FOUND,
184184
FILE_NOT_FOUND
185185
} type;
186-
explicit Output(const std::vector<std::string> &files, Output::Type id, const std::string & errMsg ) : type(id), location(files), msg(errMsg) {}
186+
explicit Output(const std::vector<std::string>& files, Type type, const std::string& msg) : type(type), location(files), msg(msg) {}
187187
Location location;
188188
std::string msg;
189189
};

0 commit comments

Comments
 (0)