diff --git a/simplecpp.cpp b/simplecpp.cpp index 48b8c6f1..71f03199 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -54,6 +54,14 @@ #undef ERROR #endif +#if __cplusplus >= 201103L +#define OVERRIDE override +#define EXPLICIT explicit +#else +#define OVERRIDE +#define EXPLICIT +#endif + #if (__cplusplus < 201103L) && !defined(__APPLE__) #define nullptr NULL #endif @@ -238,6 +246,7 @@ void simplecpp::Token::printOut() const std::cout << std::endl; } +// cppcheck-suppress noConstructor - we call init() in the inherited to initialize the private members class simplecpp::TokenList::Stream { public: virtual ~Stream() {} @@ -356,23 +365,24 @@ class simplecpp::TokenList::Stream { class StdIStream : public simplecpp::TokenList::Stream { public: - StdIStream(std::istream &istr) + // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members + EXPLICIT StdIStream(std::istream &istr) : istr(istr) { assert(istr.good()); init(); } - virtual int get() { + virtual int get() OVERRIDE { return istr.get(); } - virtual int peek() { + virtual int peek() OVERRIDE { return istr.peek(); } - virtual void unget() { + virtual void unget() OVERRIDE { istr.unget(); } - virtual bool good() { + virtual bool good() OVERRIDE { return istr.good(); } @@ -382,7 +392,8 @@ class StdIStream : public simplecpp::TokenList::Stream { class FileStream : public simplecpp::TokenList::Stream { public: - FileStream(const std::string &filename) + // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members + EXPLICIT FileStream(const std::string &filename) : file(fopen(filename.c_str(), "rb")) , lastCh(0) , lastStatus(0) @@ -391,25 +402,25 @@ class FileStream : public simplecpp::TokenList::Stream { init(); } - ~FileStream() { + ~FileStream() OVERRIDE { fclose(file); file = nullptr; } - virtual int get() { + virtual int get() OVERRIDE { lastStatus = lastCh = fgetc(file); return lastCh; } - virtual int peek() { + virtual int peek() OVERRIDE{ // keep lastCh intact const int ch = fgetc(file); unget_internal(ch); return ch; } - virtual void unget() { + virtual void unget() OVERRIDE { unget_internal(lastCh); } - virtual bool good() { + virtual bool good() OVERRIDE { return lastStatus != EOF; } @@ -424,6 +435,9 @@ class FileStream : public simplecpp::TokenList::Stream { ungetc(ch, file); } + FileStream(const FileStream&); + FileStream &operator=(const FileStream&); + FILE *file; int lastCh; int lastStatus; @@ -1439,6 +1453,7 @@ namespace simplecpp { tokenListDefine = other.tokenListDefine; parseDefine(tokenListDefine.cfront()); } + usageList = other.usageList; } return *this; } @@ -2479,6 +2494,7 @@ namespace simplecpp { if (unc) path = '/' + path; + // cppcheck-suppress duplicateExpressionTernary - platform-dependent implementation return strpbrk(path.c_str(), "*?") == nullptr ? realFilename(path) : path; } } @@ -2572,6 +2588,7 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI for (simplecpp::Token *headerToken = tok1->next; headerToken != tok3; headerToken = headerToken->next) header += headerToken->str(); + // cppcheck-suppress selfAssignment - platform-dependent implementation header = realFilename(header); } else { @@ -3147,14 +3164,14 @@ static void getLocaltime(struct tm <ime) #endif } -static std::string getDateDefine(struct tm *timep) +static std::string getDateDefine(const struct tm *timep) { char buf[] = "??? ?? ????"; strftime(buf, sizeof(buf), "%b %d %Y", timep); return std::string("\"").append(buf).append("\""); } -static std::string getTimeDefine(struct tm *timep) +static std::string getTimeDefine(const struct tm *timep) { char buf[] = "??:??:??"; strftime(buf, sizeof(buf), "%T", timep); @@ -3467,6 +3484,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL if (systemheader) { while ((tok = tok->next) && tok->op != '>') header += tok->str(); + // cppcheck-suppress selfAssignment - platform-dependent implementation header = realFilename(header); if (tok && tok->op == '>') closingAngularBracket = true;