diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index d2c398c49e1..da2538be6c6 100644 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -96,6 +96,8 @@ static const simplecpp::TokenString IFNDEF("ifndef"); static const simplecpp::TokenString DEFINED("defined"); static const simplecpp::TokenString ELSE("else"); static const simplecpp::TokenString ELIF("elif"); +static const simplecpp::TokenString ELIFDEF("elifdef"); +static const simplecpp::TokenString ELIFNDEF("elifndef"); static const simplecpp::TokenString ENDIF("endif"); static const simplecpp::TokenString PRAGMA("pragma"); @@ -475,26 +477,26 @@ namespace { simplecpp::TokenList::TokenList(std::vector &filenames) : frontToken(nullptr), backToken(nullptr), files(filenames) {} -simplecpp::TokenList::TokenList(std::istream &istr, std::vector &filenames, const std::string &filename, OutputList *outputList) +simplecpp::TokenList::TokenList(std::istream &istr, std::vector &filenames, const std::string &filename, const DUI &dui, OutputList *outputList) : frontToken(nullptr), backToken(nullptr), files(filenames) { StdIStream stream(istr); - readfile(stream,filename,outputList); + readfile(stream,filename,dui,outputList); } -simplecpp::TokenList::TokenList(const unsigned char* data, std::size_t size, std::vector &filenames, const std::string &filename, OutputList *outputList, int /*unused*/) +simplecpp::TokenList::TokenList(const unsigned char* data, std::size_t size, std::vector &filenames, const std::string &filename, const DUI &dui, OutputList *outputList, int /*unused*/) : frontToken(nullptr), backToken(nullptr), files(filenames) { StdCharBufStream stream(data, size); - readfile(stream,filename,outputList); + readfile(stream,filename,dui,outputList); } -simplecpp::TokenList::TokenList(const std::string &filename, std::vector &filenames, OutputList *outputList) +simplecpp::TokenList::TokenList(const std::string &filename, std::vector &filenames, const DUI &dui, OutputList *outputList) : frontToken(nullptr), backToken(nullptr), files(filenames) { try { FileStream stream(filename, filenames); - readfile(stream,filename,outputList); + readfile(stream,filename,dui,outputList); } catch (const simplecpp::Output & e) { outputList->emplace_back(e); } @@ -659,18 +661,24 @@ void simplecpp::TokenList::lineDirective(unsigned int fileIndex_, unsigned int l static const std::string COMMENT_END("*/"); -void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename, OutputList *outputList) +void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename, const DUI &dui, OutputList *outputList) { unsigned int multiline = 0U; + bool trailing_nl = true; const Token *oldLastToken = nullptr; + const cstd_t cstd = getCStd(dui.std); + const cppstd_t cppstd = getCppStd(dui.std); + Location location(fileIndex(filename), 1, 1); while (stream.good()) { unsigned char ch = stream.readChar(); if (!stream.good()) break; + trailing_nl = false; + if (ch >= 0x80) { if (outputList) { simplecpp::Output err{ @@ -693,6 +701,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename, } else { location.line += multiline + 1; multiline = 0U; + trailing_nl = true; } if (!multiline) location.col = 1; @@ -723,10 +732,64 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename, if (ppTok->str() == "line") ppTok = advanceAndSkipComments(ppTok); + if (ppTok && (ppTok->str()[0] == '-' || ppTok->str()[0] == '+')) { + if (outputList) { + simplecpp::Output err{ + simplecpp::Output::SYNTAX_ERROR, + location, + "Invalid character in line directive: '" + ppTok->str() + "'." + }; + outputList->emplace_back(std::move(err)); + } + clear(); + return; + } + if (!ppTok || !ppTok->number) continue; - const unsigned int line = std::atol(ppTok->str().c_str()); + constexpr unsigned long line_limit = std::numeric_limits::max(); + unsigned long line; + try { + line = std::min(line_limit, std::stoul(ppTok->str())); + } catch (...) { + line = line_limit; + } + + unsigned long maxline; + if ((cstd != CUnknown && cstd < C99) || (cppstd != CPPUnknown && cppstd < CPP11)) + maxline = 32767; + else + maxline = 2147483647; + + if (line == 0 || line > maxline) { + if (outputList) { + const bool unknown_std = cstd == CUnknown && cppstd == CPPUnknown; + std::string msg = "Line number out of range: " + ppTok->str() + ". "; + if (line == 0) { + msg += "Line number zero is undefined behavior."; + } else { + msg += "Line numbers above " + std::to_string(maxline) + " are "; + if (unknown_std) + msg += "undefined behavior or conditionally supported"; + else if (cppstd >= CPP26) + msg += "conditionally supported"; + else + msg += "undefined behavior"; + if (cstd != CUnknown) + msg += std::string(" in ") + getCStdName(cstd); + else if (cppstd != CPPUnknown) + msg += std::string(" in ") + getCppStdName(cppstd); + msg += "."; + } + simplecpp::Output err{ + simplecpp::Output::PORTABILITY_LINE_DIRECTIVE, + location, msg + }; + outputList->emplace_back(std::move(err)); + } + } + ppTok = advanceAndSkipComments(ppTok); unsigned int fileindex; @@ -961,6 +1024,15 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename, location.adjust(currentToken); } + if ((cstd != CUnknown || cppstd == CPPUnknown) && !trailing_nl && outputList) { + Output err{ + Output::PORTABILITY_NO_EOF_NEWLINE, + location, + "No newline at end of file is undefined behavior in C." + }; + outputList->emplace_back(std::move(err)); + } + combineOperators(); } @@ -1523,7 +1595,7 @@ namespace simplecpp { * @throws std::runtime_error thrown on bad macro syntax */ Macro(const std::string &name, const std::string &value, std::vector &f) : nameTokDef(nullptr), files(f), tokenListDefine(f), valueDefinedInCode_(false) { - const std::string def(name + ' ' + value); + const std::string def(name + ' ' + value + '\n'); StdCharBufStream stream(reinterpret_cast(def.data()), def.size()); tokenListDefine.readfile(stream); if (!parseDefine(tokenListDefine.cfront())) @@ -1602,7 +1674,7 @@ namespace simplecpp { else if (rawtok->op == ')') --par; else if (rawtok->op == '#' && !sameline(rawtok->previous, rawtok)) - throw Error(rawtok->location, "it is invalid to use a preprocessor directive as macro parameter"); + throw invalidDirectiveAsMacroParameter(rawtok->location); rawtokens2.push_back(new Token(rawtok->str(), rawtok1->location, rawtok->whitespaceahead)); rawtok = rawtok->next; } @@ -1698,6 +1770,11 @@ namespace simplecpp { const std::string what; }; + struct invalidDirectiveAsMacroParameter : public Error { + invalidDirectiveAsMacroParameter(const Location &loc) + : Error(loc, "it is invalid to use a preprocessor directive as macro parameter") {} + }; + /** Struct that is thrown when macro is expanded with wrong number of parameters */ struct wrongNumberOfParameters : public Error { wrongNumberOfParameters(const Location &loc, const std::string ¯oName) : Error(loc, "Wrong number of parameters for macro \'" + macroName + "\'.") {} @@ -3126,8 +3203,8 @@ simplecpp::FileDataCache::FileDataCache() {} simplecpp::FileDataCache::~FileDataCache() = default; -simplecpp::FileDataCache::FileDataCache(FileDataCache &&) noexcept = default; -simplecpp::FileDataCache &simplecpp::FileDataCache::operator=(simplecpp::FileDataCache &&) noexcept = default; +simplecpp::FileDataCache::FileDataCache(FileDataCache &&) SIMPLECPP_NOEXCEPT = default; +simplecpp::FileDataCache &simplecpp::FileDataCache::operator=(simplecpp::FileDataCache &&) SIMPLECPP_NOEXCEPT = default; static bool getFileId(const std::string &path, FileID &id); @@ -3145,7 +3222,7 @@ std::pair simplecpp::FileDataCache::tryload(FileDat return {id_it->second, false}; } - auto *const data = new FileData {path, TokenList(path, filenames, outputList)}; + auto *const data = new FileData {path, TokenList(path, filenames, {}, outputList)}; if (dui.removeComments) data->tokens.removeComments(); @@ -3336,7 +3413,7 @@ simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens, return cache; } -static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token *&tok1, simplecpp::MacroMap ¯os, std::vector &files, simplecpp::OutputList *outputList) +static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token *&tok1, simplecpp::MacroMap ¯os, std::vector &files, simplecpp::OutputList *outputList, const simplecpp::DUI &dui) { const simplecpp::Token * const tok = tok1; const simplecpp::MacroMap::const_iterator it = tok->name ? macros.find(tok->str()) : macros.end(); @@ -3344,6 +3421,16 @@ static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token simplecpp::TokenList value(files); try { tok1 = it->second.expand(value, tok, macros, files); + } catch (const simplecpp::Macro::invalidDirectiveAsMacroParameter &err) { + if (outputList) { + simplecpp::Output out{ + simplecpp::Output::DIRECTIVE_AS_MACRO_PARAMETER, + err.location, + "failed to expand \'" + tok->str() + "\', " + err.what + }; + outputList->emplace_back(std::move(out)); + } + return false; } catch (const simplecpp::Macro::Error &err) { if (outputList) { simplecpp::Output out{ @@ -3357,7 +3444,7 @@ static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token } output.takeTokens(value); } else { - if (!tok->comment) + if (!tok->comment || !dui.removeComments) output.push_back(new simplecpp::Token(*tok)); tok1 = tok->next; } @@ -3552,7 +3639,9 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL continue; } - if (ifstates.size() <= 1U && (rawtok->str() == ELIF || rawtok->str() == ELSE || rawtok->str() == ENDIF)) { + if (ifstates.size() <= 1U && (rawtok->str() == ELIF || rawtok->str() == ELIFDEF || + rawtok->str() == ELIFNDEF || rawtok->str() == ELSE || + rawtok->str() == ENDIF)) { if (outputList) { simplecpp::Output err{ Output::SYNTAX_ERROR, @@ -3632,7 +3721,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL TokenList inc2(files); if (!inc1.empty() && inc1.cfront()->name) { const Token *inctok = inc1.cfront(); - if (!preprocessToken(inc2, inctok, macros, files, outputList)) { + if (!preprocessToken(inc2, inctok, macros, files, outputList, dui)) { output.clear(); return; } @@ -3693,7 +3782,8 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL rawtok = filedata->tokens.cfront(); continue; } - } else if (rawtok->str() == IF || rawtok->str() == IFDEF || rawtok->str() == IFNDEF || rawtok->str() == ELIF) { + } else if (rawtok->str() == IF || rawtok->str() == IFDEF || rawtok->str() == IFNDEF || rawtok->str() == ELIF || + rawtok->str() == ELIFDEF || rawtok->str() == ELIFNDEF) { if (!sameline(rawtok,rawtok->next)) { if (outputList) { simplecpp::Output out{ @@ -3708,15 +3798,28 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL } bool conditionIsTrue; - if (ifstates.top() == AlwaysFalse || (ifstates.top() == ElseIsTrue && rawtok->str() != ELIF)) { + if (ifstates.top() == AlwaysFalse || (ifstates.top() == ElseIsTrue && rawtok->str() != ELIF && + rawtok->str() != ELIFDEF && rawtok->str() != ELIFNDEF)) { conditionIsTrue = false; } - else if (rawtok->str() == IFDEF) { - conditionIsTrue = (macros.find(rawtok->next->str()) != macros.end() || (hasInclude && rawtok->next->str() == HAS_INCLUDE)); - maybeUsedMacros[rawtok->next->str()].emplace_back(rawtok->next->location); - } else if (rawtok->str() == IFNDEF) { - conditionIsTrue = (macros.find(rawtok->next->str()) == macros.end() && !(hasInclude && rawtok->next->str() == HAS_INCLUDE)); - maybeUsedMacros[rawtok->next->str()].emplace_back(rawtok->next->location); + else if (rawtok->str() == IFDEF || rawtok->str() == ELIFDEF) { + const std::string &name = rawtok->next->str(); + conditionIsTrue = (macros.find(name) != macros.end() || (hasInclude && name == HAS_INCLUDE)); + maybeUsedMacros[name].emplace_back(rawtok->next->location); + if (ifCond) { + const std::string E = conditionIsTrue ? "1" : "0"; + const long long result = conditionIsTrue ? 1 : 0; + ifCond->emplace_back(rawtok->location, E, result); + } + } else if (rawtok->str() == IFNDEF || rawtok->str() == ELIFNDEF) { + const std::string &name = rawtok->next->str(); + conditionIsTrue = (macros.find(name) == macros.end() && !(hasInclude && name == HAS_INCLUDE)); + maybeUsedMacros[name].emplace_back(rawtok->next->location); + if (ifCond) { + const std::string E = conditionIsTrue ? "1" : "0"; + const long long result = conditionIsTrue ? 1 : 0; + ifCond->emplace_back(rawtok->location, E, result); + } } else { /*if (rawtok->str() == IF || rawtok->str() == ELIF)*/ TokenList expr(files); for (const Token *tok = rawtok->next; tok && tok->location.sameline(rawtok->location); tok = tok->next) { @@ -3802,7 +3905,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL maybeUsedMacros[rawtok->next->str()].emplace_back(rawtok->next->location); const Token *tmp = tok; - if (!preprocessToken(expr, tmp, macros, files, outputList)) { + if (!preprocessToken(expr, tmp, macros, files, outputList, dui)) { output.clear(); return; } @@ -3839,7 +3942,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL } } - if (rawtok->str() != ELIF) { + if (rawtok->str() != ELIF && rawtok->str() != ELIFDEF && rawtok->str() != ELIFNDEF) { // push a new ifstate.. if (ifstates.top() != True) ifstates.push(AlwaysFalse); @@ -3900,7 +4003,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL const Location loc(rawtok->location); TokenList tokens(files); - if (!preprocessToken(tokens, rawtok, macros, files, outputList)) { + if (!preprocessToken(tokens, rawtok, macros, files, outputList, dui)) { output.clear(); return; } @@ -3959,6 +4062,20 @@ simplecpp::cstd_t simplecpp::getCStd(const std::string &std) return CUnknown; } +const char *simplecpp::getCStdName(cstd_t std) +{ + switch (std) { + case CUnknown: return "C"; + case C89: return "C89"; + case C99: return "C99"; + case C11: return "C11"; + case C17: return "C17"; + case C23: return "C23"; + case C2Y: return "C2Y"; + } + return ""; +} + std::string simplecpp::getCStdString(cstd_t std) { switch (std) { @@ -4011,6 +4128,21 @@ simplecpp::cppstd_t simplecpp::getCppStd(const std::string &std) return CPPUnknown; } +const char *simplecpp::getCppStdName(cppstd_t std) +{ + switch (std) { + case CPPUnknown: return "C++"; + case CPP03: return "C++03"; + case CPP11: return "C++11"; + case CPP14: return "C++14"; + case CPP17: return "C++17"; + case CPP20: return "C++20"; + case CPP23: return "C++23"; + case CPP26: return "C++26"; + } + return ""; +} + std::string simplecpp::getCppStdString(cppstd_t std) { switch (std) { diff --git a/externals/simplecpp/simplecpp.h b/externals/simplecpp/simplecpp.h index 3d6fc5262b9..e64a8f7b4d0 100644 --- a/externals/simplecpp/simplecpp.h +++ b/externals/simplecpp/simplecpp.h @@ -60,6 +60,15 @@ # endif #endif +#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 9 +// Hack to workaround GCC bug. +// Details: https://trac.cppcheck.net/ticket/14850 +// seen on g++ before 10.x +#define SIMPLECPP_NOEXCEPT +#else +#define SIMPLECPP_NOEXCEPT noexcept +#endif + namespace simplecpp { /** C code standard */ enum cstd_t : std::int8_t { CUnknown=-1, C89, C99, C11, C17, C23, C2Y }; @@ -238,7 +247,10 @@ namespace simplecpp { MISSING_HEADER, INCLUDE_NESTED_TOO_DEEPLY, SYNTAX_ERROR, + DIRECTIVE_AS_MACRO_PARAMETER, PORTABILITY_BACKSLASH, + PORTABILITY_LINE_DIRECTIVE, + PORTABILITY_NO_EOF_NEWLINE, UNHANDLED_CHAR_ERROR, EXPLICIT_INCLUDE_NOT_FOUND, FILE_NOT_FOUND, @@ -251,6 +263,21 @@ namespace simplecpp { using OutputList = std::list; + /** + * Command line preprocessor settings. + * On the command line these are configured by -D, -U, -I, --include, -std + */ + struct SIMPLECPP_LIB DUI { + DUI() = default; + std::list defines; + std::set undefined; + std::list includePaths; + std::list includes; + std::string std; + bool clearIncludeCache{}; + bool removeComments{}; /** remove comment tokens from included files */ + }; + /** List of tokens. */ class SIMPLECPP_LIB TokenList { public: @@ -258,45 +285,45 @@ namespace simplecpp { explicit TokenList(std::vector &filenames); /** generates a token list from the given std::istream parameter */ - TokenList(std::istream &istr, std::vector &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr); + TokenList(std::istream &istr, std::vector &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr); /** generates a token list from the given buffer */ template - TokenList(const char (&data)[size], std::vector &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr) - : TokenList(reinterpret_cast(data), size-1, filenames, filename, outputList, 0) + TokenList(const char (&data)[size], std::vector &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr) + : TokenList(reinterpret_cast(data), size-1, filenames, filename, dui, outputList, 0) {} /** generates a token list from the given buffer */ template - TokenList(const unsigned char (&data)[size], std::vector &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr) - : TokenList(data, size-1, filenames, filename, outputList, 0) + TokenList(const unsigned char (&data)[size], std::vector &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr) + : TokenList(data, size-1, filenames, filename, dui, outputList, 0) {} #if SIMPLECPP_TOKENLIST_ALLOW_PTR /** generates a token list from the given buffer */ - TokenList(const unsigned char* data, std::size_t size, std::vector &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr) - : TokenList(data, size, filenames, filename, outputList, 0) + TokenList(const unsigned char* data, std::size_t size, std::vector &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr) + : TokenList(data, size, filenames, filename, dui, outputList, 0) {} /** generates a token list from the given buffer */ - TokenList(const char* data, std::size_t size, std::vector &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr) - : TokenList(reinterpret_cast(data), size, filenames, filename, outputList, 0) + TokenList(const char* data, std::size_t size, std::vector &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr) + : TokenList(reinterpret_cast(data), size, filenames, filename, dui, outputList, 0) {} #endif // SIMPLECPP_TOKENLIST_ALLOW_PTR /** generates a token list from the given buffer */ - TokenList(View data, std::vector &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr) - : TokenList(reinterpret_cast(data.data()), data.size(), filenames, filename, outputList, 0) + TokenList(View data, std::vector &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr) + : TokenList(reinterpret_cast(data.data()), data.size(), filenames, filename, dui, outputList, 0) {} #ifdef __cpp_lib_span /** generates a token list from the given buffer */ - TokenList(std::span data, std::vector &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr) - : TokenList(reinterpret_cast(data.data()), data.size(), filenames, filename, outputList, 0) + TokenList(std::span data, std::vector &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr) + : TokenList(reinterpret_cast(data.data()), data.size(), filenames, filename, dui, outputList, 0) {} /** generates a token list from the given buffer */ - TokenList(std::span data, std::vector &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr) - : TokenList(data.data(), data.size(), filenames, filename, outputList, 0) + TokenList(std::span data, std::vector &filenames, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr) + : TokenList(data.data(), data.size(), filenames, filename, dui, outputList, 0) {} #endif // __cpp_lib_span /** generates a token list from the given filename parameter */ - TokenList(const std::string &filename, std::vector &filenames, OutputList *outputList = nullptr); + TokenList(const std::string &filename, std::vector &filenames, const DUI &dui = {}, OutputList *outputList = nullptr); TokenList(const TokenList &other); TokenList(TokenList &&other); ~TokenList(); @@ -312,7 +339,7 @@ namespace simplecpp { void dump(bool linenrs = false) const; std::string stringify(bool linenrs = false) const; - void readfile(Stream &stream, const std::string &filename=std::string(), OutputList *outputList = nullptr); + void readfile(Stream &stream, const std::string &filename=std::string(), const DUI &dui = {}, OutputList *outputList = nullptr); /** * @throws std::overflow_error thrown on overflow or division by zero * @throws std::runtime_error thrown on invalid expressions @@ -376,7 +403,7 @@ namespace simplecpp { const std::string& file(const Location& loc) const; private: - TokenList(const unsigned char* data, std::size_t size, std::vector &filenames, const std::string &filename, OutputList *outputList, int /*unused*/); + TokenList(const unsigned char* data, std::size_t size, std::vector &filenames, const std::string &filename, const DUI &dui, OutputList *outputList, int /*unused*/); void combineOperators(); @@ -425,21 +452,6 @@ namespace simplecpp { long long result; // condition result }; - /** - * Command line preprocessor settings. - * On the command line these are configured by -D, -U, -I, --include, -std - */ - struct SIMPLECPP_LIB DUI { - DUI() = default; - std::list defines; - std::set undefined; - std::list includePaths; - std::list includes; - std::string std; - bool clearIncludeCache{}; - bool removeComments{}; /** remove comment tokens from included files */ - }; - struct SIMPLECPP_LIB FileData { /** The canonical filename associated with this data */ std::string filename; @@ -453,10 +465,10 @@ namespace simplecpp { ~FileDataCache(); FileDataCache(const FileDataCache &) = delete; - FileDataCache(FileDataCache &&) noexcept; + FileDataCache(FileDataCache &&) SIMPLECPP_NOEXCEPT; FileDataCache &operator=(const FileDataCache &) = delete; - FileDataCache &operator=(FileDataCache &&) noexcept; + FileDataCache &operator=(FileDataCache &&) SIMPLECPP_NOEXCEPT; /** Get the cached data for a file, or load and then return it if it isn't cached. * returns the file data and true if the file was loaded, false if it was cached. */ @@ -578,9 +590,15 @@ namespace simplecpp { /** Returns the C version a given standard */ SIMPLECPP_LIB cstd_t getCStd(const std::string &std); + /** Returns the name of a C standard */ + SIMPLECPP_LIB const char *getCStdName(cstd_t std); + /** Returns the C++ version a given standard */ SIMPLECPP_LIB cppstd_t getCppStd(const std::string &std); + /** Returns the name of a C++ standard */ + SIMPLECPP_LIB const char *getCppStdName(cppstd_t std); + /** Returns the __STDC_VERSION__ value for a given standard */ SIMPLECPP_LIB std::string getCStdString(const std::string &std); SIMPLECPP_LIB std::string getCStdString(cstd_t std); diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 26d98c0c7b4..cc8f8491501 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -894,16 +894,20 @@ std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const std: unsigned int CppCheck::checkBuffer(const FileWithDetails &file, const std::string &cfgname, const char* data, std::size_t size) { - const auto f = [&file, data, size](std::vector& files, simplecpp::OutputList* outputList) { - return simplecpp::TokenList{{data, size}, files, file.spath(), outputList}; + const auto f = [&file, data, size, this](std::vector& files, simplecpp::OutputList* outputList) { + simplecpp::DUI dui; + dui.std = mSettings.standards.getStdForLanguage(file.lang()); + return simplecpp::TokenList{{data, size}, files, file.spath(), dui, outputList}; }; return checkInternal(file, cfgname, f); } unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string &cfgname) { - const auto f = [&file](std::vector& files, simplecpp::OutputList* outputList) { - return simplecpp::TokenList{file.spath(), files, outputList}; + const auto f = [&file, this](std::vector& files, simplecpp::OutputList* outputList) { + simplecpp::DUI dui; + dui.std = mSettings.standards.getStdForLanguage(file.lang()); + return simplecpp::TokenList{file.spath(), files, dui, outputList}; }; return checkInternal(file, cfgname, f); } diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 242c1719ba9..7d269db8ec4 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -648,7 +648,7 @@ namespace { } static bool evalCondition(const std::string& condition, const ProjectConfiguration &p) { - std::string c = '(' + condition + ")"; + std::string c = '(' + condition + ")\n"; replaceAll(c, "$(Configuration)", p.configuration); replaceAll(c, "$(Platform)", p.platformStr); diff --git a/lib/library.cpp b/lib/library.cpp index 2a198001d3c..4e542bc55ef 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -177,7 +177,7 @@ static std::vector getnames(const char *names) static void gettokenlistfromvalid(const std::string& valid, TokenList& tokenList) { - const std::string str(valid + ','); + const std::string str(valid + ",\n"); tokenList.createTokensFromBuffer(str.data(), str.size()); // TODO: check result? for (Token *tok = tokenList.front(); tok; tok = tok->next()) { if (Token::Match(tok,"- %num%")) { diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 3e0b33c7f10..8fe715db864 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -930,6 +930,8 @@ const simplecpp::Output* Preprocessor::reportOutput(const simplecpp::OutputList break; case simplecpp::Output::WARNING: case simplecpp::Output::PORTABILITY_BACKSLASH: + case simplecpp::Output::PORTABILITY_LINE_DIRECTIVE: + case simplecpp::Output::PORTABILITY_NO_EOF_NEWLINE: break; case simplecpp::Output::MISSING_HEADER: { // not considered an "error" @@ -939,6 +941,7 @@ const simplecpp::Output* Preprocessor::reportOutput(const simplecpp::OutputList missingInclude(out.location, out.msg.substr(pos1+1, pos2-pos1-1), out.msg[pos1] == '\"' ? UserHeader : SystemHeader); } break; + case simplecpp::Output::DIRECTIVE_AS_MACRO_PARAMETER: case simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY: case simplecpp::Output::SYNTAX_ERROR: case simplecpp::Output::UNHANDLED_CHAR_ERROR: @@ -963,6 +966,7 @@ static std::string simplecppErrToId(simplecpp::Output::Type type) case simplecpp::Output::ERROR: return "preprocessorErrorDirective"; case simplecpp::Output::SYNTAX_ERROR: + case simplecpp::Output::DIRECTIVE_AS_MACRO_PARAMETER: return "syntaxError"; case simplecpp::Output::UNHANDLED_CHAR_ERROR: return "unhandledChar"; @@ -979,6 +983,8 @@ static std::string simplecppErrToId(simplecpp::Output::Type type) // no handled at all (warnings) case simplecpp::Output::WARNING: case simplecpp::Output::PORTABILITY_BACKSLASH: + case simplecpp::Output::PORTABILITY_LINE_DIRECTIVE: + case simplecpp::Output::PORTABILITY_NO_EOF_NEWLINE: throw std::runtime_error("unexpected simplecpp::Output type " + std::to_string(type)); } diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 9571e04ea00..142385ac641 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -1937,7 +1937,7 @@ static std::shared_ptr createTokenFromExpression(const std::string& retur { std::shared_ptr tokenList = std::make_shared(settings, cpp ? Standards::Language::CPP : Standards::Language::C); { - const std::string code = "return " + returnValue + ";"; + const std::string code = "return " + returnValue + ";\n"; if (!tokenList->createTokensFromBuffer(code.data(), code.size())) return nullptr; } diff --git a/lib/standards.cpp b/lib/standards.cpp index a0ec72c1580..06b129ab8cf 100644 --- a/lib/standards.cpp +++ b/lib/standards.cpp @@ -157,3 +157,15 @@ bool Standards::setStd(const std::string& str) { return setC(str) || setCPP(str); } + +std::string Standards::getStdForLanguage(Standards::Language language) const +{ + switch (language) { + case C: + return getC(); + case CPP: + return getCPP(); + default: + return ""; + } +} diff --git a/lib/standards.h b/lib/standards.h index d2c2a2b8e01..0ab73300a9a 100644 --- a/lib/standards.h +++ b/lib/standards.h @@ -58,6 +58,7 @@ struct CPPCHECKLIB Standards { static std::string getCPP(cppstd_t std); static cppstd_t getCPP(const std::string &std); bool setStd(const std::string& str); + std::string getStdForLanguage(Language language) const; }; /// @} diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index a666c15b536..7a0148a24a2 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -8093,7 +8093,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to if (!typestr.empty()) { ValueType valuetype; TokenList tokenList(mSettings, tok->isCpp() ? Standards::Language::CPP : Standards::Language::C); - const std::string str(typestr+";"); + const std::string str(typestr+";\n"); tokenList.createTokensFromBuffer(str.data(), str.size()); // TODO: check result? tokenList.simplifyStdType(); if (parsedecl(tokenList.front(), &valuetype, mDefaultSignedness, mSettings)) { @@ -8186,7 +8186,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to continue; } TokenList tokenList(mSettings, tok->isCpp() ? Standards::Language::CPP : Standards::Language::C); - const std::string str(typestr+";"); + const std::string str(typestr+";\n"); if (tokenList.createTokensFromBuffer(str.data(), str.size())) { ValueType vt; tokenList.simplifyPlatformTypes(); diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index ca509904db3..384c45e406b 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -354,7 +354,9 @@ bool TokenList::createTokensFromBufferInternal(const char* data, size_t size, co #endif simplecpp::OutputList outputList; - simplecpp::TokenList tokens({data, size}, mFiles, file0, &outputList); + simplecpp::DUI dui; + dui.std = mSettings.standards.getStdForLanguage(mLang); + simplecpp::TokenList tokens({data, size}, mFiles, file0, dui, &outputList); createTokens(std::move(tokens)); diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 5efe698bf61..cbfdafdff3b 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1817,7 +1817,8 @@ static bool isNotEqual(std::pair x, std::pair x, const std::string& y, bool cpp, const Settings& settings) { TokenList tokenList(settings, cpp ? Standards::Language::CPP : Standards::Language::C); - tokenList.createTokensFromBuffer(y.data(), y.size()); // TODO: check result? + const std::string str(y + "\n"); + tokenList.createTokensFromBuffer(str.data(), str.size()); // TODO: check result? return isNotEqual(x, std::make_pair(tokenList.front(), tokenList.back())); } static bool isNotEqual(std::pair x, const ValueType* y, bool cpp, const Settings& settings) @@ -7095,7 +7096,7 @@ static bool getMinMaxValues(const std::string& typestr, MathLib::bigint& maxvalue) { TokenList typeTokens(settings, cpp ? Standards::Language::CPP : Standards::Language::C); - const std::string str(typestr + ";"); + const std::string str(typestr + ";\n"); if (!typeTokens.createTokensFromBuffer(str.data(), str.size())) return false; typeTokens.simplifyPlatformTypes(); diff --git a/test/helpers.cpp b/test/helpers.cpp index 70437207a84..95a2dfae24b 100644 --- a/test/helpers.cpp +++ b/test/helpers.cpp @@ -113,8 +113,12 @@ ScopedFile::~ScopedFile() { void SimpleTokenizer2::preprocess(const char* code, std::size_t size, std::vector &files, const std::string& file0, Tokenizer& tokenizer, ErrorLogger& errorlogger) { + const Standards &standards = tokenizer.getSettings().standards; + const Standards::Language language = tokenizer.isCPP() ? Standards::CPP : Standards::C; simplecpp::OutputList outputList; - simplecpp::TokenList tokens1({code, size}, files, file0, &outputList); + simplecpp::DUI dui; + dui.std = standards.getStdForLanguage(language); + simplecpp::TokenList tokens1({code, size}, files, file0, dui, &outputList); Preprocessor preprocessor(tokens1, tokenizer.getSettings(), errorlogger, Path::identify(tokens1.getFiles()[0], false)); (void)preprocessor.loadFiles(files); // TODO: check result diff --git a/test/test64bit.cpp b/test/test64bit.cpp index cc96da48577..1507f15ec72 100644 --- a/test/test64bit.cpp +++ b/test/test64bit.cpp @@ -58,7 +58,7 @@ class Test64BitPortability : public TestFixture { check("using CharArray = char[16];\n" "void f() {\n" " CharArray foo = \"\";\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct T { std::vector*a[2][2]; };\n" // #11560 @@ -79,7 +79,7 @@ class Test64BitPortability : public TestFixture { check("void foo()\n" "{\n" " a = p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -88,65 +88,65 @@ class Test64BitPortability : public TestFixture { "{\n" " int a = p;\n" " return a + 4;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11]: (portability) Assigning a pointer to an integer is not portable. [AssignmentAddressToInteger]\n", errout_str()); check("int foo(int p[])\n" "{\n" " int a = p;\n" " return a + 4;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11]: (portability) Assigning a pointer to an integer is not portable. [AssignmentAddressToInteger]\n", errout_str()); check("int foo(int p[])\n" "{\n" " int *a = p;\n" " return a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (portability) Returning an address value in a function with integer return type is not portable. [CastAddressToIntegerAtReturn]\n", errout_str()); check("void foo(int x)\n" "{\n" " int *p = x;\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:12]: (portability) Assigning an integer to a pointer is not portable. [AssignmentIntegerToAddress]\n", errout_str()); check("int f(const char *p) {\n" // #4659 " return 6 + p[2] * 256;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int foo(int *p) {\n" // #6096 " bool a = p;\n" " return a;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::array f();\n" "void g() {\n" " std::array a = f();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::array f(int x);\n" "void g(int i) {\n" " std::array a = f(i);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("typedef std::array Array;\n" "Array f(int x);\n" "void g(int i) {\n" " Array a = f(i);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("typedef std::array Array;\n" "Array f();\n" "void g(int i) {\n" " Array a = f();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" // #9951 @@ -174,7 +174,7 @@ class Test64BitPortability : public TestFixture { check("struct Foo { int *p; };\n" "void f(struct Foo *foo) {\n" " int i = foo->p;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11]: (portability) Assigning a pointer to an integer is not portable. [AssignmentAddressToInteger]\n", errout_str()); check("struct S {\n" // #10145 @@ -192,7 +192,7 @@ class Test64BitPortability : public TestFixture { // Ticket #2892 check("void foo(int *p) {\n" " int a = (p != NULL);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -201,74 +201,74 @@ class Test64BitPortability : public TestFixture { check("void foo(int *p) {\n" " int x = 10;\n" " int *a = p + x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int *p) {\n" " int x = 10;\n" " int *a = x + p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int *p) {\n" " int x = 10;\n" " int *a = x * x;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:12]: (portability) Assigning an integer to a pointer is not portable. [AssignmentIntegerToAddress]\n", errout_str()); check("void foo(int *start, int *end) {\n" " int len;\n" " int len = end + 10 - start;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void returnIssues() { check("void* foo(int i) {\n" " return i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (portability) Returning an integer in a function with pointer return type is not portable. [CastIntegerToAddressAtReturn]\n", errout_str()); check("void* foo(int* i) {\n" " return i;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void* foo() {\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int foo(int i) {\n" " return i;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct Foo {};\n" "\n" "int* dostuff(Foo foo) {\n" " return foo;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int foo(char* c) {\n" " return c;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (portability) Returning an address value in a function with integer return type is not portable. [CastAddressToIntegerAtReturn]\n", errout_str()); check("int foo(char* c) {\n" " return 1+c;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (portability) Returning an address value in a function with integer return type is not portable. [CastAddressToIntegerAtReturn]\n", errout_str()); check("std::string foo(char* c) {\n" " return c;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int foo(char *a, char *b) {\n" // #4486 " return a + 1 - b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct s {\n" // 4642 @@ -276,13 +276,13 @@ class Test64BitPortability : public TestFixture { "};\n" "int func(struct s *p) {\n" " return 1 + p->i;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("static void __iomem *f(unsigned int port_no) {\n" " void __iomem *mmio = hpriv->mmio;\n" " return mmio + (port_no * 0x80);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #7247: don't check return statements in nested functions.. @@ -290,7 +290,7 @@ class Test64BitPortability : public TestFixture { " struct {\n" " const char * name() { return \"abc\"; }\n" " } table;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #7451: Lambdas @@ -298,7 +298,7 @@ class Test64BitPortability : public TestFixture { " auto it = std::find_if(outputs.begin(), outputs.end(),\n" " [&](int ele) { return \"test\" == text; });\n" " return nullptr;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" // #12159 diff --git a/test/testassert.cpp b/test/testassert.cpp index ea170c43f2d..24d91518be0 100644 --- a/test/testassert.cpp +++ b/test/testassert.cpp @@ -61,7 +61,7 @@ class TestAssert : public TestFixture { " if (b) { a = 1+2 };\n" " return a;\n" "}\n" - "assert(foo() == 3);"); + "assert(foo() == 3);\n"); ASSERT_EQUALS("", errout_str()); check( @@ -69,7 +69,7 @@ class TestAssert : public TestFixture { " int b=a+1;\n" " return b;\n" "}\n" - "assert(foo(1) == 2);"); + "assert(foo(1) == 2);\n"); ASSERT_EQUALS("", errout_str()); } @@ -80,7 +80,7 @@ class TestAssert : public TestFixture { " a = 1+2;\n" " return a;\n" "}\n" - "assert(foo() == 3);"); + "assert(foo() == 3);\n"); ASSERT_EQUALS("[test.cpp:6:8]: (warning) Assert statement calls a function which may have desired side effects: 'foo'. [assertWithSideEffect]\n", errout_str()); // Ticket #4937 "false positive: Assert calls a function which may have desired side effects" @@ -92,7 +92,7 @@ class TestAssert : public TestFixture { "};\n" "void foo() {\n" " assert( !SquarePack::isRank1Or8(push2) );\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct SquarePack {\n" @@ -103,7 +103,7 @@ class TestAssert : public TestFixture { "};\n" "void foo() {\n" " assert( !SquarePack::isRank1Or8(push2) );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:25]: (warning) Assert statement calls a function which may have desired side effects: 'isRank1Or8'. [assertWithSideEffect]\n", errout_str()); check("struct SquarePack {\n" @@ -114,7 +114,7 @@ class TestAssert : public TestFixture { "};\n" "void foo() {\n" " assert( !SquarePack::isRank1Or8(push2) );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:25]: (warning) Assert statement calls a function which may have desired side effects: 'isRank1Or8'. [assertWithSideEffect]\n", errout_str()); check("struct SquarePack {\n" @@ -125,7 +125,7 @@ class TestAssert : public TestFixture { "};\n" "void foo() {\n" " assert( !SquarePack::isRank1Or8(push2) );\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct Geometry {\n" @@ -136,7 +136,7 @@ class TestAssert : public TestFixture { "\n" "void Geometry::ReadGeometry() {\n" " assert(empty());\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" // #4811 @@ -155,7 +155,7 @@ class TestAssert : public TestFixture { "};\n" "void foo(SquarePack s) {\n" " assert( s.Foo() );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:14]: (warning) Assert statement calls a function which may have desired side effects: 'Foo'. If there are no side effects, consider declaring the method const. [assertWithSideEffect]\n", errout_str()); check("struct SquarePack {\n" @@ -163,7 +163,7 @@ class TestAssert : public TestFixture { "};\n" "void foo(SquarePack* s) {\n" " assert( s->Foo() );\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct SquarePack {\n" @@ -171,14 +171,14 @@ class TestAssert : public TestFixture { "};\n" "void foo(SquarePack* s) {\n" " assert( s->Foo() );\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct SquarePack {\n" "};\n" "void foo(SquarePack* s) {\n" " assert( s->Foo() );\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -187,54 +187,54 @@ class TestAssert : public TestFixture { " int a; a = 0;\n" " assert(a = 2);\n" " return a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:14]: (warning) Assert statement modifies 'a'. [assignmentInAssert]\n", errout_str()); check("void f(int a) {\n" " assert(a == 2);\n" " return a;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int a, int b) {\n" " assert(a == 2 && (b = 1));\n" " return a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:25]: (warning) Assert statement modifies 'b'. [assignmentInAssert]\n", errout_str()); check("void f() {\n" " int a; a = 0;\n" " assert(a += 2);\n" " return a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:14]: (warning) Assert statement modifies 'a'. [assignmentInAssert]\n", errout_str()); check("void f() {\n" " int a; a = 0;\n" " assert(a *= 2);\n" " return a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:14]: (warning) Assert statement modifies 'a'. [assignmentInAssert]\n", errout_str()); check("void f() {\n" " int a; a = 0;\n" " assert(a -= 2);\n" " return a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:14]: (warning) Assert statement modifies 'a'. [assignmentInAssert]\n", errout_str()); check("void f() {\n" " int a = 0;\n" " assert(a--);\n" " return a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:13]: (warning) Assert statement modifies 'a'. [assignmentInAssert]\n", errout_str()); check("void f() {\n" " int a = 0;\n" " assert(--a);\n" " return a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:12]: (warning) Assert statement modifies 'a'. [assignmentInAssert]\n", errout_str()); check("void f() {\n" @@ -243,19 +243,19 @@ class TestAssert : public TestFixture { " auto const expected = someOtherValue;\n" " return tmp == expected;\n" " }));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void crash() { check("void foo() {\n" " assert(sizeof(struct { int a[x++]; })==sizeof(int));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" // #9790 " assert(kad_bucket_hash(&(kad_guid) { .bytes = { 0 } }, & (kad_guid){.bytes = { 0 }}) == -1);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } }; diff --git a/test/testastutils.cpp b/test/testastutils.cpp index 6a6e0624587..46dde522338 100644 --- a/test/testastutils.cpp +++ b/test/testastutils.cpp @@ -62,29 +62,29 @@ class TestAstUtils : public TestFixture { void findLambdaEndTokenTest() { const Token* nullTok = nullptr; ASSERT(nullptr == (::findLambdaEndToken)(nullTok)); - ASSERT_EQUALS(false, findLambdaEndToken("void f() { }")); - ASSERT_EQUALS(true, findLambdaEndToken("[]{ }")); - ASSERT_EQUALS(true, findLambdaEndToken("[]{ return 0; }")); - ASSERT_EQUALS(true, findLambdaEndToken("[](){ }")); - ASSERT_EQUALS(true, findLambdaEndToken("[&](){ }")); - ASSERT_EQUALS(true, findLambdaEndToken("[&, i](){ }")); - ASSERT_EQUALS(true, findLambdaEndToken("[](void) { return -1; }")); - ASSERT_EQUALS(true, findLambdaEndToken("[](int a, int b) { return a + b; }")); - ASSERT_EQUALS(true, findLambdaEndToken("[](int a, int b) mutable { return a + b; }")); - ASSERT_EQUALS(true, findLambdaEndToken("[](int a, int b) constexpr { return a + b; }")); - ASSERT_EQUALS(true, findLambdaEndToken("[](void) -> int { return -1; }")); - ASSERT_EQUALS(true, findLambdaEndToken("[](void) mutable -> int { return -1; }")); - ASSERT_EQUALS(false, findLambdaEndToken("[](void) foo -> int { return -1; }")); - ASSERT_EQUALS(true, findLambdaEndToken("[](void) constexpr -> int { return -1; }")); - ASSERT_EQUALS(true, findLambdaEndToken("[](void) constexpr -> int* { return x; }")); - ASSERT_EQUALS(true, findLambdaEndToken("[](void) constexpr -> const * int { return x; }")); - ASSERT_EQUALS(true, findLambdaEndToken("[](void) mutable -> const * int { return x; }")); - ASSERT_EQUALS(true, findLambdaEndToken("[](void) constexpr -> const ** int { return x; }")); - ASSERT_EQUALS(true, findLambdaEndToken("[](void) constexpr -> const * const* int { return x; }")); - ASSERT_EQUALS(false, findLambdaEndToken("int** a[] { new int*[2] { new int, new int} };", "[ ]")); - ASSERT_EQUALS(false, findLambdaEndToken("int** a[] { new int*[2] { new int, new int} };", "[ 2")); - ASSERT_EQUALS(false, findLambdaEndToken("shared_ptr sp{ new Type *[2] {new Type, new Type}, Deleter{ 2 } };", "[ 2")); - ASSERT_EQUALS(true, findLambdaEndToken("int i = 5 * []{ return 7; }();", "[", /*checkNext*/ false)); + ASSERT_EQUALS(false, findLambdaEndToken("void f() { }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[]{ }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[]{ return 0; }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[](){ }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[&](){ }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[&, i](){ }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[](void) { return -1; }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[](int a, int b) { return a + b; }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[](int a, int b) mutable { return a + b; }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[](int a, int b) constexpr { return a + b; }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[](void) -> int { return -1; }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[](void) mutable -> int { return -1; }\n")); + ASSERT_EQUALS(false, findLambdaEndToken("[](void) foo -> int { return -1; }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[](void) constexpr -> int { return -1; }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[](void) constexpr -> int* { return x; }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[](void) constexpr -> const * int { return x; }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[](void) mutable -> const * int { return x; }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[](void) constexpr -> const ** int { return x; }\n")); + ASSERT_EQUALS(true, findLambdaEndToken("[](void) constexpr -> const * const* int { return x; }\n")); + ASSERT_EQUALS(false, findLambdaEndToken("int** a[] { new int*[2] { new int, new int} };\n", "[ ]")); + ASSERT_EQUALS(false, findLambdaEndToken("int** a[] { new int*[2] { new int, new int} };\n", "[ 2")); + ASSERT_EQUALS(false, findLambdaEndToken("shared_ptr sp{ new Type *[2] {new Type, new Type}, Deleter{ 2 } };\n", "[ 2")); + ASSERT_EQUALS(true, findLambdaEndToken("int i = 5 * []{ return 7; }();\n", "[", /*checkNext*/ false)); } #define findLambdaStartToken(...) findLambdaStartToken_(__FILE__, __LINE__, __VA_ARGS__) @@ -98,25 +98,25 @@ class TestAstUtils : public TestFixture { void findLambdaStartTokenTest() { ASSERT(nullptr == (::findLambdaStartToken)(nullptr)); - ASSERT_EQUALS(false, findLambdaStartToken("void f() { }")); - ASSERT_EQUALS(true, findLambdaStartToken("[]{ }")); - ASSERT_EQUALS(true, findLambdaStartToken("[]{ return 0; }")); - ASSERT_EQUALS(true, findLambdaStartToken("[](){ }")); - ASSERT_EQUALS(true, findLambdaStartToken("[&](){ }")); - ASSERT_EQUALS(true, findLambdaStartToken("[&, i](){ }")); - ASSERT_EQUALS(true, findLambdaStartToken("[](void) { return -1; }")); - ASSERT_EQUALS(true, findLambdaStartToken("[](int a, int b) { return a + b; }")); - ASSERT_EQUALS(true, findLambdaStartToken("[](int a, int b) mutable { return a + b; }")); - ASSERT_EQUALS(true, findLambdaStartToken("[](int a, int b) constexpr { return a + b; }")); - ASSERT_EQUALS(true, findLambdaStartToken("[](void) -> int { return -1; }")); - ASSERT_EQUALS(true, findLambdaStartToken("[](void) mutable -> int { return -1; }")); - ASSERT_EQUALS(false, findLambdaStartToken("[](void) foo -> int { return -1; }")); - ASSERT_EQUALS(true, findLambdaStartToken("[](void) constexpr -> int { return -1; }")); - ASSERT_EQUALS(true, findLambdaStartToken("[](void) constexpr -> int* { return x; }")); - ASSERT_EQUALS(true, findLambdaStartToken("[](void) constexpr -> const * int { return x; }")); - ASSERT_EQUALS(true, findLambdaStartToken("[](void) mutable -> const * int { return x; }")); - ASSERT_EQUALS(true, findLambdaStartToken("[](void) constexpr -> const ** int { return x; }")); - ASSERT_EQUALS(true, findLambdaStartToken("[](void) constexpr -> const * const* int { return x; }")); + ASSERT_EQUALS(false, findLambdaStartToken("void f() { }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[]{ }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[]{ return 0; }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[](){ }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[&](){ }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[&, i](){ }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[](void) { return -1; }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[](int a, int b) { return a + b; }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[](int a, int b) mutable { return a + b; }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[](int a, int b) constexpr { return a + b; }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[](void) -> int { return -1; }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[](void) mutable -> int { return -1; }\n")); + ASSERT_EQUALS(false, findLambdaStartToken("[](void) foo -> int { return -1; }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[](void) constexpr -> int { return -1; }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[](void) constexpr -> int* { return x; }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[](void) constexpr -> const * int { return x; }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[](void) mutable -> const * int { return x; }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[](void) constexpr -> const ** int { return x; }\n")); + ASSERT_EQUALS(true, findLambdaStartToken("[](void) constexpr -> const * const* int { return x; }\n")); } #define isNullOperand(...) isNullOperand_(__FILE__, __LINE__, __VA_ARGS__) @@ -128,16 +128,16 @@ class TestAstUtils : public TestFixture { } void isNullOperandTest() { - ASSERT_EQUALS(true, isNullOperand("(void*)0;")); - ASSERT_EQUALS(true, isNullOperand("(void*)0U;")); - ASSERT_EQUALS(true, isNullOperand("(void*)0x0LL;")); - ASSERT_EQUALS(true, isNullOperand("NULL;")); - ASSERT_EQUALS(true, isNullOperand("nullptr;")); - ASSERT_EQUALS(true, isNullOperand("(void*)NULL;")); - ASSERT_EQUALS(true, isNullOperand("static_cast(0);")); - ASSERT_EQUALS(false, isNullOperand("0;")); - ASSERT_EQUALS(false, isNullOperand("(void*)0.0;")); - ASSERT_EQUALS(false, isNullOperand("(void*)1;")); + ASSERT_EQUALS(true, isNullOperand("(void*)0;\n")); + ASSERT_EQUALS(true, isNullOperand("(void*)0U;\n")); + ASSERT_EQUALS(true, isNullOperand("(void*)0x0LL;\n")); + ASSERT_EQUALS(true, isNullOperand("NULL;\n")); + ASSERT_EQUALS(true, isNullOperand("nullptr;\n")); + ASSERT_EQUALS(true, isNullOperand("(void*)NULL;\n")); + ASSERT_EQUALS(true, isNullOperand("static_cast(0);\n")); + ASSERT_EQUALS(false, isNullOperand("0;\n")); + ASSERT_EQUALS(false, isNullOperand("(void*)0.0;\n")); + ASSERT_EQUALS(false, isNullOperand("(void*)1;\n")); } #define isReturnScope(...) isReturnScope_(__FILE__, __LINE__, __VA_ARGS__) @@ -152,22 +152,22 @@ class TestAstUtils : public TestFixture { } void isReturnScopeTest() { - ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { return; } }", -2)); - ASSERT_EQUALS(true, isReturnScope("int f() { if (a) { return {}; } }", -2)); // #8891 - ASSERT_EQUALS(true, isReturnScope("std::string f() { if (a) { return std::string{}; } }", -2)); // #8891 - ASSERT_EQUALS(true, isReturnScope("std::string f() { if (a) { return std::string{\"\"}; } }", -2)); // #8891 - ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { return (ab){0}; } }", -2)); // #7103 - ASSERT_EQUALS(false, isReturnScope("void f() { if (a) { return (ab){0}; } }", -4)); // #7103 - ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string(x);}; } }", -4)); // #7144 - ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string(x);}; } }", -2)); // #7144 - ASSERT_EQUALS(false, isReturnScope("void f() { [=]() { return data; }; }", -1)); - ASSERT_EQUALS(true, isReturnScope("auto f() { return [=]() { return data; }; }", -1)); - ASSERT_EQUALS(true, isReturnScope("auto f() { return [=]() { return data; }(); }", -1)); - ASSERT_EQUALS(false, isReturnScope("auto f() { [=]() { return data; }(); }", -1)); - - ASSERT_EQUALS(true, isReturnScope("void negativeTokenOffset() { return; }", -1)); - ASSERT_EQUALS(false, isReturnScope("void zeroTokenOffset() { return; }", 0)); - ASSERT_EQUALS(true, isReturnScope("void positiveTokenOffset() { return; }", 7)); + ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { return; } }\n", -2)); + ASSERT_EQUALS(true, isReturnScope("int f() { if (a) { return {}; } }\n", -2)); // #8891 + ASSERT_EQUALS(true, isReturnScope("std::string f() { if (a) { return std::string{}; } }\n", -2)); // #8891 + ASSERT_EQUALS(true, isReturnScope("std::string f() { if (a) { return std::string{\"\"}; } }\n", -2)); // #8891 + ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { return (ab){0}; } }\n", -2)); // #7103 + ASSERT_EQUALS(false, isReturnScope("void f() { if (a) { return (ab){0}; } }\n", -4)); // #7103 + ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string(x);}; } }\n", -4)); // #7144 + ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string(x);}; } }\n", -2)); // #7144 + ASSERT_EQUALS(false, isReturnScope("void f() { [=]() { return data; }; }\n", -1)); + ASSERT_EQUALS(true, isReturnScope("auto f() { return [=]() { return data; }; }\n", -1)); + ASSERT_EQUALS(true, isReturnScope("auto f() { return [=]() { return data; }(); }\n", -1)); + ASSERT_EQUALS(false, isReturnScope("auto f() { [=]() { return data; }(); }\n", -1)); + + ASSERT_EQUALS(true, isReturnScope("void negativeTokenOffset() { return; }\n", -1)); + ASSERT_EQUALS(false, isReturnScope("void zeroTokenOffset() { return; }\n", 0)); + ASSERT_EQUALS(true, isReturnScope("void positiveTokenOffset() { return; }\n", 7)); } #define isSameExpression(...) isSameExpression_(__FILE__, __LINE__, __VA_ARGS__) @@ -181,33 +181,33 @@ class TestAstUtils : public TestFixture { } void isSameExpressionTestInternal(bool cpp) { - ASSERT_EQUALS(true, isSameExpression("x = 1 + 1;", "1", "1", cpp)); - ASSERT_EQUALS(false, isSameExpression("x = 1 + 1u;", "1", "1u", cpp)); - ASSERT_EQUALS(true, isSameExpression("x = 1.0 + 1.0;", "1.0", "1.0", cpp)); - ASSERT_EQUALS(false, isSameExpression("x = 1.0f + 1.0;", "1.0f", "1.0", cpp)); - ASSERT_EQUALS(false, isSameExpression("x = 1L + 1;", "1L", "1", cpp)); - ASSERT_EQUALS(true, isSameExpression("x = 0.0f + 0x0p+0f;", "0.0f", "0x0p+0f", cpp)); - ASSERT_EQUALS(true, isSameExpression("x < x;", "x", "x", cpp)); - ASSERT_EQUALS(false, isSameExpression("x < y;", "x", "y", cpp)); - ASSERT_EQUALS(true, isSameExpression("(x + 1) < (x + 1);", "+", "+", cpp)); - ASSERT_EQUALS(false, isSameExpression("(x + 1) < (x + 1L);", "+", "+", cpp)); - ASSERT_EQUALS(!cpp, isSameExpression("(1 + x) < (x + 1);", "+", "+", cpp)); - ASSERT_EQUALS(false, isSameExpression("(1.0l + x) < (1.0 + x);", "+", "+", cpp)); - ASSERT_EQUALS(!cpp, isSameExpression("(0.0 + x) < (x + 0x0p+0);", "+", "+", cpp)); - ASSERT_EQUALS(true, isSameExpression("void f() {double y = 1e1; (x + y) < (x + 10.0); } ", "+", "+", cpp)); - ASSERT_EQUALS(!cpp, isSameExpression("void f() {double y = 1e1; (x + 10.0) < (y + x); } ", "+", "+", cpp)); - ASSERT_EQUALS(true, isSameExpression("void f() {double y = 1e1; double z = 10.0; (x + y) < (x + z); } ", "+", "+", cpp)); - ASSERT_EQUALS(true, isSameExpression("A + A", "A", "A", cpp)); + ASSERT_EQUALS(true, isSameExpression("x = 1 + 1;\n", "1", "1", cpp)); + ASSERT_EQUALS(false, isSameExpression("x = 1 + 1u;\n", "1", "1u", cpp)); + ASSERT_EQUALS(true, isSameExpression("x = 1.0 + 1.0;\n", "1.0", "1.0", cpp)); + ASSERT_EQUALS(false, isSameExpression("x = 1.0f + 1.0;\n", "1.0f", "1.0", cpp)); + ASSERT_EQUALS(false, isSameExpression("x = 1L + 1;\n", "1L", "1", cpp)); + ASSERT_EQUALS(true, isSameExpression("x = 0.0f + 0x0p+0f;\n", "0.0f", "0x0p+0f", cpp)); + ASSERT_EQUALS(true, isSameExpression("x < x;\n", "x", "x", cpp)); + ASSERT_EQUALS(false, isSameExpression("x < y;\n", "x", "y", cpp)); + ASSERT_EQUALS(true, isSameExpression("(x + 1) < (x + 1);\n", "+", "+", cpp)); + ASSERT_EQUALS(false, isSameExpression("(x + 1) < (x + 1L);\n", "+", "+", cpp)); + ASSERT_EQUALS(!cpp, isSameExpression("(1 + x) < (x + 1);\n", "+", "+", cpp)); + ASSERT_EQUALS(false, isSameExpression("(1.0l + x) < (1.0 + x);\n", "+", "+", cpp)); + ASSERT_EQUALS(!cpp, isSameExpression("(0.0 + x) < (x + 0x0p+0);\n", "+", "+", cpp)); + ASSERT_EQUALS(true, isSameExpression("void f() {double y = 1e1; (x + y) < (x + 10.0); } \n", "+", "+", cpp)); + ASSERT_EQUALS(!cpp, isSameExpression("void f() {double y = 1e1; (x + 10.0) < (y + x); } \n", "+", "+", cpp)); + ASSERT_EQUALS(true, isSameExpression("void f() {double y = 1e1; double z = 10.0; (x + y) < (x + z); } \n", "+", "+", cpp)); + ASSERT_EQUALS(true, isSameExpression("A + A\n", "A", "A", cpp)); // the remaining test cases are not valid C code if (!cpp) return; //https://trac.cppcheck.net/ticket/9700 - ASSERT_EQUALS(true, isSameExpression("A::B + A::B;", "::", "::", cpp)); - ASSERT_EQUALS(false, isSameExpression("A::B + A::C;", "::", "::", cpp)); - ASSERT_EQUALS(true, isSameExpression("A::B* get() { if(x) return new A::B(true); else return new A::B(true); }", "new", "new", cpp)); - ASSERT_EQUALS(false, isSameExpression("A::B* get() { if(x) return new A::B(true); else return new A::C(true); }", "new", "new", cpp)); + ASSERT_EQUALS(true, isSameExpression("A::B + A::B;\n", "::", "::", cpp)); + ASSERT_EQUALS(false, isSameExpression("A::B + A::C;\n", "::", "::", cpp)); + ASSERT_EQUALS(true, isSameExpression("A::B* get() { if(x) return new A::B(true); else return new A::B(true); }\n", "new", "new", cpp)); + ASSERT_EQUALS(false, isSameExpression("A::B* get() { if(x) return new A::B(true); else return new A::C(true); }\n", "new", "new", cpp)); } void isSameExpressionCpp() { @@ -233,7 +233,7 @@ class TestAstUtils : public TestFixture { (void)isVariableChanged("void f() {\n" " int b;\n" " if (b) { (int)((INTOF(8))result >> b); }\n" - "}", "if", "}"); + "}\n", "if", "}"); // #9235 ASSERT_EQUALS(false, isVariableChanged("void f() {\n" @@ -242,13 +242,13 @@ class TestAstUtils : public TestFixture { "= a", "}")); - ASSERT_EQUALS(false, isVariableChanged("void f(const A& a) { a.f(); }", "{", "}")); + ASSERT_EQUALS(false, isVariableChanged("void f(const A& a) { a.f(); }\n", "{", "}")); ASSERT_EQUALS(true, isVariableChanged("void g(int*);\n" "void f(int x) { g(&x); }\n", "{", "}")); - ASSERT_EQUALS(false, isVariableChanged("const int A[] = { 1, 2, 3 };", "[", "]")); + ASSERT_EQUALS(false, isVariableChanged("const int A[] = { 1, 2, 3 };\n", "[", "]")); } #define isVariableChangedByFunctionCall(...) isVariableChangedByFunctionCall_( __FILE__, __LINE__, __VA_ARGS__) @@ -267,7 +267,7 @@ class TestAstUtils : public TestFixture { { // #8271 - template method const char code[] = "void f(int x) {\n" " a(x);\n" - "}"; + "}\n"; bool inconclusive = false; ASSERT_EQUALS(false, isVariableChangedByFunctionCall(code, "x ) ;", &inconclusive)); ASSERT_EQUALS(true, inconclusive); @@ -431,8 +431,8 @@ class TestAstUtils : public TestFixture { void isExpressionChangedTest() { - ASSERT_EQUALS(true, isExpressionChanged("void f(std::map& m) { m[0]; }", "m [", "{", "}")); - ASSERT_EQUALS(false, isExpressionChanged("void f(const A& a) { a.f(); }", "a .", "{", "}")); + ASSERT_EQUALS(true, isExpressionChanged("void f(std::map& m) { m[0]; }\n", "m [", "{", "}")); + ASSERT_EQUALS(false, isExpressionChanged("void f(const A& a) { a.f(); }\n", "a .", "{", "}")); ASSERT_EQUALS(true, isExpressionChanged("void g(int*);\n" @@ -459,17 +459,17 @@ class TestAstUtils : public TestFixture { } void nextAfterAstRightmostLeafTest() { - ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("void f(int a, int b) { int x = a + b; }", "=", "; }")); - ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a); }", "=", "; }")); - ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a)[b]; }", "=", "; }")); - ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(g(a)[b]); }", "=", "; }")); - ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(g(a)[b] + a); }", "=", "; }")); - ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a)[b + 1]; }", "=", "; }")); - ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("void f() { int a; int b; int x = [](int a){}; }", "=", "; }")); - - ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = a + b; }", "+", "; }")); - ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a)[b + 1]; }", "+", "] ; }")); - ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a + 1)[b]; }", "+", ") [")); + ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("void f(int a, int b) { int x = a + b; }\n", "=", "; }")); + ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a); }\n", "=", "; }")); + ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a)[b]; }\n", "=", "; }")); + ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(g(a)[b]); }\n", "=", "; }")); + ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(g(a)[b] + a); }\n", "=", "; }")); + ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a)[b + 1]; }\n", "=", "; }")); + ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("void f() { int a; int b; int x = [](int a){}; }\n", "=", "; }")); + + ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = a + b; }\n", "+", "; }")); + ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a)[b + 1]; }\n", "+", "] ; }")); + ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a + 1)[b]; }\n", "+", ") [")); } enum class Result : std::uint8_t {False, True, Fail}; @@ -486,37 +486,37 @@ class TestAstUtils : public TestFixture { } void isUsedAsBool() { - ASSERT(Result::True == isUsedAsBool("void f() { bool b = true; }", "b")); - ASSERT(Result::False ==isUsedAsBool("void f() { int i = true; }", "i")); - ASSERT(Result::True == isUsedAsBool("void f() { int i; if (i) {} }", "i )")); - ASSERT(Result::True == isUsedAsBool("void f() { int i; while (i) {} }", "i )")); - ASSERT(Result::True == isUsedAsBool("void f() { int i; for (;i;) {} }", "i ; )")); - ASSERT(Result::False == isUsedAsBool("void f() { int i; for (;;i) {} }", "i )")); - ASSERT(Result::False == isUsedAsBool("void f() { int i; for (i;;) {} }", "i ; ; )")); - ASSERT(Result::True == isUsedAsBool("void f() { int i; for (int j=0; i; ++j) {} }", "i ; ++")); - ASSERT(Result::False == isUsedAsBool("void f() { int i; if (i == 2) {} }", "i ==")); - ASSERT(Result::False == isUsedAsBool("void f() { int i; if (i == true) {} }", "i ==")); - ASSERT(Result::False == isUsedAsBool("void f() { int i,j; if (i == (j&&f())) {} }", "i ==")); - ASSERT(Result::True == isUsedAsBool("void f() { int i; if (!i == 0) {} }", "i ==")); - ASSERT(Result::True == isUsedAsBool("void f() { int i; if (!i) {} }", "i )")); - ASSERT(Result::True == isUsedAsBool("void f() { int i; if (!!i) {} }", "i )")); - ASSERT(Result::True == isUsedAsBool("void f() { int i; if (i && f()) {} }", "i &&")); - ASSERT(Result::True == isUsedAsBool("void f() { int i; int j = i && f(); }", "i &&")); - ASSERT(Result::False == isUsedAsBool("void f() { int i; if (i & f()) {} }", "i &")); - ASSERT(Result::True == isUsedAsBool("void f() { int i; if (static_cast(i)) {} }", "i )")); - ASSERT(Result::True == isUsedAsBool("void f() { int i; if ((bool)i) {} }", "i )")); - ASSERT(Result::True == isUsedAsBool("void f() { int i; if (1+static_cast(i)) {} }", "i )")); - ASSERT(Result::True == isUsedAsBool("void f() { int i; if (1+(bool)i) {} }", "i )")); - ASSERT(Result::False == isUsedAsBool("void f() { int i; if (1+static_cast(i)) {} }", "i )")); - ASSERT(Result::True == isUsedAsBool("void f() { int i; if (1+!static_cast(i)) {} }", "i )")); - ASSERT(Result::False == isUsedAsBool("void f() { int i; if (1+(int)i) {} }", "i )")); - ASSERT(Result::False == isUsedAsBool("void f() { int i; if (i + 2) {} }", "i +")); - ASSERT(Result::True == isUsedAsBool("void f() { int i; bool b = i; }", "i ; }")); - ASSERT(Result::True == isUsedAsBool("void f(bool b); void f() { int i; f(i); }","i )")); - ASSERT(Result::False == isUsedAsBool("void f() { int *i; if (*i) {} }", "i )")); - ASSERT(Result::True == isUsedAsBool("void f() { int *i; if (*i) {} }", "* i )")); - ASSERT(Result::True == isUsedAsBool("int g(); void h(bool); void f() { h(g()); }", "( ) )")); - ASSERT(Result::True == isUsedAsBool("int g(int); void h(bool); void f() { h(g(0)); }", "( 0 ) )")); + ASSERT(Result::True == isUsedAsBool("void f() { bool b = true; }\n", "b")); + ASSERT(Result::False ==isUsedAsBool("void f() { int i = true; }\n", "i")); + ASSERT(Result::True == isUsedAsBool("void f() { int i; if (i) {} }\n", "i )")); + ASSERT(Result::True == isUsedAsBool("void f() { int i; while (i) {} }\n", "i )")); + ASSERT(Result::True == isUsedAsBool("void f() { int i; for (;i;) {} }\n", "i ; )")); + ASSERT(Result::False == isUsedAsBool("void f() { int i; for (;;i) {} }\n", "i )")); + ASSERT(Result::False == isUsedAsBool("void f() { int i; for (i;;) {} }\n", "i ; ; )")); + ASSERT(Result::True == isUsedAsBool("void f() { int i; for (int j=0; i; ++j) {} }\n", "i ; ++")); + ASSERT(Result::False == isUsedAsBool("void f() { int i; if (i == 2) {} }\n", "i ==")); + ASSERT(Result::False == isUsedAsBool("void f() { int i; if (i == true) {} }\n", "i ==")); + ASSERT(Result::False == isUsedAsBool("void f() { int i,j; if (i == (j&&f())) {} }\n", "i ==")); + ASSERT(Result::True == isUsedAsBool("void f() { int i; if (!i == 0) {} }\n", "i ==")); + ASSERT(Result::True == isUsedAsBool("void f() { int i; if (!i) {} }\n", "i )")); + ASSERT(Result::True == isUsedAsBool("void f() { int i; if (!!i) {} }\n", "i )")); + ASSERT(Result::True == isUsedAsBool("void f() { int i; if (i && f()) {} }\n", "i &&")); + ASSERT(Result::True == isUsedAsBool("void f() { int i; int j = i && f(); }\n", "i &&")); + ASSERT(Result::False == isUsedAsBool("void f() { int i; if (i & f()) {} }\n", "i &")); + ASSERT(Result::True == isUsedAsBool("void f() { int i; if (static_cast(i)) {} }\n", "i )")); + ASSERT(Result::True == isUsedAsBool("void f() { int i; if ((bool)i) {} }\n", "i )")); + ASSERT(Result::True == isUsedAsBool("void f() { int i; if (1+static_cast(i)) {} }\n", "i )")); + ASSERT(Result::True == isUsedAsBool("void f() { int i; if (1+(bool)i) {} }\n", "i )")); + ASSERT(Result::False == isUsedAsBool("void f() { int i; if (1+static_cast(i)) {} }\n", "i )")); + ASSERT(Result::True == isUsedAsBool("void f() { int i; if (1+!static_cast(i)) {} }\n", "i )")); + ASSERT(Result::False == isUsedAsBool("void f() { int i; if (1+(int)i) {} }\n", "i )")); + ASSERT(Result::False == isUsedAsBool("void f() { int i; if (i + 2) {} }\n", "i +")); + ASSERT(Result::True == isUsedAsBool("void f() { int i; bool b = i; }\n", "i ; }")); + ASSERT(Result::True == isUsedAsBool("void f(bool b); void f() { int i; f(i); }\n","i )")); + ASSERT(Result::False == isUsedAsBool("void f() { int *i; if (*i) {} }\n", "i )")); + ASSERT(Result::True == isUsedAsBool("void f() { int *i; if (*i) {} }\n", "* i )")); + ASSERT(Result::True == isUsedAsBool("int g(); void h(bool); void f() { h(g()); }\n", "( ) )")); + ASSERT(Result::True == isUsedAsBool("int g(int); void h(bool); void f() { h(g(0)); }\n", "( 0 ) )")); } }; diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 7774d7fa733..dbec2bae0a0 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -180,21 +180,21 @@ class TestAutoVariables : public TestFixture { "{\n" " int num = 2;\n" " *res = #\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("void func1(int **res)\n" "{\n" " int num = 2;\n" " res = #\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]\n", errout_str()); check("void func1(int **res)\n" "{\n" " int num = 2;\n" " foo.res = #\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -206,7 +206,7 @@ class TestAutoVariables : public TestFixture { "{\n" " int num = 2;\n" " *res = #\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("class Fred {\n" @@ -216,7 +216,7 @@ class TestAutoVariables : public TestFixture { "{\n" " int num = 2;\n" " res = #\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:5]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]\n", errout_str()); check("class Fred {\n" @@ -226,7 +226,7 @@ class TestAutoVariables : public TestFixture { "{\n" " int num = 2;\n" " foo.res = #\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -235,7 +235,7 @@ class TestAutoVariables : public TestFixture { "{\n" " int x[100];\n" " *p = x;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } @@ -244,7 +244,7 @@ class TestAutoVariables : public TestFixture { "{\n" " static int x[100];\n" " *p = x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -253,7 +253,7 @@ class TestAutoVariables : public TestFixture { "{\n" " char a;\n" " ab->a = &a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (error, inconclusive) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } @@ -262,14 +262,14 @@ class TestAutoVariables : public TestFixture { "{\n" " char a[10];\n" " x->str = a;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("void foo(struct X *x)\n" "{\n" " char a[10];\n" " x->str = a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (error, inconclusive) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } @@ -279,7 +279,7 @@ class TestAutoVariables : public TestFixture { " struct txt_scrollpane_s * scrollpane;\n" " target->parent = &scrollpane->widget;\n" " return scrollpane;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); } @@ -287,12 +287,12 @@ class TestAutoVariables : public TestFixture { check("void foo(int*& p) {\n" " int i = 0;\n" " p = &i;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("void foo(std::string& s) {\n" " s = foo;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); } @@ -303,7 +303,7 @@ class TestAutoVariables : public TestFixture { " FN fn;\n" " FP fp;\n" " p = &fn.i;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:6:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("struct FN {int i;};\n" @@ -312,7 +312,7 @@ class TestAutoVariables : public TestFixture { " FN fn;\n" " FP fp;\n" " p = &p_fp->i;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("struct FN {int i;};\n" @@ -321,100 +321,100 @@ class TestAutoVariables : public TestFixture { " FN fn;\n" " FP fp;\n" " p = &fp.f->i;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); } void testautovar10() { // #2930 - assignment of function parameter check("void foo(char* p) {\n" " p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]\n", errout_str()); check("void foo(int b) {\n" " b = foo(b);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (style) Assignment of function parameter has no effect outside the function. [uselessAssignmentArg]\n", errout_str()); check("void foo(int b) {\n" " b += 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (style) Assignment of function parameter has no effect outside the function. [uselessAssignmentArg]\n", errout_str()); check("void foo(std::string s) {\n" " s = foo(b);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (style) Assignment of function parameter has no effect outside the function. [uselessAssignmentArg]\n", errout_str()); check("void foo(char* p) {\n" // don't warn for self assignment, there is another warning for this " p = p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char* p) {\n" " if (!p) p = buf;\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char* p) {\n" " if (!p) p = buf;\n" " do_something(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char* p) {\n" " while (!p) p = buf;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char* p) {\n" " p = 0;\n" " asm(\"somecmd\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(Foo* p) {\n" " p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]\n", errout_str()); check("class Foo {};\n" "void foo(Foo p) {\n" " p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (style) Assignment of function parameter has no effect outside the function. [uselessAssignmentArg]\n", errout_str()); check("void foo(Foo p) {\n" " p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int& p) {\n" " p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("double foo(double d) {\n" // #5005 " int i = d;\n" " d = i;\n" - " return d;" - "}",dinit(CheckOptions, $.inconclusive = false)); + " return d;\n" + "}\n",dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("void foo(int* ptr) {\n" // #4793 " ptr++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]\n", errout_str()); check("void foo(int* ptr) {\n" // #3177 " --ptr;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:7]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]\n", errout_str()); check("void foo(struct S* const x) {\n" // #7839 " ++x->n;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -425,7 +425,7 @@ class TestAutoVariables : public TestFixture { "void foo(char** p) {\n" " struct A a = bar();\n" " *p = &(*a.data)[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" @@ -434,36 +434,36 @@ class TestAutoVariables : public TestFixture { "void foo(char** p) {\n" " struct A a = bar();\n" " *p = &a.data[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("void f(char **out) {\n" " struct S *p = glob;\n" " *out = &p->data;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #4998 check("void f(s8**out) {\n" " s8 *p;\n" // <- p is pointer => no error " *out = &p[1];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(s8**out) {\n" " s8 p[10];\n" // <- p is array => error " *out = &p[1];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:3]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } void testautovar12() { // Ticket #5024, #5050 - Crash on invalid input - ASSERT_THROW_INTERNAL(check("void f(int* a) { a = }"), SYNTAX); + ASSERT_THROW_INTERNAL(check("void f(int* a) { a = }\n"), SYNTAX); check("struct custom_type { custom_type(int) {} };\n" "void func(int) {}\n" "int var;\n" "void init() { func(var); }\n" - "UNKNOWN_MACRO_EXPANDING_TO_SIGNATURE { custom_type a(var); }"); + "UNKNOWN_MACRO_EXPANDING_TO_SIGNATURE { custom_type a(var); }\n"); } void testautovar13() { // Ticket #5537 @@ -473,7 +473,7 @@ class TestAutoVariables : public TestFixture { " ~FileManager() {\n" " delete &UniqueRealDirs;\n" " }\n" - "};"); + "};\n"); } void testautovar14() { // Ticket #4776 @@ -483,7 +483,7 @@ class TestAutoVariables : public TestFixture { " x = x >> 1;\n" " goto label;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -496,7 +496,7 @@ class TestAutoVariables : public TestFixture { " if (lumdiff > 5.0f)\n" " return &darkOutline;\n" " return 0;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); } @@ -504,7 +504,7 @@ class TestAutoVariables : public TestFixture { check("void f(const void* ptr, bool* result) {\n" " int dummy;\n" " *result = (&dummy < ptr);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -533,7 +533,7 @@ class TestAutoVariables : public TestFixture { "{\n" " int num=2;" " arr[0]=#\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:19]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } @@ -545,7 +545,7 @@ class TestAutoVariables : public TestFixture { "{\n" " int num=2;" " arr[0]=#\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:19]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } @@ -596,7 +596,7 @@ class TestAutoVariables : public TestFixture { "{\n" " XPoint DropPoint;\n" " ds->location_data = (XtPointer *)&DropPoint;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (error, inconclusive) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } @@ -604,7 +604,7 @@ class TestAutoVariables : public TestFixture { check("void remove_duplicate_matches (char **matches) {\n" " char dead_slot;\n" " matches[0] = (char *)&dead_slot;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:3]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); } @@ -613,7 +613,7 @@ class TestAutoVariables : public TestFixture { "{\n" " int num=2;" " return #" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:26] -> [test.cpp:3:9] -> [test.cpp:3:26]: (error) Returning pointer to local variable 'num' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); } @@ -625,7 +625,7 @@ class TestAutoVariables : public TestFixture { "{\n" " int num=2;" " return #" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:26] -> [test.cpp:6:9] -> [test.cpp:6:26]: (error) Returning pointer to local variable 'num' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); } @@ -635,7 +635,7 @@ class TestAutoVariables : public TestFixture { "{\n" " void *&value = tls[id];" " return &value;" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -644,7 +644,7 @@ class TestAutoVariables : public TestFixture { check("void foo() {\n" " int cond2;\n" " dostuff([&cond2]() { return &cond2; });\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -681,7 +681,7 @@ class TestAutoVariables : public TestFixture { "{\n" " extern struct foo f;\n" " return &f;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -691,7 +691,7 @@ class TestAutoVariables : public TestFixture { " pcb->root0 = &root0;\n" " dostuff(pcb);\n" " pcb->root0 = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(cb* pcb) {\n" @@ -700,7 +700,7 @@ class TestAutoVariables : public TestFixture { " dostuff(pcb);\n" " if (condition) return;\n" // <- not reassigned => error " pcb->root0 = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:3]: (error, inconclusive) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("void foo(cb* pcb) {\n" @@ -709,7 +709,7 @@ class TestAutoVariables : public TestFixture { " dostuff(pcb);\n" " if (condition)\n" " pcb->root0 = 0;\n" // <- conditional reassign => error - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:3]: (error, inconclusive) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); check("struct S { int *p; };\n" @@ -721,7 +721,7 @@ class TestAutoVariables : public TestFixture { "void f() {\n" " struct S s;\n" " g(&s);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:5]: (error) Address of local auto-variable assigned to a function parameter. [autoVariables]\n", errout_str()); @@ -739,7 +739,7 @@ class TestAutoVariables : public TestFixture { " delete[] (tmp4);\n" " char tmp5[256];\n" " delete[] tmp5;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n" "[test.cpp:5:12]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n" "[test.cpp:7:12]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n" @@ -748,28 +748,28 @@ class TestAutoVariables : public TestFixture { check("void func1(char * ptr) {\n" " free(ptr);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void func1() {\n" " char* tmp1[256];\n" " init(tmp1);\n" " delete tmp1[34];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void func1() {\n" " static char tmp1[256];\n" " char *p = tmp1;\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: (error) Deallocation of a static variable (tmp1) results in undefined behaviour. [autovarInvalidDeallocation]\n", errout_str()); check("char tmp1[256];\n" "void func1() {\n" " char *p; if (x) p = tmp1;\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: (error) Deallocation of a global variable (tmp1) results in undefined behaviour. [autovarInvalidDeallocation]\n", errout_str()); check("void f()\n" @@ -780,7 +780,7 @@ class TestAutoVariables : public TestFixture { " abc(0, psz_title);\n" " free(psz_title);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #2298 new check: passing stack-address to free() @@ -788,44 +788,44 @@ class TestAutoVariables : public TestFixture { " int *p = malloc(4);\n" " free(&p);\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n", errout_str()); check("int main() {\n" " int i;\n" " free(&i);\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n", errout_str()); // #5732 check("int main() {\n" " long (*pKoeff)[256] = new long[9][256];\n" " delete[] pKoeff;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int main() {\n" " long *pKoeff[256];\n" " delete[] pKoeff;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:13]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n", errout_str()); check("int main() {\n" " long *pKoeff[256];\n" " free (pKoeff);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10]: (error) Deallocation of an auto-variable results in undefined behaviour. [autovarInvalidDeallocation]\n", errout_str()); check("void foo() {\n" " const intPtr& intref = Getter();\n" " delete intref;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void test() {\n" " MyObj& obj = *new MyObj;\n" " delete &obj;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #6506 @@ -837,7 +837,7 @@ class TestAutoVariables : public TestFixture { " F().free(c1);\n" " char *c2 = 0;\n" " F().free(&c2);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class foo {\n" @@ -846,14 +846,14 @@ class TestAutoVariables : public TestFixture { " char **dst_copy = NULL;\n" " free(&dst_copy);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // #6551 check("bool foo( ) {\n" " SwTxtFld * pTxtFld = GetFldTxtAttrAt();\n" " delete static_cast(&pTxtFld->GetAttr());\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #8910 @@ -863,14 +863,14 @@ class TestAutoVariables : public TestFixture { " if (data_size > sizeof (stack)) data = malloc (data_size);\n" " else data = (RGNDATA *)stack;\n" " if ((char *)data != stack) free (data);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #8923 check("void f(char **args1, char *args2[]) {\n" " free((char **)args1);\n" " free((char **)args2);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #10097 @@ -985,7 +985,7 @@ class TestAutoVariables : public TestFixture { check("void f(EventPtr *eventP, ActionPtr **actionsP) {\n" " EventPtr event = *eventP;\n" " *actionsP = &event->actions;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -993,7 +993,7 @@ class TestAutoVariables : public TestFixture { check("static void function(unsigned long **datap) {\n" " struct my_s *mr = global_structure_pointer;\n" " *datap = &mr->value;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1002,7 +1002,7 @@ class TestAutoVariables : public TestFixture { "void f() {\n" " int x[10];\n" " p = x;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7] -> [test.cpp:3:7] -> [test.cpp:4:3]: (error) Non-local variable 'p' will use pointer to local variable 'x'. [danglingLifetime]\n", errout_str()); check("int *p;\n" @@ -1010,7 +1010,7 @@ class TestAutoVariables : public TestFixture { " int x[10];\n" " p = x;\n" " p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1019,7 +1019,7 @@ class TestAutoVariables : public TestFixture { "void f() {\n" " int x;\n" " p = &x;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7] -> [test.cpp:3:7] -> [test.cpp:4:3]: (error) Non-local variable 'p' will use pointer to local variable 'x'. [danglingLifetime]\n", errout_str()); check("int *p;\n" @@ -1027,7 +1027,7 @@ class TestAutoVariables : public TestFixture { " int x;\n" " p = &x;\n" " p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1038,7 +1038,7 @@ class TestAutoVariables : public TestFixture { " ptr = &x;\n" " }\n" " int *ptr;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:11] -> [test.cpp:3:9] -> [test.cpp:4:5]: (error) Non-local variable 'ptr' will use pointer to local variable 'x'. [danglingLifetime]\n", errout_str()); check("struct A {\n" @@ -1048,7 +1048,7 @@ class TestAutoVariables : public TestFixture { " ptr = 0;\n" " }\n" " int *ptr;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct R {\n" // #11393 @@ -1072,7 +1072,7 @@ class TestAutoVariables : public TestFixture { "{\n" " char str[100] = {0};\n" " return str;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:12] -> [test.cpp:3:10] -> [test.cpp:4:12]: (error) Returning pointer to local variable 'str' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -1082,7 +1082,7 @@ class TestAutoVariables : public TestFixture { " char str[100] = {0};\n" " char *p = str;\n" " return p;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:15] -> [test.cpp:3:10] -> [test.cpp:5:12]: (error) Returning pointer to local variable 'str' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -1094,7 +1094,7 @@ class TestAutoVariables : public TestFixture { "{\n" " char str[100] = {0};\n" " return str;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:7:12] -> [test.cpp:6:10] -> [test.cpp:7:12]: (error) Returning pointer to local variable 'str' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -1106,7 +1106,7 @@ class TestAutoVariables : public TestFixture { " char temp[42];\n" " char *tp = temp;\n" " tp = format_reg(tp);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1115,7 +1115,7 @@ class TestAutoVariables : public TestFixture { "{\n" " char str[100] = {0};\n" " return str;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class Fred {\n" @@ -1125,7 +1125,7 @@ class TestAutoVariables : public TestFixture { "{\n" " char str[100] = {0};\n" " return str;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1135,14 +1135,14 @@ class TestAutoVariables : public TestFixture { check("char *foo() {\n" " char q[] = \"AAAAAAAAAAAA\";\n" " return &q[1];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:12] -> [test.cpp:2:10] -> [test.cpp:3:12]: (error) Returning pointer to local variable 'q' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("char *foo()\n" "{\n" " static char q[] = \"AAAAAAAAAAAA\";\n" " return &q[1];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("char *foo()\n" @@ -1151,7 +1151,7 @@ class TestAutoVariables : public TestFixture { "char *p;\n" "p = &q[1];\n" "return p;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5] -> [test.cpp:3:6] -> [test.cpp:6:8]: (error) Returning pointer to local variable 'q' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); } @@ -1159,7 +1159,7 @@ class TestAutoVariables : public TestFixture { check("char *foo() {\n" " char x[10] = {0};\n" " return x+5;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:12] -> [test.cpp:2:10] -> [test.cpp:3:13]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -1167,7 +1167,7 @@ class TestAutoVariables : public TestFixture { check("char *foo(int y) {\n" " char x[10] = {0};\n" " return (x+8)-y;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:13] -> [test.cpp:2:10] -> [test.cpp:3:17]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -1177,7 +1177,7 @@ class TestAutoVariables : public TestFixture { check("char *foo() {\n" " int x[10] = {0};\n" " return (char *)x;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:20] -> [test.cpp:2:9] -> [test.cpp:3:12]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -1188,7 +1188,7 @@ class TestAutoVariables : public TestFixture { " int x = 123;\n" " int p = &x;\n" " return p;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:13] -> [test.cpp:2:9] -> [test.cpp:4:12]: (error) Returning object that points to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); } @@ -1198,35 +1198,35 @@ class TestAutoVariables : public TestFixture { " int s = 0;\n" " int& x = s;\n" " return x;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:12] -> [test.cpp:5:12]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("std::string &foo()\n" "{\n" " std::string s;\n" " return s;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:12]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("std::vector &foo()\n" "{\n" " std::vector v;\n" " return v;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:12]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("std::vector &foo()\n" "{\n" " static std::vector v;\n" " return v;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::vector &foo()\n" "{\n" " thread_local std::vector v;\n" " return v;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::string hello()\n" @@ -1237,7 +1237,7 @@ class TestAutoVariables : public TestFixture { "std::string &f()\n" "{\n" " return hello();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:17]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); // make sure scope is used in function lookup @@ -1248,7 +1248,7 @@ class TestAutoVariables : public TestFixture { "};\n" "std::string &f() {\n" " return hello();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::string hello() {\n" @@ -1257,7 +1257,7 @@ class TestAutoVariables : public TestFixture { "\n" "std::string &f() {\n" " return hello();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:17]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("std::string hello() {\n" @@ -1266,7 +1266,7 @@ class TestAutoVariables : public TestFixture { "\n" "std::string &f() {\n" " return hello().substr(1);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:26]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("class Foo;\n" @@ -1276,7 +1276,7 @@ class TestAutoVariables : public TestFixture { "\n" "Foo& f() {\n" " return hello();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:17]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); // make sure function overloads are handled properly @@ -1291,7 +1291,7 @@ class TestAutoVariables : public TestFixture { "\n" "Foo& f() {\n" " return hello(true);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("Foo hello() {\n" @@ -1300,7 +1300,7 @@ class TestAutoVariables : public TestFixture { "\n" "Foo& f() {\n" // Unknown type - might be a reference " return hello();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1312,7 +1312,7 @@ class TestAutoVariables : public TestFixture { "{\n" " std::string s;\n" " return s;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:12]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("class Fred {\n" @@ -1322,7 +1322,7 @@ class TestAutoVariables : public TestFixture { "{\n" " std::vector v;\n" " return v;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:12]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("class Fred {\n" @@ -1332,7 +1332,7 @@ class TestAutoVariables : public TestFixture { "{\n" " static std::vector v;\n" " return v;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class Fred {\n" @@ -1345,7 +1345,7 @@ class TestAutoVariables : public TestFixture { "std::string &Fred::f()\n" "{\n" " return hello();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:17]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("class Fred {\n" @@ -1359,7 +1359,7 @@ class TestAutoVariables : public TestFixture { "std::string &Fred::f()\n" "{\n" " return hello();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:11:17]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("class Bar;\n" @@ -1368,7 +1368,7 @@ class TestAutoVariables : public TestFixture { "}\n" "Bar& bar() {\n" " return foo();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:15]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("std::map foo() {\n" @@ -1376,7 +1376,7 @@ class TestAutoVariables : public TestFixture { "}\n" "std::map& bar() {\n" " return foo();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:15]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("Bar foo() {\n" @@ -1384,13 +1384,13 @@ class TestAutoVariables : public TestFixture { "}\n" "Bar& bar() {\n" // Unknown type - might be a typedef to a reference type " return foo();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Don't crash with function in unknown scope (#4076) - check("X& a::Bar() {}" + check("X& a::Bar() {}\n" "X& foo() {" " return Bar();" - "}"); + "}\n"); } void returnReference3() { @@ -1398,7 +1398,7 @@ class TestAutoVariables : public TestFixture { " double ret = getValue();\n" " rd = ret;\n" " return rd;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); } @@ -1407,7 +1407,7 @@ class TestAutoVariables : public TestFixture { check("double a;\n" "double & f() {\n" " return a;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1427,7 +1427,7 @@ class TestAutoVariables : public TestFixture { " const A &ra = pb->a;\n" " return ra;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1435,7 +1435,7 @@ class TestAutoVariables : public TestFixture { check("Fred & create() {\n" " Fred &fred(*new Fred);\n" " return fred;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1444,14 +1444,14 @@ class TestAutoVariables : public TestFixture { "std::string &a(int);\n" "std::string &b() {\n" " return a(12);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::string &a(int);\n" "std::string a();\n" "std::string &b() {\n" " return a(12);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1460,14 +1460,14 @@ class TestAutoVariables : public TestFixture { " std::vector::iterator it = v.begin();\n" " int& value = *it;\n" " return value;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void returnReference9() { check("int& f(bool b, int& x, int& y) {\n" " return b ? x : y;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1476,14 +1476,14 @@ class TestAutoVariables : public TestFixture { "int& g() {\n" " A a;\n" " return a.f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:15]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("class A { int& f() const; };\n" "int& g() {\n" " A a;\n" " return a.f();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1491,19 +1491,19 @@ class TestAutoVariables : public TestFixture { check("class A { static int f(); };\n" "int& g() {\n" " return A::f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:16]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("class A { static int& f(); };\n" "int& g() {\n" " return A::f();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("namespace A { int& f(); }\n" "int& g() {\n" " return A::f();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1511,14 +1511,14 @@ class TestAutoVariables : public TestFixture { check("class A { static int& f(); };\n" "auto g() {\n" " return &A::f;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class A { static int& f(); };\n" "auto g() {\n" " auto x = &A::f;\n" " return x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1527,14 +1527,14 @@ class TestAutoVariables : public TestFixture { "void* vp = &v;\n" "int& foo(size_t i) {\n" " return ((std::vector*)vp)->at(i);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::vector v;\n" "void* vp = &v;\n" "int& foo(size_t i) {\n" " return static_cast*>(vp)->at(i);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1547,7 +1547,7 @@ class TestAutoVariables : public TestFixture { "}\n" "void* &A::f() {\n" " return g()->m;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1560,7 +1560,7 @@ class TestAutoVariables : public TestFixture { "template \n" "const int& f(const T&) {\n" " return f();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("template \n" @@ -1568,19 +1568,19 @@ class TestAutoVariables : public TestFixture { "template \n" "const int& f(const T&) {\n" " return g();\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("error", "", errout_str()); } void returnReference16() { check("int& f(std::tuple& x) {\n" " return std::get<0>(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int& f(int x) {\n" " return std::get<0>(std::make_tuple(x));\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("error", "", errout_str()); } @@ -1588,7 +1588,7 @@ class TestAutoVariables : public TestFixture { check("auto g() -> int&;\n" "int& f() {\n" " return g();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1597,7 +1597,7 @@ class TestAutoVariables : public TestFixture { "auto f(T& x) -> decltype(x);\n" "int& g(int* x) {\n" " return f(*x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1605,7 +1605,7 @@ class TestAutoVariables : public TestFixture { void returnReference19() { check("struct C : B {\n" " const B &f() const { return (const B &)*this; }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1616,7 +1616,7 @@ class TestAutoVariables : public TestFixture { "};\n" "int& b() {\n" " return a()();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("auto a() {\n" @@ -1627,13 +1627,13 @@ class TestAutoVariables : public TestFixture { "}\n" "const int& c() {\n" " return a()();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::function a();\n" "int& b() {\n" " return a()();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9889 @@ -1779,7 +1779,7 @@ class TestAutoVariables : public TestFixture { "int& hello() {\n" " int x = 0;\n" " return f(x);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:6:12] -> [test.cpp:6:13]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); @@ -1790,7 +1790,7 @@ class TestAutoVariables : public TestFixture { "int* hello() {\n" " int x = 0;\n" " return &f(x);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:6:13] -> [test.cpp:6:12] -> [test.cpp:5:9] -> [test.cpp:6:12]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -1800,7 +1800,7 @@ class TestAutoVariables : public TestFixture { "}\n" "int * g(int x) {\n" " return f(&x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:14] -> [test.cpp:5:14] -> [test.cpp:4:13] -> [test.cpp:5:13]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("int* f(int * x) {\n" @@ -1809,7 +1809,7 @@ class TestAutoVariables : public TestFixture { "}\n" "int * g(int x) {\n" " return f(&x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(int& a) {\n" @@ -1818,7 +1818,7 @@ class TestAutoVariables : public TestFixture { "int& hello() {\n" " int x = 0;\n" " return f(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:13]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("int& f(int a) {\n" @@ -1827,7 +1827,7 @@ class TestAutoVariables : public TestFixture { "int& hello() {\n" " int x = 0;\n" " return f(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("int f(int a) {\n" @@ -1836,14 +1836,14 @@ class TestAutoVariables : public TestFixture { "int& hello() {\n" " int x = 0;\n" " return f(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:13]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("template\n" "int& f(int& x, T y) {\n" " x += y;\n" " return x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1851,31 +1851,31 @@ class TestAutoVariables : public TestFixture { check("auto& f() {\n" " std::vector x;\n" " return x[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:13]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("auto& f() {\n" " std::vector x;\n" " return x.front();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:14] -> [test.cpp:3:19]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("std::vector g();\n" "auto& f() {\n" " return g().front();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:16] -> [test.cpp:3:21]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("auto& f() {\n" " return std::vector{1}.front();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:32] -> [test.cpp:2:37]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("struct A { int foo; };\n" "int& f(std::vector v) {\n" " auto it = v.begin();\n" " return it->foo;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:22] -> [test.cpp:4:14]: (error) Reference to local variable returned. [returnReference]\n", errout_str()); check("template \n" @@ -1909,7 +1909,7 @@ class TestAutoVariables : public TestFixture { "int& f(std::vector& v) {\n" " auto it = v.begin();\n" " return it->foo;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("static std::vector A[2];\n" @@ -1923,18 +1923,18 @@ class TestAutoVariables : public TestFixture { void returnReferenceLiteral() { check("const std::string &a() {\n" " return \"foo\";\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("const std::string a() {\n" " return \"foo\";\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("const std::string& f(const std::string& x) { return x; }\n" "const std::string &a() {\n" " return f(\"foo\");\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:1:42] -> [test.cpp:1:53] -> [test.cpp:3:12] -> [test.cpp:3:13]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); @@ -1942,59 +1942,59 @@ class TestAutoVariables : public TestFixture { check("const char * f(const char * x) { return x; }\n" "const std::string &a() {\n" " return f(\"foo\");\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:13]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); } void returnReferenceCalculation() { check("const std::string &a(const std::string& str) {\n" " return \"foo\" + str;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:18]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("int& operator<<(int out, int path) {\n" " return out << path;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("std::ostream& operator<<(std::ostream& out, const std::string& path) {\n" " return out << path;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::ostream& operator<<(std::ostream* out, const std::string& path) {\n" " return *out << path;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("Unknown1& operator<<(Unknown1 out, Unknown2 path) {\n" " return out << path;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int& a(int b) {\n" " return 2*(b+1);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("const std::string &a(const std::string& str) {\n" " return str;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("const std::string &a(int bar) {\n" " return foo(bar + 1);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("const std::string a(const std::string& str) {\n" " return \"foo\" + str;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int& incValue(int& value) {\n" " return ++value;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2005,7 +2005,7 @@ class TestAutoVariables : public TestFixture { " [](const Item& lhs, const Item& rhs) {\n" " return false;\n" " });\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #5844 @@ -2015,13 +2015,13 @@ class TestAutoVariables : public TestFixture { " return var;\n" " }();\n" "return s_var;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #7583 check("Command& foo() {\n" " return f([]() -> int { return 1; });\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2034,16 +2034,16 @@ class TestAutoVariables : public TestFixture { " }\n" " };\n" " return _make(_Wrapper::call, pmf);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void returnReferenceRecursive() { - check("int& f() { return f(); }"); + check("int& f() { return f(); }\n"); ASSERT_EQUALS("", errout_str()); check("int& g(int& i) { return i; }\n" - "int& f() { return g(f()); }"); + "int& f() { return g(f()); }\n"); ASSERT_EQUALS("", errout_str()); } @@ -2053,7 +2053,7 @@ class TestAutoVariables : public TestFixture { "auto f() {\n" " const int& x = h();\n" " return [&] { return x; };\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:18] -> [test.cpp:5:25] -> [test.cpp:4:16] -> [test.cpp:5:12]: (error) Returning lambda that captures local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("void g(int*);\n" @@ -2061,7 +2061,7 @@ class TestAutoVariables : public TestFixture { "int* f() {\n" " const int& x = h();\n" " return &x;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:18] -> [test.cpp:5:12] -> [test.cpp:4:16] -> [test.cpp:5:12]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("void g(int*);\n" @@ -2069,7 +2069,7 @@ class TestAutoVariables : public TestFixture { "void f() {\n" " int& x = h();\n" " g(&x);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:12] -> [test.cpp:5:7] -> [test.cpp:4:15] -> [test.cpp:5:7]: (error) Using pointer that is a temporary. [danglingTemporaryLifetime]\n" "[test.cpp:4:12] -> [test.cpp:5:8]: (error) Using reference to dangling temporary. [danglingTempReference]\n", @@ -2080,7 +2080,7 @@ class TestAutoVariables : public TestFixture { "void f() {\n" " const int& x = h();\n" " g(&x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct Data {\n" @@ -2089,7 +2089,7 @@ class TestAutoVariables : public TestFixture { "const char* foo() {\n" " const Data& data = getData();\n" " return data.path.c_str();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2098,7 +2098,7 @@ class TestAutoVariables : public TestFixture { "{\n" " static int &r = k;\n" " return r;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:19] -> [test.cpp:3:17]: (error) Non-local reference variable 'r' to local variable 'k' [danglingReference]\n", errout_str()); @@ -2106,7 +2106,7 @@ class TestAutoVariables : public TestFixture { "{\n" " static int &r = k;\n" " return r;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2274,7 +2274,7 @@ class TestAutoVariables : public TestFixture { " {\n" " pNum = apNum;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2283,28 +2283,28 @@ class TestAutoVariables : public TestFixture { check("int* foo(int y)\n" "{\n" " return &y;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:1:14] -> [test.cpp:3:10]: (error) Returning pointer to local variable 'y' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("int ** foo(int * y)\n" "{\n" " return &y;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:1:18] -> [test.cpp:3:10]: (error) Returning pointer to local variable 'y' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("const int * foo(const int & y)\n" "{\n" " return &y;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int * foo(int * y)\n" "{\n" " return y;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); @@ -2314,7 +2314,7 @@ class TestAutoVariables : public TestFixture { "{\n" " struct s *r = f();\n" " *q = &r->p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2325,7 +2325,7 @@ class TestAutoVariables : public TestFixture { " const_tree_iterator& parent() {\n" " return const_tree_iterator(foo);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:31]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); } @@ -2336,7 +2336,7 @@ class TestAutoVariables : public TestFixture { "}\n" "void opened_cb () {\n" " g_signal_connect (G_CALLBACK (removed_cb));\n" - "}"); + "}\n"); } void danglingLifetimeLambda() { @@ -2344,30 +2344,30 @@ class TestAutoVariables : public TestFixture { " int a = 1;\n" " auto l = [&](){ return a; };\n" " return l;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:28] -> [test.cpp:2:9] -> [test.cpp:4:12]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f() {\n" " int a = 1;\n" " return [&](){ return a; };\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:26] -> [test.cpp:2:9] -> [test.cpp:3:12]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f(int a) {\n" " return [&](){ return a; };\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:26] -> [test.cpp:1:12] -> [test.cpp:2:12]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f(int a) {\n" " auto p = &a;\n" " return [=](){ return p; };\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14] -> [test.cpp:3:26] -> [test.cpp:1:12] -> [test.cpp:3:12]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto g(int& a) {\n" " int p = a;\n" " return [&](){ return p; };\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:26] -> [test.cpp:2:9] -> [test.cpp:3:12]: (error) Returning lambda that captures local variable 'p' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f() {\n" @@ -2375,7 +2375,7 @@ class TestAutoVariables : public TestFixture { " int a = 1;\n" " return [&](){ return a; };\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:30] -> [test.cpp:3:13] -> [test.cpp:4:16]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f(int b) {\n" @@ -2383,30 +2383,30 @@ class TestAutoVariables : public TestFixture { " a += b;\n" " return [&](){ return a; };\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:30] -> [test.cpp:2:20] -> [test.cpp:4:16]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto g(int& a) {\n" " return [&](){ return a; };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("auto g(int a) {\n" " auto p = a;\n" " return [=](){ return p; };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("auto g(int& a) {\n" " auto p = a;\n" " return [=](){ return p; };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("auto g(int& a) {\n" " int& p = a;\n" " return [&](){ return p; };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("template\n" @@ -2414,7 +2414,7 @@ class TestAutoVariables : public TestFixture { "auto f() {\n" " int x;\n" " return g([&]() { return x; });\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("auto f() {\n" @@ -2487,28 +2487,28 @@ class TestAutoVariables : public TestFixture { check("auto f(const std::vector& x) {\n" " auto it = x.begin();\n" " return it;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::vector::iterator f() {\n" " std::vector x;\n" " auto it = x.begin();\n" " return it;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:22] -> [test.cpp:2:22] -> [test.cpp:4:12]: (error) Returning iterator to local container 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f() {\n" " std::vector x;\n" " auto it = std::begin(x);\n" " return it;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:25] -> [test.cpp:2:22] -> [test.cpp:4:12]: (error) Returning iterator to local container 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("int* f() {\n" " std::vector x;\n" " auto p = x.data();\n" " return p;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:20] -> [test.cpp:2:22] -> [test.cpp:4:12]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -2517,7 +2517,7 @@ class TestAutoVariables : public TestFixture { " std::vector x;\n" " auto p = &x[0];\n" " return p;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:14] -> [test.cpp:2:22] -> [test.cpp:4:12]: (error) Returning pointer to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -2526,7 +2526,7 @@ class TestAutoVariables : public TestFixture { "int* f(std::vector v) {\n" " auto it = v.begin();\n" " return &it->foo;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:22] -> [test.cpp:4:12] -> [test.cpp:2:23] -> [test.cpp:4:12]: (error) Returning pointer to local variable 'v' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -2534,14 +2534,14 @@ class TestAutoVariables : public TestFixture { check("std::vector::iterator f(std::vector x) {\n" " auto it = x.begin();\n" " return it;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:22] -> [test.cpp:1:47] -> [test.cpp:3:12]: (error) Returning iterator to local container 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f() {\n" " std::vector x;\n" " auto it = x.begin();\n" " return std::next(it);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:22] -> [test.cpp:2:22] -> [test.cpp:4:21]: (error) Returning iterator to local container 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -2550,7 +2550,7 @@ class TestAutoVariables : public TestFixture { " std::vector x;\n" " auto it = x.begin();\n" " return it + 1;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:22] -> [test.cpp:2:22] -> [test.cpp:4:15]: (error) Returning iterator to local container 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -2559,7 +2559,7 @@ class TestAutoVariables : public TestFixture { " std::vector x;\n" " auto it = x.begin();\n" " return std::next(it + 1);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:22] -> [test.cpp:4:25] -> [test.cpp:2:22] -> [test.cpp:4:21]: (error) Returning object that points to local variable 'x' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -2569,7 +2569,7 @@ class TestAutoVariables : public TestFixture { " std::vector v;\n" " v.push_back(&i);\n" " return v;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:17] -> [test.cpp:4:17] -> [test.cpp:2:9] -> [test.cpp:5:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -2581,7 +2581,7 @@ class TestAutoVariables : public TestFixture { " v.push_back(&i);\n" " r.assign(v.begin(), v.end());\n" " return r;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:5:17] -> [test.cpp:5:17] -> [test.cpp:5:5] -> [test.cpp:3:9] -> [test.cpp:7:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -2592,7 +2592,7 @@ class TestAutoVariables : public TestFixture { " int i;\n" " v.push_back(&i);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS( "[test.cpp:5:21] -> [test.cpp:5:21] -> [test.cpp:4:13] -> [test.cpp:5:9]: (error) Non-local variable 'v' will use object that points to local variable 'i'. [danglingLifetime]\n", errout_str()); @@ -2604,7 +2604,7 @@ class TestAutoVariables : public TestFixture { " int * p = &i;\n" " v.push_back(p);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS( "[test.cpp:5:19] -> [test.cpp:6:21] -> [test.cpp:4:13] -> [test.cpp:6:9]: (error) Non-local variable 'v' will use object that points to local variable 'i'. [danglingLifetime]\n", errout_str()); @@ -2617,7 +2617,7 @@ class TestAutoVariables : public TestFixture { " v.push_back(&x);\n" " m.insert(m.end(), v.begin(), v.end());\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS( "[test.cpp:6:21] -> [test.cpp:6:21] -> [test.cpp:6:9] -> [test.cpp:4:13] -> [test.cpp:7:9]: (error) Non-local variable 'm' will use object that points to local variable 'x'. [danglingLifetime]\n" "[test.cpp:6:21] -> [test.cpp:6:21] -> [test.cpp:6:9] -> [test.cpp:4:13] -> [test.cpp:7:18]: (error) Non-local variable 'm' will use object that points to local variable 'x'. [danglingLifetime]\n", // duplicate @@ -2628,7 +2628,7 @@ class TestAutoVariables : public TestFixture { " return it;\n" " }\n" " return {};\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:26] -> [test.cpp:1:47] -> [test.cpp:3:16]: (error) Returning iterator to local container 'v' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -2636,7 +2636,7 @@ class TestAutoVariables : public TestFixture { check("const char * f() {\n" " std::string ba(\"hello\");\n" " return ba.c_str();\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:19] -> [test.cpp:2:16] -> [test.cpp:3:19]: (error) Returning pointer to local variable 'ba' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -2658,7 +2658,7 @@ class TestAutoVariables : public TestFixture { check("std::vector g();\n" "auto f() {\n" " return g().begin();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:21] -> [test.cpp:3:21]: (error) Returning iterator that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -2666,14 +2666,14 @@ class TestAutoVariables : public TestFixture { "std::vector::iterator f() {\n" " auto it = g().begin();\n" " return it;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:24] -> [test.cpp:3:16] -> [test.cpp:4:5]: (error) Using iterator that is a temporary. [danglingTemporaryLifetime]\n", errout_str()); check("std::vector g();\n" "int& f() {\n" " return *g().begin();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:22] -> [test.cpp:3:12]: (error) Reference to temporary returned. [returnTempReference]\n", errout_str()); check("struct A {\n" @@ -2682,7 +2682,7 @@ class TestAutoVariables : public TestFixture { " char s[3];\n" " v.push_back(s);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("std::vector f() {\n" @@ -2690,46 +2690,46 @@ class TestAutoVariables : public TestFixture { " std::vector v;\n" " v.push_back(s);\n" " return v;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("auto f() {\n" " static std::vector x;\n" " return x.begin();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::string g() {\n" " std::vector v;\n" " return v.data();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::vector::iterator f(std::vector* v) {\n" " return v->begin();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::vector::iterator f(std::vector* v) {\n" " std::vector* v = new std::vector();\n" " return v->begin();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(std::vector v) {\n" " return *v.begin();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(std::vector v) {\n" " return v.end() - v.begin();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("auto g() {\n" " std::vector v;\n" " return {v, [v]() { return v.data(); }};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("template\n" @@ -2737,7 +2737,7 @@ class TestAutoVariables : public TestFixture { "auto f() {\n" " std::vector v;\n" " return g([&]() { return v.data(); });\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::vector g();\n" @@ -2747,7 +2747,7 @@ class TestAutoVariables : public TestFixture { " std::vector v = g();\n" " m.insert(m.end(), v.begin(), v.end());\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool b) {\n" @@ -2757,7 +2757,7 @@ class TestAutoVariables : public TestFixture { " v.insert(a, a+1);\n" " }\n" " return v.back() == 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class A {\n" @@ -2768,7 +2768,7 @@ class TestAutoVariables : public TestFixture { " struct B {};\n" " std::map< S, B > m1;\n" " std::map< S, B > m2;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" @@ -2777,33 +2777,33 @@ class TestAutoVariables : public TestFixture { " void f() {\n" " v.push_back(&x);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("size_t f(const std::string& x) {\n" " std::string y = \"x\";\n" " return y.find(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::string* f();\n" "const char* g() {\n" " std::string* var = f();\n" " return var->c_str();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::string f() {\n" " std::vector data{};\n" " data.push_back('a');\n" " return std::string{ data.data(), data.size() };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::vector f() {\n" " char a = 0;\n" " return std::vector{&a};\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:31] -> [test.cpp:3:31] -> [test.cpp:2:10] -> [test.cpp:3:30]: (error) Returning object that points to local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("std::vector* g();\n" @@ -3246,20 +3246,20 @@ class TestAutoVariables : public TestFixture { " std::vector a;\n" " auto it = a.begin();\n" " return [=](){ return it; };\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:22] -> [test.cpp:4:26] -> [test.cpp:2:22] -> [test.cpp:4:12]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("auto f(std::vector a) {\n" " auto it = a.begin();\n" " return [=](){ return it; };\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:22] -> [test.cpp:3:26] -> [test.cpp:1:25] -> [test.cpp:3:12]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); check("struct e {};\n" "e * j() {\n" " e c[20];\n" " return c;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:12] -> [test.cpp:3:7] -> [test.cpp:4:12]: (error) Returning pointer to local variable 'c' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -3267,12 +3267,12 @@ class TestAutoVariables : public TestFixture { check("auto f(std::vector& a) {\n" " auto it = a.begin();\n" " return [=](){ return it; };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int * f(int a[]) {\n" " return a;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -3280,14 +3280,14 @@ class TestAutoVariables : public TestFixture { " uint32_t f[6];\n" " } d;\n" " uint32_t *a = d.f;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Don't decay std::array check("std::array f() {\n" " std::array x;\n" " return x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Make sure we don't hang @@ -3295,7 +3295,7 @@ class TestAutoVariables : public TestFixture { "void f() {\n" " using T = A[3];\n" " A &&a = T{1, 2, 3}[1];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Make sure we don't hang @@ -3303,7 +3303,7 @@ class TestAutoVariables : public TestFixture { "void f() {\n" " using T = A[3];\n" " A &&a = T{1, 2, 3}[1]();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Make sure we don't hang @@ -3311,7 +3311,7 @@ class TestAutoVariables : public TestFixture { "void f() {\n" " using T = A[3];\n" " A &&a = T{1, 2, 3}[1];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Make sure we don't hang @@ -3319,7 +3319,7 @@ class TestAutoVariables : public TestFixture { "void f() {\n" " using T = A[3];\n" " A &&a = T{1, 2, 3}[1]();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Crash #8872 @@ -3327,14 +3327,14 @@ class TestAutoVariables : public TestFixture { " void operator()(b c) override {\n" " d(c, [&] { c->e });\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct a {\n" " void operator()(b c) override {\n" " d(c, [=] { c->e });\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct a {\n" @@ -3343,7 +3343,7 @@ class TestAutoVariables : public TestFixture { "a f() {\n" " char c[20];\n" " return c;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct a {\n" @@ -3353,7 +3353,7 @@ class TestAutoVariables : public TestFixture { " char c[20];\n" " a d = c;\n" " return d;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -3361,14 +3361,14 @@ class TestAutoVariables : public TestFixture { " std::vector v;\n" " auto g() { return v.end(); }\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int * f(std::vector& v) {\n" " for(int & x : v)\n" " return &x;\n" " return nullptr;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9275 @@ -3380,7 +3380,7 @@ class TestAutoVariables : public TestFixture { " char buf[1024];\n" " const char* msg = buf;\n" " m = msg;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9201 @@ -3388,14 +3388,14 @@ class TestAutoVariables : public TestFixture { " struct a { int m; };\n" " static a b{0};\n" " return &b.m;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9453 check("int *ptr;\n" "void foo(int arr[]) {\n" " ptr = &arr[2];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9639 @@ -3406,7 +3406,7 @@ class TestAutoVariables : public TestFixture { "const char * f() {\n" " const Fred &fred = getFred();\n" " return fred.s.c_str();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9534 @@ -3416,14 +3416,14 @@ class TestAutoVariables : public TestFixture { "int* f(int i, std::vector& v) {\n" " A& y = v[i];\n" " return &y.x[i];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9712 check("std::string f(const char *str) {\n" " char value[256];\n" " return value;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9770 @@ -3597,7 +3597,7 @@ class TestAutoVariables : public TestFixture { check("auto f() {\n" " int a;\n" " return std::ref(a);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:21] -> [test.cpp:2:9] -> [test.cpp:3:20]: (error) Returning object that points to local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -3605,7 +3605,7 @@ class TestAutoVariables : public TestFixture { check("auto f() {\n" " int a;\n" " return std::make_tuple(std::ref(a));\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:37] -> [test.cpp:3:36] -> [test.cpp:2:9] -> [test.cpp:3:27]: (error) Returning object that points to local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -3617,7 +3617,7 @@ class TestAutoVariables : public TestFixture { "auto g() {\n" " std::vector v;\n" " return by_value(v.begin());\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:7:28] -> [test.cpp:7:28] -> [test.cpp:3:12] -> [test.cpp:3:25] -> [test.cpp:6:22] -> [test.cpp:7:20]: (error) Returning object that points to local variable 'v' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -3640,7 +3640,7 @@ class TestAutoVariables : public TestFixture { "auto f() {\n" " int i = 0;\n" " return by_ref(i);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:12] -> [test.cpp:1:19] -> [test.cpp:2:25] -> [test.cpp:6:19] -> [test.cpp:5:9] -> [test.cpp:6:18]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -3658,7 +3658,7 @@ class TestAutoVariables : public TestFixture { " int a;\n" " std::tie(a) = x;\n" " return a;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::pair\n" @@ -3907,7 +3907,7 @@ class TestAutoVariables : public TestFixture { "A f() {\n" " int i = 0;\n" " return A{i, i};\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:7:14] -> [test.cpp:6:9] -> [test.cpp:7:13]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -3919,7 +3919,7 @@ class TestAutoVariables : public TestFixture { "A f() {\n" " int i = 0;\n" " return {i, i};\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:7:13] -> [test.cpp:6:9] -> [test.cpp:7:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -3932,7 +3932,7 @@ class TestAutoVariables : public TestFixture { " int i = 0;\n" " A r{i, i};\n" " return r;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:7:9] -> [test.cpp:6:9] -> [test.cpp:8:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -3945,7 +3945,7 @@ class TestAutoVariables : public TestFixture { " int i = 0;\n" " A r = {i, i};\n" " return r;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:7:12] -> [test.cpp:6:9] -> [test.cpp:8:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -3957,7 +3957,7 @@ class TestAutoVariables : public TestFixture { "A f(int& x) {\n" " int i = 0;\n" " return A{i, x};\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:7:14] -> [test.cpp:6:9] -> [test.cpp:7:13]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); @@ -3969,7 +3969,7 @@ class TestAutoVariables : public TestFixture { "A f(int& x) {\n" " int i = 0;\n" " return A{x, i};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" @@ -3978,14 +3978,14 @@ class TestAutoVariables : public TestFixture { "};\n" "A f(int& x) {\n" " return A{x, x};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { int i; const int& j; };\n" "A f(int& x) {\n" " int y = 0;\n" " return A{y, x};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct a {\n" @@ -4086,7 +4086,7 @@ class TestAutoVariables : public TestFixture { " int i = 0;\n" " std::vector v = {&i, &i};\n" " return v;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:28] -> [test.cpp:3:28] -> [test.cpp:2:9] -> [test.cpp:4:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n" "[test.cpp:3:32] -> [test.cpp:3:32] -> [test.cpp:2:9] -> [test.cpp:4:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", @@ -4096,7 +4096,7 @@ class TestAutoVariables : public TestFixture { " int i = 0;\n" " std::vector v{&i, &i};\n" " return v;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:25] -> [test.cpp:3:25] -> [test.cpp:2:9] -> [test.cpp:4:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n" "[test.cpp:3:29] -> [test.cpp:3:29] -> [test.cpp:2:9] -> [test.cpp:4:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", @@ -4105,7 +4105,7 @@ class TestAutoVariables : public TestFixture { check("std::vector f() {\n" " int i = 0;\n" " return {&i, &i};\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:13] -> [test.cpp:3:13] -> [test.cpp:2:9] -> [test.cpp:3:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n" "[test.cpp:3:17] -> [test.cpp:3:17] -> [test.cpp:2:9] -> [test.cpp:3:12]: (error) Returning object that points to local variable 'i' that will be invalid when returning. [returnDanglingLifetime]\n", @@ -4113,7 +4113,7 @@ class TestAutoVariables : public TestFixture { check("std::vector f(int& x) {\n" " return {&x, &x};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::vector f() {\n" @@ -4121,7 +4121,7 @@ class TestAutoVariables : public TestFixture { " x.insert(\"1\");\n" " x.insert(\"2\");\n" " return { x.begin(), x.end() };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -4130,7 +4130,7 @@ class TestAutoVariables : public TestFixture { "A f() {\n" " std::string ba(\"hello\");\n" " return ba.c_str();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { A(const char *a); };\n" @@ -4138,7 +4138,7 @@ class TestAutoVariables : public TestFixture { " std::string ba(\"hello\");\n" " A bp = ba.c_str();\n" " return bp;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { A(const char *a); };\n" @@ -4147,7 +4147,7 @@ class TestAutoVariables : public TestFixture { " std::vector v;\n" " v.push_back(ba.c_str());\n" " return v;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::string f(const std::string& x) {\n" @@ -4155,7 +4155,7 @@ class TestAutoVariables : public TestFixture { " if (!x.empty())\n" " return x + c;\n" " return \"\";\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::string f(const std::string& x) {\n" @@ -4163,7 +4163,7 @@ class TestAutoVariables : public TestFixture { " if (!x.empty())\n" " return c + 1;\n" " return \"\";\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -4186,7 +4186,7 @@ class TestAutoVariables : public TestFixture { "void f(int& i) {\n" " int* x = &g(0);\n" " i += *x;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:1:26] -> [test.cpp:2:12] -> [test.cpp:5:15] -> [test.cpp:5:14] -> [test.cpp:5:17] -> [test.cpp:6:11]: (error) Using pointer that is a temporary. [danglingTemporaryLifetime]\n", errout_str()); @@ -4196,7 +4196,7 @@ class TestAutoVariables : public TestFixture { " const char* b = a.toStdString().c_str();\n" " QString c = b;\n" " return c;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:42] -> [test.cpp:3:34] -> [test.cpp:4:15]: (error) Using pointer that is a temporary. [danglingTemporaryLifetime]\n", errout_str()); @@ -4204,7 +4204,7 @@ class TestAutoVariables : public TestFixture { " const char *x = s.substr(1,2).c_str();\n" " auto i = s.substr(4,5).begin();\n" " return *i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:33] -> [test.cpp:3:22] -> [test.cpp:4:13]: (error) Using iterator that is a temporary. [danglingTemporaryLifetime]\n", errout_str()); @@ -4212,7 +4212,7 @@ class TestAutoVariables : public TestFixture { " std::stringstream tmp;\n" " const std::string &str = tmp.str();\n" " return std::string(str.c_str(), 1);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int get_value();\n" @@ -4682,7 +4682,7 @@ class TestAutoVariables : public TestFixture { " f = [&]{ return b; };\n" " }\n" " f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:25] -> [test.cpp:4:13] -> [test.cpp:7:5]: (error) Using lambda that captures local variable 'b' that is out of scope. [invalidLifetime]\n", errout_str()); check("void f(bool b) {\n" @@ -4692,7 +4692,7 @@ class TestAutoVariables : public TestFixture { " x = y;\n" " }\n" " x[3];\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:5:9] -> [test.cpp:4:9] -> [test.cpp:7:3]: (error) Using pointer to local variable 'y' that is out of scope. [invalidLifetime]\n", errout_str()); @@ -4704,7 +4704,7 @@ class TestAutoVariables : public TestFixture { " f = [&]{ return b; };\n" " f();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct a {\n" @@ -4713,7 +4713,7 @@ class TestAutoVariables : public TestFixture { "};\n" "void a::b() {\n" " c.end()\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void b(char f[], char c[]) {\n" @@ -4721,7 +4721,7 @@ class TestAutoVariables : public TestFixture { " std::string e;\n" " b(f, e.c_str())\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool b) {\n" @@ -4731,11 +4731,11 @@ class TestAutoVariables : public TestFixture { " s = buf;\n" " }\n" " std::cout << s;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int &a[];\n" - "void b(){int *c = a};"); + "void b(){int *c = a};\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" @@ -4749,7 +4749,7 @@ class TestAutoVariables : public TestFixture { " return y.x;\n" " };\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("namespace test {\n" @@ -4883,7 +4883,7 @@ class TestAutoVariables : public TestFixture { " p = &x;\n" " }\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9] -> [test.cpp:7:4]: (error) Using pointer to local variable 'x' that is out of scope. [invalidLifetime]\n", errout_str()); // FP: don't warn in subfunction @@ -4900,7 +4900,7 @@ class TestAutoVariables : public TestFixture { " } else {\n" " }\n" " f(tmp);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Don't warn about references (#6399) @@ -4912,7 +4912,7 @@ class TestAutoVariables : public TestFixture { " }\n" " if (former_hover != pitem)\n" " dosth();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -4923,7 +4923,7 @@ class TestAutoVariables : public TestFixture { " }\n" " if (former_hover != pitem)\n" " dosth();\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:5:24] -> [test.cpp:3:47] -> [test.cpp:4:26] -> [test.cpp:7:9]: (error) Using pointer to local variable 'item' that is out of scope. [invalidLifetime]\n", errout_str()); @@ -4936,7 +4936,7 @@ class TestAutoVariables : public TestFixture { " };\n" " EventReport * rep = &repData;\n" " rep->setEventType(NDB_LE_Connected);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #8785 @@ -4949,7 +4949,7 @@ class TestAutoVariables : public TestFixture { " if(b && a)\n" " return *iPtr;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:5:16] -> [test.cpp:7:10] -> [test.cpp:4:13] -> [test.cpp:8:17]: (error) Using pointer to local variable 'x' that is out of scope. [invalidLifetime]\n", errout_str()); diff --git a/test/testbool.cpp b/test/testbool.cpp index 6074bbab46a..46365c11af3 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -96,28 +96,28 @@ class TestBool : public TestFixture { void assignBoolToPointer() { check("void foo(bool *p) {\n" " p = false;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\n", errout_str()); check("void foo(bool *p) {\n" " p = (x[rSize];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // ticket #6588 (c mode) @@ -152,7 +152,7 @@ class TestBool : public TestFixture { " const int *rmat = n < 4 ? " /* OK */ " ctx->q_intra_matrix :" " ctx->q_chroma_intra_matrix;\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\n", errout_str()); // ticket #6588 (c++ mode) @@ -162,7 +162,7 @@ class TestBool : public TestFixture { " const int *rmat = n < 4 ? " /* OK */ " ctx->q_intra_matrix :" " ctx->q_chroma_intra_matrix;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:19]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\n", errout_str()); // ticket #6665 @@ -171,37 +171,37 @@ class TestBool : public TestFixture { " char* m1 = compare(a, b) < 0\n" " ? (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a))\n" " : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); // #7381 check("void foo(bool *p, bool b) {\n" " p = b;\n" " p = &b;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:7]: (error) Boolean value assigned to pointer. [assignBoolToPointer]\n", errout_str()); } void assignBoolToFloat() { check("void foo1() {\n" " double d = false;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\n", errout_str()); check("void foo2() {\n" " float d = true;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\n", errout_str()); check("void foo3() {\n" " long double d = (2>1);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:19]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\n", errout_str()); // stability - don't crash: check("void foo4() {\n" " unknown = false;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" @@ -210,7 +210,7 @@ class TestBool : public TestFixture { "void f() {\n" " S s = {0};\n" " s.p = true;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:9]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\n", errout_str()); check("struct S {\n" @@ -219,7 +219,7 @@ class TestBool : public TestFixture { "void f() {\n" " S s = {0};\n" " *s.p[0] = true;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:13]: (style) Boolean value assigned to floating point variable. [assignBoolToFloat]\n", errout_str()); } @@ -227,50 +227,50 @@ class TestBool : public TestFixture { check("void f(int x) {\n" " if ((x && 0x0f)==6)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if ((x && 0x0f)==0)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if ((x || 0x0f)==6)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if ((x || 0x0f)==0)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if ((x & 0x0f)==6)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if ((x | 0x0f)==6)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if ((5 && x)==3)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if ((5 && x)==3 || (8 && x)==9)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n" "[test.cpp:2:32]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", @@ -279,39 +279,39 @@ class TestBool : public TestFixture { check("void f(int x) {\n" " if ((5 && x)!=3)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if ((5 && x) > 3)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if ((5 && x) > 0)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if ((5 && x) < 0)\n" " a++;\n" - "}" + "}\n" ); ASSERT_EQUALS("[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if ((5 && x) < 1)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if ((5 && x) > 1)\n" " a++;\n" - "}" + "}\n" ); ASSERT_EQUALS("[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\n", errout_str()); @@ -319,91 +319,91 @@ class TestBool : public TestFixture { check("void f(int x) {\n" " if (0 < (5 && x))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if (0 > (5 && x))\n" " a++;\n" - "}" + "}\n" ); ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int x) {\n" " if (1 > (5 && x))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if (1 < (5 && x))\n" " a++;\n" - "}" + "}\n" ); ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(bool x ) {\n" " if ( x > false )\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(bool x ) {\n" " if ( false < x )\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(bool x ) {\n" " if ( x < false )\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(bool x ) {\n" " if ( false > x )\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(bool x ) {\n" " if ( x >= false )\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(bool x ) {\n" " if ( false >= x )\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(bool x ) {\n" " if ( x <= false )\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(bool x ) {\n" " if ( false <= x )\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("typedef int (*func)(bool invert);\n" "void x(int, func f);\n" "void foo(int error) {\n" " if (error == ABC) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); - check("int f() { return !a+b1){} }"); + check("void f() { if (!!a+!!b+!!c>1){} }\n"); ASSERT_EQUALS("",errout_str()); - check("void f(int a, int b, int c) { if (a != !b || c) {} }"); + check("void f(int a, int b, int c) { if (a != !b || c) {} }\n"); ASSERT_EQUALS("",errout_str()); - check("void f(int a, int b, int c) { if (1 < !!a + !!b + !!c) {} }"); + check("void f(int a, int b, int c) { if (1 < !!a + !!b + !!c) {} }\n"); ASSERT_EQUALS("",errout_str()); - check("void f(int a, int b, int c) { if (1 < !(a+b)) {} }"); + check("void f(int a, int b, int c) { if (1 < !(a+b)) {} }\n"); ASSERT_EQUALS("[test.cpp:1:37]: (warning) Comparison of a boolean expression with an integer. [compareBoolExpressionWithInt]\n",errout_str()); } void comparisonOfBoolExpressionWithInt3() { check("int f(int x) {\n" " return t<0>() && x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -498,48 +498,48 @@ class TestBool : public TestFixture { // #5016 check("void f() {\n" " for(int i = 4; i > -1 < 5 ; --i) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:25]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(int a, int b, int c) {\n" " return (a > b) < c;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int a, int b, int c) {\n" " return x(a > b) < c;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int a, int b, int c) {\n" " return a > b == c;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // templates check("struct Tokenizer { TokenList list; };\n" "void Tokenizer::f() {\n" " std::list locationList;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #5063 - or check("void f() {\n" " return a > b or c < d;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f() {\n" " return (a < b) != 0U;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f() {\n" " return (a < b) != 0x0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f() {\n" " return (a < b) != 42U;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:18]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); } @@ -563,7 +563,7 @@ class TestBool : public TestFixture { " }\n" " else\n" " return true;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\n", errout_str()); } @@ -588,7 +588,7 @@ class TestBool : public TestFixture { " }\n" " else\n" " return false;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\n" "[test.cpp:11:7]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\n", errout_str()); } @@ -600,7 +600,7 @@ class TestBool : public TestFixture { " printf(\"foo\");\n" " }\n" "}\n" - "bool compare(int temp);"); + "bool compare(int temp);\n"); ASSERT_EQUALS("[test.cpp:3:19]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n" "[test.cpp:3:12]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\n", errout_str()); } @@ -626,7 +626,7 @@ class TestBool : public TestFixture { " }\n" " else\n" " return false;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:13]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\n", errout_str()); } @@ -650,7 +650,7 @@ class TestBool : public TestFixture { " }\n" " else\n" " return true;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:17]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfTwoFuncsReturningBoolError]\n", errout_str()); } @@ -664,7 +664,7 @@ class TestBool : public TestFixture { " if(compare1(temp) > compare2(temp)){\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("namespace Foo {\n" @@ -676,7 +676,7 @@ class TestBool : public TestFixture { " if(compare1(temp) > compare2(temp)){\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int compare1(int temp);\n" @@ -688,7 +688,7 @@ class TestBool : public TestFixture { " printf(\"foo\");\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:20]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator. [comparisonOfFuncReturningBoolError]\n", errout_str()); check("int compare1(int temp);\n" @@ -700,7 +700,7 @@ class TestBool : public TestFixture { " printf(\"foo\");\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool compare1(int temp);\n" @@ -709,7 +709,7 @@ class TestBool : public TestFixture { " if(foo.compare1(temp) > compare2(temp)){\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -739,7 +739,7 @@ class TestBool : public TestFixture { " if(b > a){ \n" // here warning should be displayed " ;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\n", errout_str()); // op: < check("int main(void){\n" @@ -748,7 +748,7 @@ class TestBool : public TestFixture { " if(b < a){ \n" // here warning should be displayed " ;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\n", errout_str()); // op: >= check("int main(void){\n" @@ -757,7 +757,7 @@ class TestBool : public TestFixture { " if(b >= a){ \n" // here warning should be displayed " ;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\n", errout_str()); // op: <= check("int main(void){\n" @@ -766,7 +766,7 @@ class TestBool : public TestFixture { " if(b <= a){ \n" // here warning should be displayed " ;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator. [comparisonOfBoolWithBoolError]\n", errout_str()); } @@ -778,7 +778,7 @@ class TestBool : public TestFixture { " if ( eval(argv[1]) > eval(argv[2]) )\n" " return 1;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -812,96 +812,96 @@ class TestBool : public TestFixture { void bitwiseOnBoolean() { // 3062 check("void f(_Bool a, _Bool b) {\n" " if(a & b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\n", errout_str()); check("void f(_Bool a, _Bool b) {\n" " if(a | b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a & !b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a | !b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("bool a, b;\n" "void f() {\n" " if(a & b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\n", errout_str()); check("bool a, b;\n" "void f() {\n" " if(a & !b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\n", errout_str()); check("bool a, b;\n" "void f() {\n" " if(a | b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("bool a, b;\n" "void f() {\n" " if(a | !b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("void f(bool a, int b) {\n" " if(a & b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\n", errout_str()); check("void f(int a, bool b) {\n" " if(a & b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\n", errout_str()); check("void f(int a, int b) {\n" " if((a > 0) & (b < 0)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (style, inconclusive) Boolean expression 'a>0' is used in bitwise operation. Did you mean '&&'? [bitwiseOnBoolean]\n", errout_str()); check("void f(bool a, int b) {\n" " if(a | b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("void f(int a, bool b) {\n" " if(a | b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style, inconclusive) Boolean expression 'b' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("int f(bool a, int b) {\n" " return a | b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(bool a, int b) {\n" " return a | b;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (style, inconclusive) Boolean expression 'a' is used in bitwise operation. Did you mean '||'? [bitwiseOnBoolean]\n", errout_str()); check("void f(int a, int b) {\n" " if(a & b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool b) {\n" " foo(bar, &b);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool b) {\n" // #9405 " class C { void foo(bool &b) {} };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f();\n" @@ -970,27 +970,27 @@ class TestBool : public TestFixture { void incrementBoolean() { check("bool bValue = true;\n" - "void f() { bValue++; }"); + "void f() { bValue++; }\n"); ASSERT_EQUALS("[test.cpp:2:12]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\n", errout_str()); check("void f(bool test){\n" " test++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\n", errout_str()); check("void f(bool* test){\n" " (*test)++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:6]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\n", errout_str()); check("void f(bool* test){\n" " test[0]++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead. [incrementboolean]\n", errout_str()); check("void f(int test){\n" " test++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -999,51 +999,51 @@ class TestBool : public TestFixture { " if (x < 10) {\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(bool x) {\n" " if (10 >= x) {\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(bool x) {\n" " if (x != 0) {\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool x) {\n" // #3356 " if (x == 1) {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool x) {\n" " if (x != 10) {\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(bool x) {\n" " if (x == 10) {\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); check("void f(bool x) {\n" " if (x == 0) {\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); - check("DensePropertyMap visited;"); // #4075 + check("DensePropertyMap visited;\n"); // #4075 ASSERT_EQUALS("", errout_str()); } @@ -1052,28 +1052,28 @@ class TestBool : public TestFixture { " if (x == y) {\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x, bool y) {\n" " if (x == y) {\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool x, bool y) {\n" " if (x == y) {\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool x, fooClass y) {\n" " if (x == y) {\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1082,35 +1082,35 @@ class TestBool : public TestFixture { " if (y > false) {\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=). [comparisonOfBoolWithInvalidComparator]\n", errout_str()); check("void f(int y) {\n" " if (true == y) {\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool y) {\n" " if (y == true) {\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool y) {\n" " if (false < 5) {\n" " printf(\"foo\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Comparison of a boolean expression with an integer other than 0 or 1. [compareBoolExpressionWithInt]\n", errout_str()); } void comparisonOfBoolWithInt4() { check("void f(int x) {\n" " if (!x == 1) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1118,21 +1118,21 @@ class TestBool : public TestFixture { check("void SetVisible(int index, bool visible) {\n" " bool (SciTEBase::*ischarforsel)(char ch);\n" " if (visible != GetVisible(index)) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void comparisonOfBoolWithInt6() { // #4224 - integer is casted to bool check("void SetVisible(bool b, int i) {\n" " if (b == (bool)i) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void comparisonOfBoolWithInt7() { // #4846 - (!x==true) check("void f(int x) {\n" " if (!x == true) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1142,7 +1142,7 @@ class TestBool : public TestFixture { " auto res = Fun();\n" " if (expectedResult == res)\n" " throw 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int Fun();\n" @@ -1150,7 +1150,7 @@ class TestBool : public TestFixture { " auto res = Fun();\n" " if (expectedResult == res)\n" " throw 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool Fun();\n" @@ -1158,7 +1158,7 @@ class TestBool : public TestFixture { " auto res = Fun();\n" " if (5 + expectedResult == res)\n" " throw 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int Fun();\n" @@ -1166,7 +1166,7 @@ class TestBool : public TestFixture { " auto res = Fun();\n" " if (5 + expectedResult == res)\n" " throw 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int Fun();\n" @@ -1174,7 +1174,7 @@ class TestBool : public TestFixture { " auto res = Fun();\n" " if (expectedResult == res + 5)\n" " throw 2;\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("error", "", errout_str()); } @@ -1185,7 +1185,7 @@ class TestBool : public TestFixture { " b = !b;\n" " }\n" " return b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1210,76 +1210,76 @@ class TestBool : public TestFixture { void pointerArithBool1() { // #5126 check("void f(char *p) {\n" " if (p+1){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\n", errout_str()); check("void f(char *p) {\n" " do {} while (p+1);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:19]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\n", errout_str()); check("void f(char *p) {\n" " while (p-1) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\n", errout_str()); check("void f(char *p) {\n" " for (int i = 0; p+1; i++) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:22]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\n", errout_str()); check("void f(char *p) {\n" " if (p && p+1){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\n", errout_str()); check("void f(char *p) {\n" " if (p+2 || p) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour. [pointerArithBool]\n", errout_str()); } void returnNonBool() { check("bool f(void) {\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(void) {\n" " return 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(void) {\n" " return 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f(void) {\n" " return -1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f(void) {\n" " return 1 + 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f(void) {\n" " int x = 0;\n" " return x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(void) {\n" " int x = 10;\n" " return x;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f(void) {\n" " return 2 < 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(void) {\n" @@ -1287,7 +1287,7 @@ class TestBool : public TestFixture { " if (a)\n" " ret = 1;\n" " return ret;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(void) {\n" @@ -1295,20 +1295,20 @@ class TestBool : public TestFixture { " if (a)\n" " ret = 3;\n" " return ret;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f(void) {\n" " if (a)\n" " return 3;\n" " return 4;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n" "[test.cpp:4:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f(void) {\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1316,42 +1316,42 @@ class TestBool : public TestFixture { check("bool f(void) {\n" " auto x = [](void) { return -1; };\n" " return false;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(void) {\n" " auto x = [](void) { return -1; };\n" " return 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f(void) {\n" " auto x = [](void) -> int { return -1; };\n" " return false;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(void) {\n" " auto x = [](void) -> int { return -1; };\n" " return 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); } void returnNonBoolLogicalOp() { check("bool f(int x) {\n" " return x & 0x4;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(int x, int y) {\n" " return x | y;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(int x) {\n" " return (x & 0x2);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1359,7 +1359,7 @@ class TestBool : public TestFixture { check("class X {\n" " public:\n" " bool f() { return -1;}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:20]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); check("bool f() {\n" @@ -1368,7 +1368,7 @@ class TestBool : public TestFixture { " int f() { return -1;}\n" " };\n" " return false;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f() {\n" @@ -1377,7 +1377,7 @@ class TestBool : public TestFixture { " int f() { return -1;}\n" " };\n" " return false;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f() {\n" @@ -1386,7 +1386,7 @@ class TestBool : public TestFixture { " bool f() { return -1;}\n" " };\n" " return -1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:5]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n" "[test.cpp:4:24]: (style) Non-boolean value returned from function returning bool [returnNonBoolInBooleanFunction]\n", errout_str()); } diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 8bac50a468c..aafd002bb3c 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -327,7 +327,7 @@ class TestBufferOverrun : public TestFixture { " {\n" " char str[50];\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -349,7 +349,7 @@ class TestBufferOverrun : public TestFixture { "void f4(const char str[])\n" "{\n" " strcpy(buf, str);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -360,7 +360,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " char data[1];\n" " return abc.data[1];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -370,7 +370,7 @@ class TestBufferOverrun : public TestFixture { check("static void f() {\n" " char data[100];\n" " const char *p = data + 100;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -382,7 +382,7 @@ class TestBufferOverrun : public TestFixture { " snprintf(group, 32, \"%u\", 0);\n" " struct group *gr;\n" " snprintf(group, 32, \"%u\", gr->gr_gid);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -392,14 +392,14 @@ class TestBufferOverrun : public TestFixture { " char str[0x10] = {0};\n" " str[15] = 0;\n" " str[16] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:8]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("char f()\n" "{\n" " char str[16] = {0};\n" " return str[16];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:15]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // test stack array @@ -409,7 +409,7 @@ class TestBufferOverrun : public TestFixture { " int y;\n" " y = x[ 4 ];\n" " return y;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9]: (error) Array 'x[3]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("int f()\n" @@ -418,15 +418,15 @@ class TestBufferOverrun : public TestFixture { " int y;\n" " y = x[ 2 ];\n" " return y;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int x[5] = {0};\n" - "int a = x[10];"); + "int a = x[10];\n"); ASSERT_EQUALS("[test.cpp:2:10]: (error) Array 'x[5]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("int x[5] = {0};\n" - "int a = (x)[10];"); + "int a = (x)[10];\n"); ASSERT_EQUALS("[test.cpp:2:12]: (error) Array 'x[5]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -437,21 +437,21 @@ class TestBufferOverrun : public TestFixture { " char *str = new char[0x10];\n" " str[i] = 0;\n" "}\n" - "void b() { a(16); }"); + "void b() { a(16); }\n"); ASSERT_EQUALS("[test.cpp:4:8]: (error) Array 'str[16]' accessed at index 16, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_4() { - check("char c = \"abc\"[4];"); + check("char c = \"abc\"[4];\n"); ASSERT_EQUALS("[test.cpp:1:15]: (error) Array '\"abc\"[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); - check("p = &\"abc\"[4];"); + check("p = &\"abc\"[4];\n"); ASSERT_EQUALS("", errout_str()); - check("char c = \"\\0abc\"[2];"); + check("char c = \"\\0abc\"[2];\n"); ASSERT_EQUALS("", errout_str()); - check("char c = L\"abc\"[4];"); + check("char c = L\"abc\"[4];\n"); ASSERT_EQUALS("[test.cpp:1:16]: (error) Array 'L\"abc\"[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -462,7 +462,7 @@ class TestBufferOverrun : public TestFixture { " int i, sum=0;\n" " for (i = 0; i < 100; i++)\n" " sum += val[i];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:19]: (error) Array 'val[50]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" @@ -471,7 +471,7 @@ class TestBufferOverrun : public TestFixture { " int i, sum=0;\n" " for (i = 1; i < 100; i++)\n" " sum += val[i];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:19]: (error) Array 'val[50]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f(int a)\n" @@ -480,7 +480,7 @@ class TestBufferOverrun : public TestFixture { " int i, sum=0;\n" " for (i = a; i < 100; i++)\n" " sum += val[i];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:19]: (error) Array 'val[50]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("typedef struct g g2[3];\n" @@ -490,21 +490,21 @@ class TestBufferOverrun : public TestFixture { " {\n" " a[i]=0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int argc)\n" "{\n" " char a[2];\n" " for (int i = 4; i < argc; i++){}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int a[10]) {\n" " for (int i=0;i<50;++i) {\n" " a[i] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10]: (error) Array 'a[10]' accessed at index 49, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -518,7 +518,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " struct ABC abc;\n" " abc.str[10] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:12]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct ABC\n" @@ -530,7 +530,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " struct ABC abc;\n" " return abc.str[10];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:19]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // This is not out of bounds because it is a variable length array @@ -543,7 +543,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " struct ABC* x = malloc(sizeof(struct ABC) + 10);\n" " x->str[1] = 0;" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // This is not out of bounds because it is not a variable length array @@ -557,7 +557,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " struct ABC* x = malloc(sizeof(struct ABC) + 10);\n" " x->str[1] = 0;" - "}"); + "}\n"); TODO_ASSERT_EQUALS("error", "", errout_str()); // This is not out of bounds because it is a variable length array @@ -571,8 +571,8 @@ class TestBufferOverrun : public TestFixture { "static void f()\n" "{\n" " struct ABC* x = malloc(sizeof(struct ABC) + 10);\n" - " x->str[10] = 0;" - "}"); + " x->str[10] = 0;\n" + "}\n"); ASSERT_EQUALS("", errout_str()); // This is out of bounds because it is outside the memory allocated. @@ -585,8 +585,8 @@ class TestBufferOverrun : public TestFixture { "static void f()\n" "{\n" " struct ABC* x = malloc(sizeof(struct ABC) + 10);\n" - " x->str[11] = 0;" - "}"); + " x->str[11] = 0;\n" + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:9]: (error) Array 'str[1]' accessed at index 11, which is out of bounds.\n", "", errout_str()); // This is out of bounds if 'sizeof(ABC)' is 1 (No padding) @@ -598,8 +598,8 @@ class TestBufferOverrun : public TestFixture { "static void f()\n" "{\n" " struct ABC* x = malloc(sizeof(ABC) + 10);\n" - " x->str[11] = 0;" - "}"); + " x->str[11] = 0;\n" + "}\n"); TODO_ASSERT_EQUALS("error", "", errout_str()); // This is out of bounds because it is outside the memory allocated @@ -612,8 +612,8 @@ class TestBufferOverrun : public TestFixture { "static void f()\n" "{\n" " struct ABC* x = malloc(sizeof(struct ABC));\n" - " x->str[1] = 0;" - "}"); + " x->str[1] = 0;\n" + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:9]: (error) Array 'str[1]' accessed at index 1, which is out of bounds.\n", "", errout_str()); // This is out of bounds because it is outside the memory allocated @@ -626,8 +626,8 @@ class TestBufferOverrun : public TestFixture { "static void f()\n" "{\n" " struct ABC* x = malloc(sizeof(ABC));\n" - " x->str[1] = 0;" - "}"); + " x->str[1] = 0;\n" + "}\n"); TODO_ASSERT_EQUALS("error", "", errout_str()); // This is out of bounds because it is not a variable array @@ -639,8 +639,8 @@ class TestBufferOverrun : public TestFixture { "static void f()\n" "{\n" " struct ABC x;\n" - " x.str[1] = 0;" - "}"); + " x.str[1] = 0;\n" + "}\n"); ASSERT_EQUALS("[test.cpp:9:10]: (error) Array 'x.str[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct foo\n" @@ -653,19 +653,19 @@ class TestBufferOverrun : public TestFixture { " foo f;\n" " for ( unsigned int i = 0; i < 64; ++i )\n" " f.str[i] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:14]: (error) Array 'f.str[10]' accessed at index 63, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct AB { char a[NUM]; char b[NUM]; }\n" "void f(struct AB *ab) {\n" " ab->a[0] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("union { char a[1]; int b; } ab;\n" "void f() {\n" " ab.a[2] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9]: (error) Array 'ab.a[1]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -679,7 +679,7 @@ class TestBufferOverrun : public TestFixture { "static void f(struct ABC *abc)\n" "{\n" " abc->str[10] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:13]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -698,7 +698,7 @@ class TestBufferOverrun : public TestFixture { " {\n" " abc->str[10] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:13:17]: (error) Array 'abc->str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -713,7 +713,7 @@ class TestBufferOverrun : public TestFixture { "Fred::Fred()\n" "{\n" " str[10] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:8]: (error) Array 'str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("class Fred\n" @@ -726,7 +726,7 @@ class TestBufferOverrun : public TestFixture { "char Fred::c()\n" "{\n" " return str[10];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:15]: (error) Array 'str[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -739,7 +739,7 @@ class TestBufferOverrun : public TestFixture { " if (i < 10)\n" " int x = buf[i];\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -749,7 +749,7 @@ class TestBufferOverrun : public TestFixture { " int a[10];\n" " for (int i = 0; i < 10; i++)\n" " a[i+10] = i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -759,7 +759,7 @@ class TestBufferOverrun : public TestFixture { " int a[10];\n" " for (int i = 0; i < 10; i++)\n" " a[10+i] = i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -769,7 +769,7 @@ class TestBufferOverrun : public TestFixture { " int a[10];\n" " for (int i = 0; i < 10; i++)\n" " a[i+1] = i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -779,7 +779,7 @@ class TestBufferOverrun : public TestFixture { " int a[10];\n" " for (int i = 0; i < 10; i++)\n" " a[i*2] = i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[10]' accessed at index 18, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" @@ -787,7 +787,7 @@ class TestBufferOverrun : public TestFixture { " int a[12];\n" " for (int i = 0; i < 12; i+=6)\n" " a[i+5] = i;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" @@ -795,21 +795,21 @@ class TestBufferOverrun : public TestFixture { " int a[12];\n" " for (int i = 0; i < 12; i+=6)\n" " a[i+6] = i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[12]' accessed at index 12, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" // #4398 " int a[2];\n" " for (int i = 0; i < 4; i+=2)\n" " a[i] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" // #4398 " int a[2];\n" " for (int i = 0; i < 4; i+=2)\n" " do_stuff(a+i);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -822,7 +822,7 @@ class TestBufferOverrun : public TestFixture { " a[i] = i;\n" " i+=1;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" @@ -833,7 +833,7 @@ class TestBufferOverrun : public TestFixture { " a[i] = i;\n" " i++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" @@ -844,7 +844,7 @@ class TestBufferOverrun : public TestFixture { " a[i] = i;\n" " ++i;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" @@ -855,7 +855,7 @@ class TestBufferOverrun : public TestFixture { " a[i] = i;\n" " i=4;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:10]: (error) Array 'a[5]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" @@ -866,7 +866,7 @@ class TestBufferOverrun : public TestFixture { " a[i] = i;\n" " i+=1;\n" " }\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Buffer overrun\n", "", errout_str()); } @@ -876,7 +876,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " char a[2];\n" " char *end = &(a[2]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Getting more than one past the end is not legal @@ -884,7 +884,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " char a[2];\n" " char *end = &(a[3]);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:18]: (error) Array 'a[2]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -895,7 +895,7 @@ class TestBufferOverrun : public TestFixture { " int b[10];\n" " for ( int i = 0; i < 9; i++ )\n" " b[i] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -909,7 +909,7 @@ class TestBufferOverrun : public TestFixture { " for(int j=0; j<3; ++j) {\n" " int b = indices[j];\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -917,7 +917,7 @@ class TestBufferOverrun : public TestFixture { check("int main() {\n" " size_t indices[2];\n" " int b = indices[2];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:18]: (error) Array 'indices[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -926,7 +926,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " char c[10];\n" " c[1<<23]='a';\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 'c[10]' accessed at index 8388608, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -945,7 +945,7 @@ class TestBufferOverrun : public TestFixture { " int a[n];\n" // n <= SCHAR_MAX " a[-1] = 0;\n" // negative index " a[128] = 0;\n" // 128 > SCHAR_MAX - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[128]' accessed at index -1, which is out of bounds. [negativeIndex]\n" "[test.cpp:4:6]: (error) Array 'a[128]' accessed at index 128, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); @@ -953,7 +953,7 @@ class TestBufferOverrun : public TestFixture { " int a[n];\n" // n <= UCHAR_MAX " a[-1] = 0;\n" // negative index " a[256] = 0;\n" // 256 > UCHAR_MAX - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[256]' accessed at index -1, which is out of bounds. [negativeIndex]\n" "[test.cpp:4:6]: (error) Array 'a[256]' accessed at index 256, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); @@ -961,7 +961,7 @@ class TestBufferOverrun : public TestFixture { " int a[n];\n" // n <= SHRT_MAX " a[-1] = 0;\n" // negative index " a[32768] = 0;\n" // 32768 > SHRT_MAX - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[32768]' accessed at index -1, which is out of bounds. [negativeIndex]\n" "[test.cpp:4:6]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); @@ -969,7 +969,7 @@ class TestBufferOverrun : public TestFixture { " int a[n];\n" // n <= USHRT_MAX " a[-1] = 0;\n" // negative index " a[65536] = 0;\n" // 65536 > USHRT_MAX - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[65536]' accessed at index -1, which is out of bounds. [negativeIndex]\n" "[test.cpp:4:6]: (error) Array 'a[65536]' accessed at index 65536, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); @@ -977,26 +977,26 @@ class TestBufferOverrun : public TestFixture { " int a[n];\n" // n <= SHRT_MAX " a[-1] = 0;\n" // negative index " a[32768] = 0;\n" // 32768 > SHRT_MAX - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[32768]' accessed at index -1, which is out of bounds. [negativeIndex]\n" "[test.cpp:4:6]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f(int n) {\n" " int a[n];\n" // n <= INT_MAX " a[-1] = 0;\n" // negative index - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); check("void f(unsigned int n) {\n" " int a[n];\n" // n <= UINT_MAX " a[-1] = 0;\n" // negative index - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[4294967296]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); check("void f(signed int n) {\n" " int a[n];\n" // n <= INT_MAX " a[-1] = 0;\n" // negative index - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'a[2147483648]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); } @@ -1004,7 +1004,7 @@ class TestBufferOverrun : public TestFixture { check("void foo()\n" "{\n" " long l[SOME_SIZE];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1014,7 +1014,7 @@ class TestBufferOverrun : public TestFixture { " int a[3];\n" " for (int i = 3; 0 <= i; i--)\n" " a[i] = i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" @@ -1022,7 +1022,7 @@ class TestBufferOverrun : public TestFixture { " int a[4];\n" " for (int i = 3; 0 <= i; i--)\n" " a[i] = i;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1032,7 +1032,7 @@ class TestBufferOverrun : public TestFixture { " int a[10];\n" " for (int i = 0; i < 10; i++)\n" " a[i-1] = a[i];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); } @@ -1043,7 +1043,7 @@ class TestBufferOverrun : public TestFixture { " int i[2];\n" " int *ip = i + 1;\n" " ip[-10] = 1;\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Array ip[-10] out of bounds.\n", "", errout_str()); } @@ -1055,7 +1055,7 @@ class TestBufferOverrun : public TestFixture { " int *i = iBuf + 9;" " int *ii = i + -5;" " ii[10] = 0;" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Array ii[10] out of bounds.\n", "", errout_str()); } @@ -1065,7 +1065,7 @@ class TestBufferOverrun : public TestFixture { check("void f() {\n" " UINT8 x[2];\n" " x[5] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'x[2]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -1082,7 +1082,7 @@ class TestBufferOverrun : public TestFixture { "void y() {\n" " struct s1 obj;\n" " x(obj.delay, 123);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct s1 {\n" @@ -1096,7 +1096,7 @@ class TestBufferOverrun : public TestFixture { "void y() {\n" " struct s1 obj;\n" " x(obj.delay, 123);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:6]: (error) Array 'obj.delay[3]' accessed at index 4, which is out of bounds.\n", "", errout_str()); @@ -1107,7 +1107,7 @@ class TestBufferOverrun : public TestFixture { "\n" "void f() {\n" " struct s1 *obj;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1121,14 +1121,14 @@ class TestBufferOverrun : public TestFixture { " m_x[1] = 0;\n" " }\n" " int m_x[1];\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:7:11]: (error) Array 'm_x[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void array_index_33() { check("void foo(char bar[][4]) {\n" " baz(bar[5]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1137,7 +1137,7 @@ class TestBufferOverrun : public TestFixture { " int y[2][2][2];\n" " y[0][2][0] = 0;\n" " y[0][0][2] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:6]: (error) Array 'y[2][2][2]' accessed at index y[0][2][0], which is out of bounds. [arrayIndexOutOfBounds]\n" "[test.cpp:4:6]: (error) Array 'y[2][2][2]' accessed at index y[0][0][2], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); @@ -1157,7 +1157,7 @@ class TestBufferOverrun : public TestFixture { " ptest->a[10] = 3;\n" " ptest->b[10][2] = 4;\n" " ptest->b[0][19] = 4;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:11]: (error) Array 'test.a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n" "[test.cpp:10:11]: (error) Array 'test.b[10][5]' accessed at index test.b[10][2], which is out of bounds. [arrayIndexOutOfBounds]\n" "[test.cpp:11:11]: (error) Array 'test.b[10][5]' accessed at index test.b[0][19], which is out of bounds. [arrayIndexOutOfBounds]\n" @@ -1178,7 +1178,7 @@ class TestBufferOverrun : public TestFixture { " ptest = &test;\n" " ptest->a[9][5] = 4;\n" " ptest->a[0][50] = 4;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:11]: (error) Array 'test.a[10][5]' accessed at index test.a[9][5], which is out of bounds. [arrayIndexOutOfBounds]\n" "[test.cpp:9:11]: (error) Array 'test.a[10][5]' accessed at index test.a[0][50], which is out of bounds. [arrayIndexOutOfBounds]\n" "[test.cpp:12:13]: (error) Array 'ptest->a[10][5]' accessed at index ptest->a[9][5], which is out of bounds. [arrayIndexOutOfBounds]\n" @@ -1189,21 +1189,21 @@ class TestBufferOverrun : public TestFixture { check("void f() {\n" " struct Struct { unsigned m_Var[1]; } s;\n" " s.m_Var[1] = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:12]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct Struct { unsigned m_Var[1]; };\n" "void f() {\n" " struct Struct s;\n" " s.m_Var[1] = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:12]: (error) Array 's.m_Var[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct Struct { unsigned m_Var[1]; };\n" "void f() {\n" " struct Struct * s = calloc(40);\n" " s->m_Var[1] = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1215,7 +1215,7 @@ class TestBufferOverrun : public TestFixture { "};\n" "Fred::Fred(const Fred & rhs) {\n" " m_b[2] = rhs.m_b[2];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:8]: (error) Array 'm_b[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n" "[test.cpp:7:21]: (error) Array 'rhs.m_b[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -1227,7 +1227,7 @@ class TestBufferOverrun : public TestFixture { " for (unsigned int i = 0; i < 15; i++)\n" " i;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1246,7 +1246,7 @@ class TestBufferOverrun : public TestFixture { " }\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1255,7 +1255,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " char a[10];\n" " a[10] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -1264,7 +1264,7 @@ class TestBufferOverrun : public TestFixture { " char a[10];\n" " for (int i = 0; i < 10; ++i)\n" " f2(&a[i + 1]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1277,7 +1277,7 @@ class TestBufferOverrun : public TestFixture { "\n" "void b() {\n" " struct Fred { char data[3]; } fred;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void a() {\n" @@ -1288,7 +1288,7 @@ class TestBufferOverrun : public TestFixture { "void b() {\n" " struct Fred { char data[3]; } fred;\n" " fred.data[4] = 0;\n" // <- error - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:14]: (error) Array 'fred.data[3]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -1299,7 +1299,7 @@ class TestBufferOverrun : public TestFixture { " char *p; p = (char *)malloc(10);\n" " p[10] = 7;\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" @@ -1307,7 +1307,7 @@ class TestBufferOverrun : public TestFixture { " float *p; p = (float *)malloc(10 * sizeof(float));\n" " p[10] = 7;\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" @@ -1316,7 +1316,7 @@ class TestBufferOverrun : public TestFixture { " p[0] = 0;\n" " p[9] = 9;\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" @@ -1325,7 +1325,7 @@ class TestBufferOverrun : public TestFixture { " p[0] = 0;\n" " p[9] = 9;\n" " delete [] p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" @@ -1334,7 +1334,7 @@ class TestBufferOverrun : public TestFixture { " p[0] = 0;\n" " p[9] = 9;\n" " delete [] p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" @@ -1345,11 +1345,11 @@ class TestBufferOverrun : public TestFixture { " }\n" " catch(...){\n" " return;\n" - " }" + " }\n" " p[0] = 0;\n" " p[9] = 9;\n" " delete [] p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1366,7 +1366,7 @@ class TestBufferOverrun : public TestFixture { " var[ 0 ].arr[ 2 ] = 2;\n" " y = var[ 0 ].arr[ 3 ];\n" // <-- array access out of bounds " return y;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:20]: (error) Array 'var[0].arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("int f( )\n" @@ -1380,7 +1380,7 @@ class TestBufferOverrun : public TestFixture { " var[ 0 ].arr[ 2 ] = 2;\n" " y = var[ 0 ].arr[ 2 ];\n" " return y;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); @@ -1396,7 +1396,7 @@ class TestBufferOverrun : public TestFixture { "var.arr[ 3 ] = 3;\n" // <-- array access out of bounds "y=var.arr[ 3 ];\n" // <-- array access out of bounds "return y;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:8]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\n" "[test.cpp:11:10]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); @@ -1410,7 +1410,7 @@ class TestBufferOverrun : public TestFixture { "var[0].var[ 1 ] = 1;\n" "var[0].var[ 2 ] = 2;\n" "var[0].var[ 4 ] = 4;\n" // <-- array access out of bounds - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:11]: (error) Array 'var[0].var[3]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f( ) {\n" @@ -1421,7 +1421,7 @@ class TestBufferOverrun : public TestFixture { "var[0].var[ 0 ] = 0;\n" "var[0].var[ 1 ] = 1;\n" "var[0].var[ 2 ] = 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // avoid FPs (modified examples taken from #3838) @@ -1430,7 +1430,7 @@ class TestBufferOverrun : public TestFixture { " struct AB ab;\n" " int * p = &ab.a[10];\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct AB { int a[10]; int b[10]; };\n" @@ -1438,7 +1438,7 @@ class TestBufferOverrun : public TestFixture { " struct AB ab[1];\n" " int * p = &ab[0].a[10];\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct AB { int a[10]; int b[10]; };\n" @@ -1446,7 +1446,7 @@ class TestBufferOverrun : public TestFixture { " struct AB ab[1];\n" " int * p = &ab[10].a[0];\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:18]: (error) Array 'ab[1]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -1460,7 +1460,7 @@ class TestBufferOverrun : public TestFixture { " {\n" " buf[i] = 1;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" @@ -1470,7 +1470,7 @@ class TestBufferOverrun : public TestFixture { " {\n" " buf[i] = 2.;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1483,7 +1483,7 @@ class TestBufferOverrun : public TestFixture { "void test() {\n" " CHAR buffer[1024];\n" " f(\"%s\", buffer);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Unnamed argument @@ -1493,7 +1493,7 @@ class TestBufferOverrun : public TestFixture { "void test() {\n" " char buffer[1024];\n" " f(buffer);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1505,7 +1505,7 @@ class TestBufferOverrun : public TestFixture { " for(int i=3; i--;) {\n" " printf(\"files(%i): %s\", 3-i, buffer[3-i]);\n" " }\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Array 'buffer[3]' accessed at index 3, which is out of bounds.\n", "", errout_str()); check("void f() {\n" @@ -1514,7 +1514,7 @@ class TestBufferOverrun : public TestFixture { " for(i=10; i--;) {\n" " buffer[i] = i;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:15]: (error) Array 'buffer[9]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // Correct access limits -> i from 9 to 0 @@ -1523,7 +1523,7 @@ class TestBufferOverrun : public TestFixture { " for(unsigned long int i=10; i--;) {\n" " buffer[i] = i;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1533,7 +1533,7 @@ class TestBufferOverrun : public TestFixture { "void f() {\n" " for (int i = 2; i < 0; i++)\n" " s[i] = 5;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1546,7 +1546,7 @@ class TestBufferOverrun : public TestFixture { " printf(\" %i\", i);\n" " array[i] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:14]: (error) Array 'array[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void test(void)\n" @@ -1556,7 +1556,7 @@ class TestBufferOverrun : public TestFixture { " scanf(\"%i\", &i);\n" " array[i] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1570,7 +1570,7 @@ class TestBufferOverrun : public TestFixture { " i++;\n" " }\n" " arr[k];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1582,7 +1582,7 @@ class TestBufferOverrun : public TestFixture { "void g() {\n" " f(\"12345678\");\n" " f(\"12345\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1590,7 +1590,7 @@ class TestBufferOverrun : public TestFixture { check("void f(void){\n" " int k=0, dd, d[1U] = {1};\n" " for (dd=d[k]; k<10; dd=d[++k]){;}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:29]: (error) Array 'd[1]' accessed at index 1, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -1601,7 +1601,7 @@ class TestBufferOverrun : public TestFixture { " for(int i = 0, j= 11; i < j; ++i)\n" " buf[i] = 0;\n" " return buf[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:11]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -1613,7 +1613,7 @@ class TestBufferOverrun : public TestFixture { " for (int i=0; i < 3; i++)\n" " for (int j = 0; j < 3; j++)\n" " M[i][j]=0.0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:15]: (error) Array 'M[3][1]' accessed at index M[*][2], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -2017,87 +2017,87 @@ class TestBufferOverrun : public TestFixture { "{\n" " char a[2][2];\n" " a[1][1] = 'a';\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" "{\n" " char a[2][2][2];\n" " a[1][1][1] = 'a';\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" "{\n" " char a[2][2];\n" " a[2][1] = 'a';\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'a[2][2]' accessed at index a[2][1], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " char a[2][2];\n" " a[1][2] = 'a';\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'a[2][2]' accessed at index a[1][2], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " char a[2][2][2];\n" " a[2][1][1] = 'a';\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'a[2][2][2]' accessed at index a[2][1][1], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " char a[2][2][2];\n" " a[1][2][1] = 'a';\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'a[2][2][2]' accessed at index a[1][2][1], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " char a[2][2][2][2];\n" " a[1][2][1][1] = 'a';\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'a[2][2][2][2]' accessed at index a[1][2][1][1], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " char a[2][2][2];\n" " a[1][1][2] = 'a';\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'a[2][2][2]' accessed at index a[1][1][2], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " char a[10][10][10];\n" " a[2*3][4*3][2] = 'a';\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:4]: (error) Array 'a[10][10][10]' accessed at index a[6][12][2], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " char a[10][10][10];\n" " a[6][40][10] = 'a';\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:4]: (error) Array 'a[10][10][10]' accessed at index a[6][40][10], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " char a[1][1][1];\n" " a[2][2][2] = 'a';\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:4]: (error) Array 'a[1][1][1]' accessed at index a[2][2][2], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " char a[6][6][6];\n" " a[6][6][2] = 'a';\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:4]: (error) Array 'a[6][6][6]' accessed at index a[6][6][2], which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " int a[2][2];\n" " p = &a[2][0];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // unknown dim.. @@ -2105,7 +2105,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " int a[2][countof(x)] = {{1,2},{3,4}};\n" " a[0][0] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void draw_quad(float z) {\n" @@ -2127,7 +2127,7 @@ class TestBufferOverrun : public TestFixture { " vertices[i][1][2] = 4.0;\n" " vertices[i][1][3] = 5.0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); { @@ -2136,7 +2136,7 @@ class TestBufferOverrun : public TestFixture { " const size_t B = 2;\n" " extern int stuff[A][B];\n" " return stuff[0][1];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // TODO: better handling of VLAs in symboldatabase. should be @@ -2146,7 +2146,7 @@ class TestBufferOverrun : public TestFixture { " const size_t B = 2;\n" " extern int stuff[A][B];\n" " return stuff[0][1];\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("error", "", errout_str()); } } @@ -2167,7 +2167,7 @@ class TestBufferOverrun : public TestFixture { " break;\n" " };\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" @@ -2185,7 +2185,7 @@ class TestBufferOverrun : public TestFixture { " break;\n" " };\n" " }\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:12]: (error) Array index out of bounds.\n", "", errout_str()); } @@ -2197,7 +2197,7 @@ class TestBufferOverrun : public TestFixture { " a[i] = 0;\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2207,7 +2207,7 @@ class TestBufferOverrun : public TestFixture { "void f(int i) {\n" " if (i >= 0 && i < 10) {}\n" " a[i] = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:19] -> [test.cpp:4:4]: (warning) Either the condition 'i<10' is redundant or the array 'a[10]' is accessed at index 10, which is out of bounds. [arrayIndexOutOfBoundsCond]\n" "[test.cpp:3:9] -> [test.cpp:4:4]: (warning) Either the condition 'i>=0' is redundant or the array 'a[10]' is accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); @@ -2221,7 +2221,7 @@ class TestBufferOverrun : public TestFixture { " for (int i = 19; i < 36; ++i) {\n" " data[i/2] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:13]: (error) Array 'data[8]' accessed at index 17, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // #2199 - false negative: array out of bounds in loop when there is calculation @@ -2231,7 +2231,7 @@ class TestBufferOverrun : public TestFixture { " for (int i = 0; i < 5; ++i) {\n" " arr[i + 7] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:12]: (error) Array 'arr[5]' accessed at index 11, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -2241,21 +2241,21 @@ class TestBufferOverrun : public TestFixture { "{\n" " char data[8];\n" " data[-1] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Array 'data[8]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); check("void f()\n" "{\n" " char data[8][4];\n" " data[5][-1] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Array 'data[8][4]' accessed at index data[*][-1], which is out of bounds. [negativeIndex]\n", errout_str()); // #1614 - negative index is ok for pointers check("void foo(char *p)\n" "{\n" " p[-1] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" @@ -2263,14 +2263,14 @@ class TestBufferOverrun : public TestFixture { " char s[] = \"abc\";\n" " char *p = s + strlen(s);\n" " if (p[-1]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // ticket #1850 check("int f(const std::map > &m)\n" "{\n" " return m[0][-1];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2279,7 +2279,7 @@ class TestBufferOverrun : public TestFixture { "void foo() {\n" " TEST test;\n" " test.a[-1] = 3;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:11]: (error) Array 'test.a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); } @@ -2295,7 +2295,7 @@ class TestBufferOverrun : public TestFixture { "void g(int i) {\n" " if( i == 0 )\n" " return f(i);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2402,7 +2402,7 @@ class TestBufferOverrun : public TestFixture { " for (int i = 10; i > 0; --i) {\n" " data[i] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:13]: (error) Array 'data[8]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" @@ -2411,7 +2411,7 @@ class TestBufferOverrun : public TestFixture { " for (unsigned int i = 3; i < 5; --i) {\n" " val[i+1] = val[i];\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" @@ -2420,7 +2420,7 @@ class TestBufferOverrun : public TestFixture { " for (int i = 3; i < 5; --i) {\n" " val[i+1] = val[i];\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:12]: (error) Array 'val[5]' accessed at index -9994, which is out of bounds. [negativeIndex]\n" "[test.cpp:5:23]: (error) Array 'val[5]' accessed at index -9995, which is out of bounds. [negativeIndex]\n", errout_str()); } @@ -2438,7 +2438,7 @@ class TestBufferOverrun : public TestFixture { " A a;\n" " a.data[3] = 0;\n" " a.b.data[2] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #1586 @@ -2453,7 +2453,7 @@ class TestBufferOverrun : public TestFixture { " A a;\n" " a.data[4] = 0;\n" " a.b.data[3] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:11]: (error) Array 'a.data[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n" "[test.cpp:11:13]: (error) Array 'a.b.data[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -2467,7 +2467,7 @@ class TestBufferOverrun : public TestFixture { " for (x = 0; x < 10 && y; x++) {\n" " data[x] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" @@ -2476,7 +2476,7 @@ class TestBufferOverrun : public TestFixture { " for (x = 0; x < 10 || y; x++) {\n" " data[x] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" @@ -2485,7 +2485,7 @@ class TestBufferOverrun : public TestFixture { " for (x = 0; x <= 10 && y; x++) {\n" " data[x] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" @@ -2494,7 +2494,7 @@ class TestBufferOverrun : public TestFixture { " for (x = 0; y && x <= 10; x++) {\n" " data[x] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:13]: (error) Array 'data[2]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("int f() {\n" // #9126 @@ -2506,7 +2506,7 @@ class TestBufferOverrun : public TestFixture { " c++;\n" " }\n" " return c;\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); } @@ -2520,7 +2520,7 @@ class TestBufferOverrun : public TestFixture { " }\n" " a[i - 1] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // extracttests.start: int maybe(); @@ -2532,7 +2532,7 @@ class TestBufferOverrun : public TestFixture { " }\n" " a[i - 1] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:10]: (error) Array 'a[2]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); } @@ -2545,7 +2545,7 @@ class TestBufferOverrun : public TestFixture { " }\n" " a[i] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:10]: (error) Array 'a[10]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // Ticket #2385 - No false positive @@ -2557,7 +2557,7 @@ class TestBufferOverrun : public TestFixture { " a[i-10] = 0;\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Ticket #3893 - start value out of bounds @@ -2567,7 +2567,7 @@ class TestBufferOverrun : public TestFixture { " for (int i = 10; maybe(); dostuff()) {\n" " a[i] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // #7686 @@ -2601,7 +2601,7 @@ class TestBufferOverrun : public TestFixture { " for (int i = 0; i != 10; ++i) {\n" " a[i] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: (error) Array 'a[5]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -2613,7 +2613,7 @@ class TestBufferOverrun : public TestFixture { " for (int i = 0; i != 10; ++i) {\n" " i == 0 ? 0 : a[i-1];\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -2621,7 +2621,7 @@ class TestBufferOverrun : public TestFixture { " for (int i = 0; i != 10; ++i) {\n" " some_condition ? 0 : a[i-1];\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:31]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); @@ -2631,7 +2631,7 @@ class TestBufferOverrun : public TestFixture { " i==0 ? 0 : a[i-1];\n" " a[i-1] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); } @@ -2639,7 +2639,7 @@ class TestBufferOverrun : public TestFixture { check("void f() {\n" " char a[10];\n" " for (i=0; i<10; i++);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2650,14 +2650,14 @@ class TestBufferOverrun : public TestFixture { " for (int i=0; i<7; ++i) {\n" " a[0] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void array_index_extern() { // Ticket #1684. FP when using 'extern'. check("extern char arr[15];\n" - "char arr[15] = \"abc\";"); + "char arr[15] = \"abc\";\n"); ASSERT_EQUALS("", errout_str()); } @@ -2671,7 +2671,7 @@ class TestBufferOverrun : public TestFixture { "void f2() {\n" " int x[2];\n" " f1(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Same type => error @@ -2681,7 +2681,7 @@ class TestBufferOverrun : public TestFixture { "void f2() {\n" " char x[2];\n" " f1(x);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:2]: (error) Array 'x[2]' accessed at index 4, which is out of bounds.\n", "", errout_str()); @@ -2691,41 +2691,41 @@ class TestBufferOverrun : public TestFixture { check("void f() {\n" " const char *str = \"abc\";\n" " bar(str[10]);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:12]: (error) Array 'str[4]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " const char *str = \"abc\";\n" " bar(str[4]);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:12]: (error) Array 'str[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " const char *str = \"abc\";\n" " bar(str[3]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" "{\n" " const char *str = \"a\tc\";\n" " bar(str[4]);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:12]: (error) Array 'str[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" // #6973 " const char *name = \"\";\n" " if ( name[0] == 'U' ? name[1] : 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int main(int argc, char **argv) {\n" " char str[6] = \"\\0\";\n" " unsigned short port = 65535;\n" " snprintf(str, sizeof(str), \"%hu\", port);\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("int f(int x) {\n" // #11020 @@ -2747,7 +2747,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " struct tt *tt=x;\n" " tt->name;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // detect error @@ -2758,7 +2758,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " struct tt *tt=x;\n" " tt->name[22] = 123;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:13]: (error) Array 'tt->name[21]' accessed at index 22, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -2767,7 +2767,7 @@ class TestBufferOverrun : public TestFixture { " char str[3];\n" " str[i] = 0;\n" " if (i==10) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10] -> [test.cpp:3:8]: (warning) Either the condition 'i==10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds. [arrayIndexOutOfBoundsCond]\n", errout_str()); check("void f(int i) {\n" @@ -2776,31 +2776,31 @@ class TestBufferOverrun : public TestFixture { " switch (i) {\n" " case 10: break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5] -> [test.cpp:3:8]: (warning) Either the switch case 'case 10' is redundant or the array 'str[3]' is accessed at index 10, which is out of bounds. [arrayIndexOutOfBoundsCond]\n", errout_str()); check("void f() {\n" " char str[3];\n" " str[((unsigned char)3) - 1] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" // #5416 FP " char *str[3];\n" " do_something(&str[0][5]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class X { static const int x[100]; };\n" // #6070 - "const int X::x[100] = {0};"); + "const int X::x[100] = {0};\n"); ASSERT_EQUALS("", errout_str()); check("namespace { class X { static const int x[100]; };\n" // #6232 - "const int X::x[100] = {0}; }"); + "const int X::x[100] = {0}; }\n"); ASSERT_EQUALS("", errout_str()); check("class ActorSprite { static ImageSet * targetCursorImages[2][10]; };\n" - "ImageSet *ActorSprite::targetCursorImages[2][10];"); + "ImageSet *ActorSprite::targetCursorImages[2][10];\n"); ASSERT_EQUALS("", errout_str()); check("int f(const std::size_t s) {\n" // #10130 @@ -2832,7 +2832,7 @@ class TestBufferOverrun : public TestFixture { " int a[10];\n" " int *p = a;\n" " p[20] = 0;\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[10]' accessed at index 20, which is out of bounds.\n", "", errout_str()); { @@ -2841,14 +2841,14 @@ class TestBufferOverrun : public TestFixture { " int a[10];\n" " int *p = a;\n" " p[10] = 0;\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4:6]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", "", errout_str()); check("void f() {\n" " int a[10];\n" " int *p = a;\n" " dostuff(&p[10]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2856,33 +2856,33 @@ class TestBufferOverrun : public TestFixture { " int a[X];\n" // unknown size " int *p = a;\n" " p[20] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int a[2];\n" " char *p = (char *)a;\n" // cast " p[4] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void array_index_function_parameter() { check("void f(char a[10]) {\n" " a[20] = 0;\n" // <- cppcheck warn here even though it's not a definite access out of bounds - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:4]: (error) Array 'a[10]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f(char a[10]) {\n" // #6353 - reassign 'a' " a += 4;\n" " a[-1] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(char a[10]) {\n" " a[0] = 0;\n" " a[-1] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:4]: (error) Array 'a[10]' accessed at index -1, which is out of bounds. [negativeIndex]\n", errout_str()); } @@ -2891,7 +2891,7 @@ class TestBufferOverrun : public TestFixture { "void f() {\n" " E arrE[] = { e1, e2 };\n" " arrE[sizeof(arrE)] = e1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Array 'arrE[2]' accessed at index 8, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -2899,7 +2899,7 @@ class TestBufferOverrun : public TestFixture { check("constexpr int blockLen = 10;\n" "void foo(std::array& a) {\n" " a[2] = 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2909,14 +2909,14 @@ class TestBufferOverrun : public TestFixture { " std::vector v(3);\n" " int* p = v.data();\n" " p[2] = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " std::vector v(3);\n" " int* p = v.data();\n" " p[5] = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:6]: (error) Array 'p[3]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); @@ -2925,7 +2925,7 @@ class TestBufferOverrun : public TestFixture { " std::vector v(3);\n" " memset(v.data(), 0, 12);\n" " memset(v.data(), 0, 100);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:18]: (error) Buffer is accessed out of bounds: v.data() [bufferAccessOutOfBounds]\n", errout_str()); @@ -2933,7 +2933,7 @@ class TestBufferOverrun : public TestFixture { " std::vector v(3);\n" " int* p = v.data();\n" " memset(p, 0, 100);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:12]: (error) Buffer is accessed out of bounds: p [bufferAccessOutOfBounds]\n", errout_str()); @@ -2944,7 +2944,7 @@ class TestBufferOverrun : public TestFixture { " int* p = v.data();\n" " v.resize(10);\n" " memset(p, 0, 40);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // ..or when the pointer is reassigned @@ -2953,7 +2953,7 @@ class TestBufferOverrun : public TestFixture { " int* p = v.data();\n" " p = q;\n" " memset(p, 0, 100);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // the buffer of c_str() includes the null terminator @@ -2961,7 +2961,7 @@ class TestBufferOverrun : public TestFixture { " std::string s = \"abc\";\n" " memcpy(dst, s.c_str(), 4);\n" " memcpy(dst, s.c_str(), 5);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:24]: (error) Buffer is accessed out of bounds: s.c_str() [bufferAccessOutOfBounds]\n", errout_str()); } @@ -2976,7 +2976,7 @@ class TestBufferOverrun : public TestFixture { " sum += val[i];\n" " if (i < 50)\n" " sum -= val[i];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool b();\n" @@ -2990,7 +2990,7 @@ class TestBufferOverrun : public TestFixture { " sum -= val[i];\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool b();\n" @@ -3002,7 +3002,7 @@ class TestBufferOverrun : public TestFixture { " sum += val[i];\n" " for (; i < 50; i++)\n" " sum -= val[i];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3089,7 +3089,7 @@ class TestBufferOverrun : public TestFixture { "static void f(struct ABC *abc)\n" "{\n" " strcpy( abc->str, \"abcdef\" );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:16]: (error) Buffer is accessed out of bounds: abc->str [bufferAccessOutOfBounds]\n", errout_str()); check("struct ABC\n" @@ -3101,7 +3101,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " struct ABC abc;\n" " strcpy( abc.str, \"abcdef\" );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:16]: (error) Buffer is accessed out of bounds: abc.str [bufferAccessOutOfBounds]\n", errout_str()); check("struct ABC\n" @@ -3112,7 +3112,7 @@ class TestBufferOverrun : public TestFixture { "static void f(struct ABC &abc)\n" "{\n" " strcpy( abc.str, \"abcdef\" );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:16]: (error) Buffer is accessed out of bounds: abc.str [bufferAccessOutOfBounds]\n", errout_str()); check("static void f()\n" @@ -3122,7 +3122,7 @@ class TestBufferOverrun : public TestFixture { " char str[5];\n" " } abc;\n" " strcpy( abc.str, \"abcdef\" );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:16]: (error) Buffer is accessed out of bounds: abc.str [bufferAccessOutOfBounds]\n", errout_str()); check("static void f()\n" @@ -3134,7 +3134,7 @@ class TestBufferOverrun : public TestFixture { " struct ABC *abc = malloc(sizeof(struct ABC));\n" " strcpy( abc->str, \"abcdef\" );\n" " free(abc);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:16]: (error) Buffer is accessed out of bounds: abc->str [bufferAccessOutOfBounds]\n", errout_str()); } @@ -3147,7 +3147,7 @@ class TestBufferOverrun : public TestFixture { " int i;\n" " for (i = 0; i <= 10; ++i)\n" " a[i] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:10]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct S { int b; } static e[1];\n" // #11052 @@ -3162,7 +3162,7 @@ class TestBufferOverrun : public TestFixture { " const char *p[2];\n" " for (int i = 0; i < 8; ++i)\n" " p[i] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'p[2]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // No false positive @@ -3171,7 +3171,7 @@ class TestBufferOverrun : public TestFixture { " const char *p[2];\n" " const char *s = y + p[1];\n" " p[1] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // There is no error here @@ -3183,7 +3183,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " char s[3];\n" " f1(s,20);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout_str()); check("void f1(char *s,int size)\n" @@ -3204,7 +3204,7 @@ class TestBufferOverrun : public TestFixture { " char n[5];\n" " sprintf(n, \"d\");\n" " printf(\"hello!\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3214,21 +3214,21 @@ class TestBufferOverrun : public TestFixture { " char n[5];\n" " strcat(n, \"abc\");\n" " strcat(n, \"def\");\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: n\n", "", errout_str()); check("void f()\n" // #12489 "{\n" " char d[3] = {};\n" " strcat(d, \"12345678\");\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:11]: (error) Buffer is accessed out of bounds: d [bufferAccessOutOfBounds]\n", errout_str()); check("void f()\n" "{\n" " char d[3] = \"ab\"; \n" " strcat(d, \"c\");\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4:11]: (error) Buffer is accessed out of bounds: d [bufferAccessOutOfBounds]\n", "", errout_str()); } @@ -3238,7 +3238,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " char a[2];\n" " strcpy(a, \"a\\0\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3251,7 +3251,7 @@ class TestBufferOverrun : public TestFixture { " {\n" " a[i] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" @@ -3261,7 +3261,7 @@ class TestBufferOverrun : public TestFixture { " {\n" " a[i] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3275,7 +3275,7 @@ class TestBufferOverrun : public TestFixture { " a[i] = 0;\n" " i += 100;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3288,7 +3288,7 @@ class TestBufferOverrun : public TestFixture { " {\n" " char b = a[i];\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3299,7 +3299,7 @@ class TestBufferOverrun : public TestFixture { " for (float i=0; i<10.0;i=i+0.1)\n" " {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" @@ -3308,7 +3308,7 @@ class TestBufferOverrun : public TestFixture { " for (float i=0; i<10.0;i=0.1+i)\n" " {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3320,7 +3320,7 @@ class TestBufferOverrun : public TestFixture { "void A::f(int i, int ii)\n" "{\n" " strcpy(val, \"ab\") ;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:12]: (error) Buffer is accessed out of bounds: val [bufferAccessOutOfBounds]\n", errout_str()); } @@ -3329,20 +3329,20 @@ class TestBufferOverrun : public TestFixture { check("void f() {\n" " struct Foo foo[5];\n" " memset(foo, 0, sizeof(foo));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" // ticket #2093 " gchar x[3];\n" " strcpy(x, \"12\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("extern char a[10];\n" "void f() {\n" " char b[25] = {0};\n" " std::memcpy(b, a, 10);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3356,7 +3356,7 @@ class TestBufferOverrun : public TestFixture { " for (int i=0; i<6; i++) {\n" " b[i] = b[i+1];\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class A {\n" @@ -3368,7 +3368,7 @@ class TestBufferOverrun : public TestFixture { " for (int i=0; i<7; i++) {\n" " b[i] = b[i+1];\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:17]: (error) Array 'b[7]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -3381,7 +3381,7 @@ class TestBufferOverrun : public TestFixture { "\n" "A::A() {\n" " memset(buf, 0, 10);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3392,7 +3392,7 @@ class TestBufferOverrun : public TestFixture { " const char *src = \"AAAAAAAAAAAAAAAAAAAAA\";\n" " for (size_t i = 0; i <= 4; i++)\n" " dst[i] = src[i];\n" - "} } }"); + "} } }\n"); ASSERT_EQUALS("[test.cpp:6:12]: (error) Array 'dst[4]' accessed at index 4, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -3404,7 +3404,7 @@ class TestBufferOverrun : public TestFixture { " for( int i = 0; i<6; ) {\n" " x += array[i];\n" " i++; }\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("error", "", errout_str()); // ticket #4096 @@ -3414,7 +3414,7 @@ class TestBufferOverrun : public TestFixture { " for( int i = 0; i<6; ) {\n" " x += array[i++];\n" " }\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("error", "", errout_str()); } @@ -3424,7 +3424,7 @@ class TestBufferOverrun : public TestFixture { " char inbuf[1000];\n" " char *f[10];\n" " split(inbuf, f, 10, \"\t\t\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3434,7 +3434,7 @@ class TestBufferOverrun : public TestFixture { "void main() {\n" "struct foobar x[5];\n" "abc(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3445,7 +3445,7 @@ class TestBufferOverrun : public TestFixture { "int main(){\n" " testChar tc1 = \"\";\n" " tc1[5]='a';\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3455,14 +3455,14 @@ class TestBufferOverrun : public TestFixture { check("struct S { int m[9]; };\n" "int f(S * s) {\n" " return s->m[sizeof(s->m)];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:16]: (error) Array 's->m[9]' accessed at index 36, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } void buffer_overrun_31() { check("void f(WhereInfo *pWInfo, int *aiCur) {\n" " memcpy(aiCur, pWInfo->aiCurOnePass, sizeof(int)*2);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3473,7 +3473,7 @@ class TestBufferOverrun : public TestFixture { " char dest[1] = \"a\";\n" " (void)strxfrm(dest,src,1);\n" " (void)strxfrm(dest,src,2);\n"// << - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:19]: (error) Buffer is accessed out of bounds: dest [bufferAccessOutOfBounds]\n", errout_str()); // destination size is too small check("void f(void) {\n" @@ -3482,7 +3482,7 @@ class TestBufferOverrun : public TestFixture { " (void)strxfrm(dest,src,1);\n" " (void)strxfrm(dest,src,2);\n" " (void)strxfrm(dest,src,3);\n" // << - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:19]: (error) Buffer is accessed out of bounds: dest [bufferAccessOutOfBounds]\n", errout_str()); // source size is too small check("void f(void) {\n" @@ -3491,7 +3491,7 @@ class TestBufferOverrun : public TestFixture { " (void)strxfrm(dest,src,1);\n" " (void)strxfrm(dest,src,2);\n" " (void)strxfrm(dest,src,3);\n" // << - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:24]: (error) Buffer is accessed out of bounds: src [bufferAccessOutOfBounds]\n", errout_str()); // source size is too small check("void f(void) {\n" @@ -3499,7 +3499,7 @@ class TestBufferOverrun : public TestFixture { " char dest[3] = \"abc\";\n" " (void)strxfrm(dest,src,1);\n" " (void)strxfrm(dest,src,2);\n" // << - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:24]: (error) Buffer is accessed out of bounds: src [bufferAccessOutOfBounds]\n", errout_str()); } @@ -3510,7 +3510,7 @@ class TestBufferOverrun : public TestFixture { " for (int j=0; j<20; j++)\n" " z[i] = 0;\n" " return z[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:12]: (error) Array 'z[16]' accessed at index 19, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -3633,12 +3633,12 @@ class TestBufferOverrun : public TestFixture { void buffer_overrun_errorpath() { setMultiline(); Settings s = settings0; - s.templateLocation = "{file}:{line}:note:{info}"; + s.templateLocation = "{file}:{line}:note:{info}\n"; check("void f() {\n" " char *p = malloc(10);\n" " memset(p, 0, 20);\n" - "}", s); + "}\n", s); ASSERT_EQUALS("[test.cpp:3:12]: error: Buffer is accessed out of bounds: p [bufferAccessOutOfBounds]\n" "[test.cpp:2:13]: note: Assign p, buffer with size 10\n" "[test.cpp:3:12]: note: Buffer overrun\n", errout_str()); @@ -3653,7 +3653,7 @@ class TestBufferOverrun : public TestFixture { "void f2() {\n" " char a[10];\n" " f1(a);" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // No false positive @@ -3665,7 +3665,7 @@ class TestBufferOverrun : public TestFixture { "void f2() {\n" " char a[10];\n" " f1(a);" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // No false negative @@ -3677,7 +3677,7 @@ class TestBufferOverrun : public TestFixture { "void f2() {\n" " char a[10];\n" " f1(a);" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:3]: (error) Array 'a[10]' accessed at index 100, which is out of bounds.\n", "", errout_str()); } @@ -3688,7 +3688,7 @@ class TestBufferOverrun : public TestFixture { "void g() {\n" " char a[2];\n" " f(a);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: warning: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\n" "[test.cpp:4:5]: note: Function 'f' is called\n" "[test.cpp:1:13]: note: Declaration of 1st function argument.\n" @@ -3699,7 +3699,7 @@ class TestBufferOverrun : public TestFixture { "void g() {\n" " float a[2][3];\n" " f(a);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: warning: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\n" "[test.cpp:4:5]: note: Function 'f' is called\n" "[test.cpp:1:14]: note: Declaration of 1st function argument.\n" @@ -3710,7 +3710,7 @@ class TestBufferOverrun : public TestFixture { "void g() {\n" " int a[2];\n" " f(a);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: warning: Buffer 'a' is too small, the function 'f' expects a bigger buffer in 1st argument [argumentSize]\n" "[test.cpp:4:5]: note: Function 'f' is called\n" "[test.cpp:1:12]: note: Declaration of 1st function argument.\n" @@ -3732,7 +3732,7 @@ class TestBufferOverrun : public TestFixture { "void foo() {\n" " unsigned char(* tree)[2048][4] = new unsigned char[256][2048][4];\n" " CreateLeafTex(tree);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int a[10]) {\n" // #10069 @@ -3760,7 +3760,7 @@ class TestBufferOverrun : public TestFixture { " memset(src, 'C', 99);\n" " src[99] = '\\0';\n" " strcat(data, src);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\n", "", errout_str()); check("void foo() {\n" @@ -3769,19 +3769,19 @@ class TestBufferOverrun : public TestFixture { " memset(src, 'C', 99);\n" " src[99] = '\\0';\n" " strcat(data, src);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char src[100]) {\n" " char * data = (char *)alloca(50);\n" " strcat(data, src);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\n", "", errout_str()); check("void foo(char src[100]) {\n" " char * data = (char *)alloca(100);\n" " strcat(data, src);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -3790,7 +3790,7 @@ class TestBufferOverrun : public TestFixture { " memset(src, 'C', 99);\n" " src[99] = '\\0';\n" " strcpy(data, src);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\n", "", errout_str()); check("void foo() {\n" @@ -3799,19 +3799,19 @@ class TestBufferOverrun : public TestFixture { " memset(src, 'C', 99);\n" " src[99] = '\\0';\n" " strcpy(data, src);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char src[100]) {\n" " char * data = (char *)alloca(50);\n" " strcpy(data, src);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\n", "", errout_str()); check("void foo(char src[100]) {\n" " char * data = (char *)alloca(100);\n" " strcpy(data, src);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3833,26 +3833,26 @@ class TestBufferOverrun : public TestFixture { check("void f() {\n" " u8 str[256];\n" " mystrcpy(str, \"abcd\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " u8 str[2];\n" " mystrcpy(str, \"abcd\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:12]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", errout_str()); // The same for structs, where the message comes from a different check check("void f() {\n" " struct { u8 str[256]; } ms;\n" " mystrcpy(ms.str, \"abcd\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " struct { u8 str[2]; } ms;\n" " mystrcpy(ms.str, \"abcd\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:16]: (error) Buffer is accessed out of bounds: ms.str [bufferAccessOutOfBounds]\n", errout_str()); } @@ -3860,31 +3860,31 @@ class TestBufferOverrun : public TestFixture { check("void f() {\n" " int i;\n" " memset(i, 0, 1000);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int i;\n" " memset(&i, 0, 1000);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10]: (error) Buffer is accessed out of bounds: &i [bufferAccessOutOfBounds]\n", errout_str()); check("void f() {\n" " int i[2];\n" " memset(&i, 0, 1000);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10]: (error) Buffer is accessed out of bounds: i [bufferAccessOutOfBounds]\n", errout_str()); check("void f() {\n" " int i;\n" " memset(&i, 0, sizeof(i));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int i[10];\n" " memset(&i[1], 0, 1000);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10]: (error) Buffer is accessed out of bounds: &i[1] [bufferAccessOutOfBounds]\n", errout_str()); check("struct S { int x; };\n" // #8616 @@ -3913,7 +3913,7 @@ class TestBufferOverrun : public TestFixture { " const char *x = s;\n" " if (cond) x = \"abcde\";\n" " return x[20];\n" // <- array index out of bounds when x is "abcde" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:11]: (error) Array 'x[6]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -3923,40 +3923,40 @@ class TestBufferOverrun : public TestFixture { check("void f() {\n" " char a[10];\n" " char *p = a + 100;\n" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("[test.cpp:3:17]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds. [pointerOutOfBounds]\n", errout_str()); check("char *f() {\n" " char a[10];\n" " return a + 100;\n" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("[test.cpp:3:14]: (portability) Undefined behaviour, pointer arithmetic 'a+100' is out of bounds. [pointerOutOfBounds]\n", errout_str()); check("void f(int i) {\n" " char x[10];\n" " if (i == 123) {}\n" " dostuff(x+i);\n" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:4:14]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x+i' is out of bounds. [pointerOutOfBoundsCond]\n", errout_str()); check("void f(int i) {\n" " char x[10];\n" " if (i == -1) {}\n" " dostuff(x+i);\n" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:4:14]: (portability) Undefined behaviour, when 'i' is -1 the pointer arithmetic 'x+i' is out of bounds. [pointerOutOfBoundsCond]\n", errout_str()); check("void f() {\n" // #6350 - fp when there is cast of buffer " wchar_t buf[64];\n" " p = (unsigned char *) buf + sizeof (buf);\n" - "}", settings0_p, false); + "}\n", settings0_p, false); ASSERT_EQUALS("", errout_str()); check("int f() {\n" " const char d[] = \"0123456789\";\n" " char *cp = d + 3;\n" " return cp - d;\n" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("", errout_str()); } @@ -3965,7 +3965,7 @@ class TestBufferOverrun : public TestFixture { " char *p = malloc(10);\n" " p += 100;\n" " free(p);" - "}", settings0_p); + "}\n", settings0_p); TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'p+100' is out of bounds.\n", "", errout_str()); check("void f() {\n" @@ -3973,7 +3973,7 @@ class TestBufferOverrun : public TestFixture { " p += 10;\n" " *p = 0;\n" " free(p);" - "}", settings0_p); + "}\n", settings0_p); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) p is out of bounds.\n", "", errout_str()); check("void f() {\n" @@ -3982,7 +3982,7 @@ class TestBufferOverrun : public TestFixture { " p -= 10;\n" " *p = 0;\n" " free(p);" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -3991,7 +3991,7 @@ class TestBufferOverrun : public TestFixture { " p = p - 1;\n" " *p = 0;\n" " free(p);" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("", errout_str()); } @@ -3999,7 +3999,7 @@ class TestBufferOverrun : public TestFixture { check("struct S { int a[10]; };\n" "void f(struct S *s) {\n" " int *p = s->a + 100;\n" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("[test.cpp:3:19]: (portability) Undefined behaviour, pointer arithmetic 's->a+100' is out of bounds. [pointerOutOfBounds]\n", errout_str()); check("template class Vector\n" @@ -4022,22 +4022,22 @@ class TestBufferOverrun : public TestFixture { void pointer_out_of_bounds_4() { check("const char* f() {\n" " g(\"Hello\" + 6);\n" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("", errout_str()); check("const char* f() {\n" " g(\"Hello\" + 7);\n" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("[test.cpp:2:15]: (portability) Undefined behaviour, pointer arithmetic '\"Hello\"+7' is out of bounds. [pointerOutOfBounds]\n", errout_str()); check("const char16_t* f() {\n" " g(u\"Hello\" + 6);\n" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("", errout_str()); check("const char16_t* f() {\n" " g(u\"Hello\" + 7);\n" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("[test.cpp:2:16]: (portability) Undefined behaviour, pointer arithmetic 'u\"Hello\"+7' is out of bounds. [pointerOutOfBounds]\n", errout_str()); check("void f() {\n" // #4647 @@ -4084,26 +4084,26 @@ class TestBufferOverrun : public TestFixture { check("char *f() {\n" " char x[10];\n" " return x-1;\n" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("[test.cpp:3:13]: (portability) Undefined behaviour, pointer arithmetic 'x-1' is out of bounds. [pointerOutOfBounds]\n", errout_str()); check("void f(int i) {\n" " char x[10];\n" " if (i == 123) {}\n" " dostuff(x-i);\n" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:4:14]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x-i' is out of bounds. [pointerOutOfBoundsCond]\n", errout_str()); check("void f(int i) {\n" " char x[10];\n" " if (i == -20) {}\n" " dostuff(x-i);\n" - "}", settings0_p); + "}\n", settings0_p); TODO_ASSERT_EQUALS("[test.cpp:4]: (portability) Undefined behaviour, when 'i' is -20 the pointer arithmetic 'x-i' is out of bounds.\n", "", errout_str()); check("void f(const char *x[10]) {\n" " return x-4;\n" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("", errout_str()); } @@ -4113,7 +4113,7 @@ class TestBufferOverrun : public TestFixture { " struct Foo x = {0};\n" " strcat(x.a, \"aa\");\n" " strcat(x.a, \"aa\");\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds.\n", "", errout_str()); } @@ -4126,7 +4126,7 @@ class TestBufferOverrun : public TestFixture { " char str[50];\n" " str[30] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -4134,7 +4134,7 @@ class TestBufferOverrun : public TestFixture { check("struct foo {\n" " void bar() { return; }\n" " type<> member[1];\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4144,7 +4144,7 @@ class TestBufferOverrun : public TestFixture { "void foo()\n" "{\n" " str[3] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:8]: (error) Array 'str[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -4153,7 +4153,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " char *s; s = new char[10];\n" " s[10] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // ticket #1670 - false negative when using return @@ -4161,7 +4161,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " int *s; s = new int[10];\n" " return s[10];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:13]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("struct Fred { char c[10]; };\n" @@ -4169,12 +4169,12 @@ class TestBufferOverrun : public TestFixture { "{\n" " Fred *f; f = new Fred;\n" " return f->c[10];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:16]: (error) Array 'f->c[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("static const size_t MAX_SIZE = UNAVAILABLE_TO_CPPCHECK;\n" "struct Thing { char data[MAX_SIZE]; };\n" - "char f4(const Thing& t) { return !t.data[0]; }"); + "char f4(const Thing& t) { return !t.data[0]; }\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -4184,7 +4184,7 @@ class TestBufferOverrun : public TestFixture { " buf = new char[9];\n" " buf[8] = 0;\n" " delete [] buf;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -4194,7 +4194,7 @@ class TestBufferOverrun : public TestFixture { " buf = new char[9];\n" " buf[9] = 0;\n" " delete [] buf;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:6]: (error) Array 'buf[9]' accessed at index 9, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void foo()\n" @@ -4202,7 +4202,7 @@ class TestBufferOverrun : public TestFixture { " enum E { Size = 10 };\n" " char *s; s = new char[Size];\n" " s[Size] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void foo()\n" @@ -4210,7 +4210,7 @@ class TestBufferOverrun : public TestFixture { " enum E { ZERO };\n" " E *e; e = new E[10];\n" " e[10] = ZERO;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:6]: (error) Array 'e[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -4220,14 +4220,14 @@ class TestBufferOverrun : public TestFixture { "{\n" " char *s; s = (char *)malloc(10);\n" " s[10] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // ticket #842 check("void f() {\n" " int *tab4 = (int *)malloc(20 * sizeof(int));\n" " tab4[20] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // ticket #1478 @@ -4236,7 +4236,7 @@ class TestBufferOverrun : public TestFixture { " free(p);\n" " p = (char *)malloc(10);\n" " p[10] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:6]: (error) Array 'p[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); // ticket #1134 @@ -4244,7 +4244,7 @@ class TestBufferOverrun : public TestFixture { " int *x, i;\n" " x = (int *)malloc(10 * sizeof(int));\n" " x[10] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 'x[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" @@ -4254,7 +4254,7 @@ class TestBufferOverrun : public TestFixture { " tab4 = malloc(21 * sizeof(int));\n" " tab4[20] = 0;\n" " free(tab4);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -4263,49 +4263,49 @@ class TestBufferOverrun : public TestFixture { " tab4 = realloc(tab4,21 * sizeof(int));\n" " tab4[20] = 0;\n" " free(tab4);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " enum E { Size = 20 };\n" " E *tab4 = (E *)malloc(Size * 4);\n" " tab4[Size] = Size;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " enum E { Size = 20 };\n" " E *tab4 = (E *)malloc(4 * Size);\n" " tab4[Size] = Size;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " enum E { ZERO };\n" " E *tab4 = (E *)malloc(20 * sizeof(E));\n" " tab4[20] = ZERO;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" // #8721 " unsigned char **cache = malloc(32);\n" " cache[i] = malloc(65536);\n" " cache[i][0xFFFF] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int **a = malloc(2 * sizeof(int*));\n" " for (int i = 0; i < 3; i++)\n" " a[i] = NULL;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f() {\n" " int **a = new int*[2];\n" " for (int i = 0; i < 3; i++)\n" " a[i] = NULL;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void f(const uint8_t* a) {\n" // 10421 @@ -4324,21 +4324,21 @@ class TestBufferOverrun : public TestFixture { "{\n" " const char *s = \"123\";\n" " s[10] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 's[4]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void foo()\n" "{\n" " char *s; s = \"\";\n" " s[10] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 's[1]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); check("void foo() {\n" " const char *s = \"\";\n" " s = y();\n" " s[10] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" // #7718 @@ -4346,7 +4346,7 @@ class TestBufferOverrun : public TestFixture { " std::string s = \"123\";\n" " s.resize(100);\n" " s[10] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -4356,7 +4356,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " char *s = (char *)alloca(10);\n" " s[10] = 0;\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 's[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", "", errout_str()); } /* @@ -4453,13 +4453,13 @@ class TestBufferOverrun : public TestFixture { check("void f() {\n" " char c[10];\n" " mymemset(c, 0, 10);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " char c[10];\n" " mymemset(c, 0, 11);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:14]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\n", errout_str()); check("struct S {\n" @@ -4468,13 +4468,13 @@ class TestBufferOverrun : public TestFixture { "void f() {\n" " S s;\n" " mymemset(s.a, 0, 10);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:6:15]: (error) Buffer is accessed out of bounds: s.a [bufferAccessOutOfBounds]\n", errout_str()); check("void foo() {\n" " char s[10];\n" " mymemset(s, 0, '*');\n" - "}", settings); + "}\n", settings); TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) The size argument is given as a char constant.\n" "[test.cpp:3:14]: (error) Buffer is accessed out of bounds: s [bufferAccessOutOfBounds]\n", "[test.cpp:3:14]: (error) Buffer is accessed out of bounds: s [bufferAccessOutOfBounds]\n", errout_str()); @@ -4482,65 +4482,65 @@ class TestBufferOverrun : public TestFixture { check("void f(void) {\n" " char a[10];\n" " mymemset(a+5, 0, 10);\n" - "}", settings); + "}\n", settings); TODO_ASSERT_EQUALS("[test.cpp:3:13]: (error) Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\n", "", errout_str()); // Ticket #909 check("void f(void) {\n" " char str[] = \"abcd\";\n" " mymemset(str, 0, 6);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:14]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", errout_str()); check("void f(void) {\n" " char str[] = \"abcd\";\n" " mymemset(str, 0, 5);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); check("void f(void) {\n" " wchar_t str[] = L\"abcd\";\n" " mymemset(str, 0, 21);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:14]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", errout_str()); check("void f(void) {\n" " wchar_t str[] = L\"abcd\";\n" " mymemset(str, 0, 20);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); // ticket #1659 - overflowing variable when using memcpy check("void f(void) {\n" " char c;\n" " mymemset(&c, 0, 4);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:12]: (error) Buffer is accessed out of bounds: &c [bufferAccessOutOfBounds]\n", errout_str()); // ticket #2121 - buffer access out of bounds when using uint32_t check("void f(void) {\n" " unknown_type_t buf[4];\n" " mymemset(buf, 0, 100);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); // #3124 - multidimensional array check("int main() {\n" " char b[5][6];\n" " mymemset(b, 0, 5 * 6);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); check("int main() {\n" " char b[5][6];\n" " mymemset(b, 0, 6 * 6);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:14]: (error) Buffer is accessed out of bounds: b [bufferAccessOutOfBounds]\n", errout_str()); check("int main() {\n" " char b[5][6];\n" " mymemset(b, 0, 31);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:14]: (error) Buffer is accessed out of bounds: b [bufferAccessOutOfBounds]\n", errout_str()); // #4968 - not standard function @@ -4549,26 +4549,26 @@ class TestBufferOverrun : public TestFixture { " foo.mymemset(str, 0, 100);\n" " foo::mymemset(str, 0, 100);\n" " std::mymemset(str, 0, 100);\n" - "}", settings); + "}\n", settings); TODO_ASSERT_EQUALS("[test.cpp:5:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", "", errout_str()); // #5257 - check strings check("void f() {\n" " mymemset(\"abc\", 0, 20);\n" - "}", settings); + "}\n", settings); TODO_ASSERT_EQUALS("[test.cpp:2]: (error) Buffer is accessed out of bounds.\n", "", errout_str()); check("void f() {\n" " mymemset(temp, \"abc\", 4);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); check("void f() {\n" // #6816 - fp when array has known string value " char c[10] = \"c\";\n" " mymemset(c, 0, 10);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); } @@ -4590,43 +4590,43 @@ class TestBufferOverrun : public TestFixture { check("void f() {\n" " char c[7];\n" " mystrncpy(c, \"hello\", 7);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " char c[6];\n" " mystrncpy(c,\"hello\",6);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " char c[5];\n" " mystrncpy(c,\"hello\",6);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:12]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\n", errout_str()); check("void f() {\n" " char c[6];\n" " mystrncpy(c,\"hello!\",7);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:15]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\n", errout_str()); check("void f(unsigned int addr) {\n" " memset((void *)addr, 0, 1000);\n" - "}", settings0); // TODO: use settings? + "}\n", settings0); // TODO: use settings? ASSERT_EQUALS("", errout_str()); check("struct AB { char a[10]; };\n" "void foo(AB *ab) {\n" " mystrncpy(x, ab->a, 100);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); check("void a(char *p) { mystrncpy(p,\"hello world!\",10); }\n" // #3168 "void b() {\n" " char buf[5];\n" " a(buf);" - "}", settings); + "}\n", settings); TODO_ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (error) Buffer is accessed out of bounds: buf\n", "", errout_str()); @@ -4652,13 +4652,13 @@ class TestBufferOverrun : public TestFixture { check("void f() {\n" " char str[3];\n" " mysprintf(str, \"test\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", errout_str()); check("void f() {\n" " char str[5];\n" " mysprintf(str, \"%s\", \"abcde\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", errout_str()); check("int getnumber();\n" @@ -4666,51 +4666,51 @@ class TestBufferOverrun : public TestFixture { "{\n" " char str[5];\n" " mysprintf(str, \"%d: %s\", getnumber(), \"abcde\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:5:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", errout_str()); check("void f() {\n" " char str[5];\n" " mysprintf(str, \"test%s\", \"\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " char *str = new char[5];\n" " mysprintf(str, \"abcde\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:15]: (error) Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]\n", errout_str()); check("void f(int condition) {\n" " char str[5];\n" " mysprintf(str, \"test%s\", condition ? \"12\" : \"34\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); check("void f(int condition) {\n" " char str[5];\n" " mysprintf(str, \"test%s\", condition ? \"12\" : \"345\");\n" - "}", settings); + "}\n", settings); TODO_ASSERT_EQUALS("error", "", errout_str()); check("struct Foo { char a[1]; };\n" "void f() {\n" " struct Foo x;\n" " mysprintf(x.a, \"aa\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:4:14]: (error) Buffer is accessed out of bounds: x.a [bufferAccessOutOfBounds]\n", errout_str()); // ticket #900 check("void f() {\n" " char *a = new char(30);\n" " mysprintf(a, \"a\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:13]: (error) Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\n", errout_str()); check("void f(char value) {\n" " char *a = new char(value);\n" " mysprintf(a, \"a\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:13]: (error) Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\n", errout_str()); // This is out of bounds if 'sizeof(ABC)' is 1 (No padding) @@ -4718,21 +4718,21 @@ class TestBufferOverrun : public TestFixture { "void f() {\n" " struct Foo *x = malloc(sizeof(Foo));\n" " mysprintf(x->a, \"aa\");\n" - "}", settings); + "}\n", settings); TODO_ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Buffer is accessed out of bounds: x.a\n", "", errout_str()); check("struct Foo { char a[1]; };\n" "void f() {\n" " struct Foo *x = malloc(sizeof(Foo) + 10);\n" " mysprintf(x->a, \"aa\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); check("struct Foo { char a[1]; };\n" "void f() {\n" " struct Foo x;\n" " mysprintf(x.a, \"aa\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:4:14]: (error) Buffer is accessed out of bounds: x.a [bufferAccessOutOfBounds]\n", errout_str()); check("struct Foo {\n" // #6668 - unknown size @@ -4741,7 +4741,7 @@ class TestBufferOverrun : public TestFixture { "};" "void Foo::f() {\n" " mysprintf(a, \"abcd\");\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); check("void f() {\n" // #901 @@ -4797,13 +4797,13 @@ class TestBufferOverrun : public TestFixture { check("void f() {\n" " char c[5];\n" " myfread(c, 1, 5, stdin);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " char c[5];\n" " myfread(c, 1, 6, stdin);\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:13]: (error) Buffer is accessed out of bounds: c [bufferAccessOutOfBounds]\n", errout_str()); } @@ -4813,7 +4813,7 @@ class TestBufferOverrun : public TestFixture { check("void f()\n" "{\n" " UnknownType *a = malloc(4);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } // extracttests.disable @@ -4825,26 +4825,26 @@ class TestBufferOverrun : public TestFixture { " baz[99] = 0;\n" " strncpy(baz, bar, 100);\n" " baz[99] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo ( char *bar ) {\n" " char baz[100];\n" " strncpy(baz, bar, 100);\n" " baz[99] = '\\0';\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo ( char *bar ) {\n" " char baz[100];\n" " strncpy(baz, bar, 100);\n" " baz[x+1] = '\\0';\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Test with invalid code that there is no segfault check("char baz[100];\n" - "strncpy(baz, \"var\", 100)"); + "strncpy(baz, \"var\", 100)\n"); ASSERT_EQUALS("", errout_str()); // Test that there are no duplicate error messages @@ -4853,7 +4853,7 @@ class TestBufferOverrun : public TestFixture { " strncpy(baz, bar, 100);\n" " foo(baz);\n" " foo(baz);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\n", errout_str()); } @@ -4863,7 +4863,7 @@ class TestBufferOverrun : public TestFixture { " strncpy(baz, bar, 100);\n" " bar[99] = 0;\n" " return strdup(baz);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\n", errout_str()); } @@ -4886,13 +4886,13 @@ class TestBufferOverrun : public TestFixture { check("void bar() {\n" " char buf[4];\n" " strncpy(buf, \"ab\", 4);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void bar() {\n" " char buf[4];\n" " strncpy(buf, \"abcde\", 4);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning, inconclusive) The buffer 'buf' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\n", errout_str()); } @@ -4918,13 +4918,13 @@ class TestBufferOverrun : public TestFixture { check("void foo() {\n" " char c[6];\n" " strncpy(&c, \"hello!\", 6);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\n", errout_str()); check("void foo() {\n" " char c[6];\n" " strncpy(&c, \"hello\\0\", 6);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -4952,7 +4952,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " char a[10];\n" " f2(a);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -4968,7 +4968,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " struct A *str;\n" " str = malloc(4);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -4980,12 +4980,12 @@ class TestBufferOverrun : public TestFixture { "void b() {\n" " char arr[64];\n" " a(arr);\n" - "}"); + "}\n"); } void crash3() { check("struct b { unknown v[0]; };\n" - "void d() { struct b *f; f = malloc(108); }"); + "void d() { struct b *f; f = malloc(108); }\n"); } void crash4() { // #8679 @@ -4993,13 +4993,13 @@ class TestBufferOverrun : public TestFixture { "int main() { " " thread_local_var = malloc(1337); " " return 0; " - "}"); + "}\n"); check("thread_local void *thread_local_var; " "int main() { " " thread_local_var = malloc(1337); " " return 0; " - "}"); + "}\n"); } void crash5() { // 8644 - token has varId() but variable() is null @@ -5007,19 +5007,19 @@ class TestBufferOverrun : public TestFixture { " void b(char **dst) {\n" " *dst = malloc(50);\n" " }\n" - "}"); + "}\n"); } void crash6() { check("void start(char* name) {\n" "char snapname[64] = { 0 };\n" "strncpy(snapname, \"snapshot\", arrayLength(snapname));\n" - "}"); + "}\n"); } void crash7() { // 9073 - [ has no astParent check("char x[10];\n" - "void f() { x[10]; }"); + "void f() { x[10]; }\n"); } void insecureCmdLineArgs() { @@ -5033,7 +5033,7 @@ class TestBufferOverrun : public TestFixture { " free(p);\n" " }\n" " return 0;\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(int argc, char *argv[])\n" @@ -5046,112 +5046,112 @@ class TestBufferOverrun : public TestFixture { " free(p);\n" " }\n" " return 0;\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(const int argc, char* argv[])\n" "{\n" " char prog[10];\n" " strcpy(prog, argv[0]);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(int argc, const char* argv[])\n" "{\n" " char prog[10];\n" " strcpy(prog, argv[0]);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(const int argc, const char* argv[])\n" "{\n" " char prog[10];\n" " strcpy(prog, argv[0]);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(int argc, char* argv[])\n" "{\n" " char prog[10] = {'\\0'};\n" " strcat(prog, argv[0]);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(int argc, char **argv, char **envp)\n" "{\n" " char prog[10];\n" " strcpy(prog, argv[0]);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(int argc, const char *const *const argv, char **envp)\n" "{\n" " char prog[10];\n" " strcpy(prog, argv[0]);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(const int argc, const char *const *const argv, const char *const *const envp)\n" "{\n" " char prog[10];\n" " strcpy(prog, argv[0]);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(int argc, char **argv, char **envp)\n" "{\n" " char prog[10] = {'\\0'};\n" " strcat(prog, argv[0]);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(const int argc, const char **argv, char **envp)\n" "{\n" " char prog[10] = {'\\0'};\n" " strcat(prog, argv[0]);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(int argc, const char **argv, char **envp)\n" "{\n" " char prog[10] = {'\\0'};\n" " strcat(prog, argv[0]);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(const int argc, char **argv, char **envp)\n" "{\n" " char prog[10] = {'\\0'};\n" " strcat(prog, argv[0]);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(int argc, char **options)\n" "{\n" " char prog[10];\n" " strcpy(prog, options[0]);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(int argc, char **options)\n" "{\n" " char prog[10] = {'\\0'};\n" " strcat(prog, options[0]);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(int argc, char **options)\n" "{\n" " char prog[10];\n" " strcpy(prog, *options);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(int argc, char **options)\n" "{\n" " char prog[10];\n" " strcpy(prog+3, *options);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); check("int main(int argc, char **argv, char **envp)\n" @@ -5159,7 +5159,7 @@ class TestBufferOverrun : public TestFixture { " char prog[10];\n" " if (strlen(argv[0]) < 10)\n" " strcpy(prog, argv[0]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int main(int argc, char **argv, char **envp)\n" @@ -5167,7 +5167,7 @@ class TestBufferOverrun : public TestFixture { " char prog[10] = {'\\0'};\n" " if (10 > strlen(argv[0]))\n" " strcat(prog, argv[0]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int main(int argc, char **argv, char **envp)\n" @@ -5175,7 +5175,7 @@ class TestBufferOverrun : public TestFixture { " char prog[10];\n" " argv[0][0] = '\\0';\n" " strcpy(prog, argv[0]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #5835 @@ -5183,18 +5183,18 @@ class TestBufferOverrun : public TestFixture { " char prog[10];\n" " strcpy(prog, argv[0]);\n" " strcpy(prog, argv[0]);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer overrun possible for long command line arguments.\n" "[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout_str()); // #7964 check("int main(int argc, char *argv[]) {\n" " char *strcpy();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int main(int argc, char *argv[]) {\n" " char *strcat();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -5202,33 +5202,33 @@ class TestBufferOverrun : public TestFixture { check("void f(char *a) {\n" " char *b = new char[strlen(a)];\n" " strcpy(b, a);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout_str()); check("void f(char *a) {\n" " char *b = new char[strlen(a) + 1];\n" " strcpy(b, a);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(char *a) {\n" " char *b = new char[strlen(a)];\n" " a[0] = '\\0';\n" " strcpy(b, a);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(char *a) {\n" " char *b = (char *)malloc(strlen(a));\n" " b = realloc(b, 10000);\n" " strcpy(b, a);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(char *a) {\n" " char *b = (char *)malloc(strlen(a));\n" " strcpy(b, a);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout_str()); check("void f(char *a) {\n" @@ -5236,31 +5236,31 @@ class TestBufferOverrun : public TestFixture { " {\n" " strcpy(b, a);\n" " }\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds.\n", "", errout_str()); check("void f(char *a) {\n" " char *b = (char *)malloc(strlen(a) + 1);\n" " strcpy(b, a);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(char *a, char *c) {\n" " char *b = (char *)realloc(c, strlen(a));\n" " strcpy(b, a);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout_str()); check("void f(char *a, char *c) {\n" " char *b = (char *)realloc(c, strlen(a) + 1);\n" " strcpy(b, a);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(char *a) {\n" " char *b = (char *)malloc(strlen(a));\n" " strcpy(b, a);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout_str()); } @@ -5274,7 +5274,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " X x;\n" " x.buf[10] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class A {\n" @@ -5286,7 +5286,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " A::X x;\n" " x.buf[10] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:10]: (error) Array 'x.buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str()); } @@ -5305,68 +5305,68 @@ class TestBufferOverrun : public TestFixture { check("void f(const char s[]) {\n" " if (s[i] == 'x' && i < y) {\n" " }" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // No message because i is unknown and thus gets no varid. Avoid an internalError here. check("void f(const char s[], int i) {\n" " if (s[i] == 'x' && i < y) {\n" " }" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\n", errout_str()); check("void f(const char s[]) {\n" " for (int i = 0; s[i] == 'x' && i < y; ++i) {\n" " }" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:22]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\n", errout_str()); check("void f(const int a[], unsigned i) {\n" " if((a[i] < 2) && (i <= 42)) {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\n", errout_str()); check("void f(const int a[], unsigned i) {\n" " if((a[i] < 2) && (42 >= i)) {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\n", errout_str()); // extracttests.start: int elen; check("void f(char* e, int y) {\n" " if (e[y] == '/' && elen > y + 1 && e[y + 1] == '?') {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // extracttests.start: int foo(int); int func(int); check("void f(const int a[], unsigned i) {\n" " if(a[i] < func(i) && i <= 42) {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\n", errout_str()); check("void f(const int a[], unsigned i) {\n" " if (i <= 42 && a[i] < func(i)) {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(const int a[], unsigned i) {\n" " if (foo(a[i] + 3) < func(i) && i <= 42) {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (style) Array index 'i' is used before limits check. [arrayIndexThenCheck]\n", errout_str()); check("void f(int i) {\n" // sizeof " sizeof(a)/sizeof(a[i]) && i < 10;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // extracttests.start: extern int buf[]; check("void f(int i) {\n" // ?: " if ((i < 10 ? buf[i] : 1) && (i < 5 ? buf[i] : 5)){}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -5389,19 +5389,19 @@ class TestBufferOverrun : public TestFixture { check("void f() {\n" " char c[6];\n" " strncpy(c,\"hello!\",6);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to strncpy(). [terminateStrncpy]\n", errout_str()); check("void f() {\n" " char c[6];\n" " memcpy(c,\"hello!\",6);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to memcpy().\n", "", errout_str()); check("void f() {\n" " char c[6];\n" " memmove(c,\"hello!\",6);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to memmove().\n", "", errout_str()); } @@ -5411,7 +5411,7 @@ class TestBufferOverrun : public TestFixture { " int *a;\n" " a = new int[-1];\n" " delete [] a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\n", errout_str()); check("void f()\n" @@ -5419,7 +5419,7 @@ class TestBufferOverrun : public TestFixture { " int *a;\n" " a = (int *)malloc( -10 );\n" " free(a);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\n", "", errout_str()); check("void f()\n" @@ -5427,14 +5427,14 @@ class TestBufferOverrun : public TestFixture { " int *a;\n" " a = (int *)malloc( -10);\n" " free(a);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\n", "", errout_str()); check("void f()\n" "{\n" " int *a;\n" " a = (int *)alloca( -10 );\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4:8]: (error) Memory allocation size is negative. [negativeMemoryAllocationSize]\n", "", errout_str()); check("int* f(int n) {\n" // #11145 @@ -5451,14 +5451,14 @@ class TestBufferOverrun : public TestFixture { check("void f(int sz) {\n" // #1760 - VLA " int a[sz];\n" "}\n" - "void x() { f(-100); }"); + "void x() { f(-100); }\n"); ASSERT_EQUALS("[test.cpp:2:8]: (error) Declaration of array 'a' with negative size is undefined behaviour [negativeArraySize]\n", errout_str()); // don't warn for constant sizes -> this is a compiler error so this is used for static assertions for instance check("int x, y;\n" "int a[-1];\n" "int b[x?1:-1];\n" - "int c[x?y:-1];"); + "int c[x?y:-1];\n"); ASSERT_EQUALS("", errout_str()); } @@ -5466,7 +5466,7 @@ class TestBufferOverrun : public TestFixture { check("void f() {\n" " char arr[10];\n" " char *p = arr + 20;\n" - "}", settings0_p); + "}\n", settings0_p); ASSERT_EQUALS("[test.cpp:3:19]: (portability) Undefined behaviour, pointer arithmetic 'arr+20' is out of bounds. [pointerOutOfBounds]\n", errout_str()); check("char(*g())[1];\n" // #7950 @@ -5506,7 +5506,7 @@ class TestBufferOverrun : public TestFixture { "int main() {\n" " char *s = malloc(4);\n" " dostuff(s);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:11] -> [test.cpp:7:10] -> [test.cpp:2:3]: (error) Array index out of bounds; buffer 'p' is accessed at offset -3. [ctuArrayIndex]\n", errout_str()); ctu("void dostuff(char *p) {\n" @@ -5516,7 +5516,7 @@ class TestBufferOverrun : public TestFixture { "int main() {\n" " char *s = malloc(4);\n" " dostuff(s);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:11] -> [test.cpp:7:10] -> [test.cpp:2:3]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 4. [ctuArrayIndex]\n", errout_str()); ctu("void f(int* p) {\n" // #10415 @@ -5548,7 +5548,7 @@ class TestBufferOverrun : public TestFixture { "int main() {\n" " char str[4];\n" " dostuff(str);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:10] -> [test.cpp:2:5]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 10. [ctuArrayIndex]\n", errout_str()); ctu("static void memclr( char *data )\n" @@ -5560,7 +5560,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " char str[5];\n" " memclr( str );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:11] -> [test.cpp:3:5]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10. [ctuArrayIndex]\n", errout_str()); ctu("static void memclr( int i, char *data )\n" @@ -5572,7 +5572,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " char str[5];\n" " memclr( 0, str );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:11] -> [test.cpp:3:5]: (error) Array index out of bounds; 'data' buffer size is 5 and it is accessed at offset 10. [ctuArrayIndex]\n", errout_str()); ctu("static void memclr( int i, char *data )\n" @@ -5584,7 +5584,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " char str[5];\n" " memclr( 10, str );\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (possible error) Array index out of bounds.\n", "", errout_str()); @@ -5599,7 +5599,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " char str[5];\n" " memclr( str, 5 );\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #2097 @@ -5613,7 +5613,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " int p[3];\n" " foo(p+1);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9112 @@ -5626,7 +5626,7 @@ class TestBufferOverrun : public TestFixture { "{\n" " u8 macstrbuf[17] = { 0 };\n" " get_mac_address(macstrbuf);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9788 @@ -5683,7 +5683,7 @@ class TestBufferOverrun : public TestFixture { "int main() {\n" " int x = 4;\n" " dostuff(&x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:10] -> [test.cpp:2:5]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 40. [ctuArrayIndex]\n", errout_str()); } @@ -5692,7 +5692,7 @@ class TestBufferOverrun : public TestFixture { "int main() {\n" " int x[3];\n" " dostuff(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10] -> [test.cpp:1:28]: (error) Pointer arithmetic overflow; 'p' buffer size is 12 [ctuPointerArith]\n", errout_str()); ctu("void f(const char *p) {\n" // #11361 @@ -5711,7 +5711,7 @@ class TestBufferOverrun : public TestFixture { "void f() {\n" " char a[10] = {};\n" " g(a);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: error: Pointer arithmetic overflow; 'p' buffer size is 10 [ctuPointerArith]\n" "[test.cpp:6:6]: note: Calling function g, 1st argument is accessed out of bounds\n" "[test.cpp:2:12]: note: Using argument p\n", @@ -5722,7 +5722,7 @@ class TestBufferOverrun : public TestFixture { check("int f() {\n" " int i;\n" " return (&i)[1];\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:13] -> [test.cpp:3:16]: (error) The address of variable 'i' is accessed at non-zero index. [objectIndex]\n", errout_str()); @@ -5730,7 +5730,7 @@ class TestBufferOverrun : public TestFixture { check("int f(int j) {\n" " int i;\n" " return (&i)[j];\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:13] -> [test.cpp:3:16]: (warning) The address of variable 'i' might be accessed at non-zero index. [objectIndex]\n", errout_str()); @@ -5738,34 +5738,34 @@ class TestBufferOverrun : public TestFixture { check("int f() {\n" " int i;\n" " return (&i)[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(int * i) {\n" " return i[1];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(std::vector i) {\n" " return i[1];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(std::vector i) {\n" " return i.data()[1];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int* f(std::vector& i) {\n" " return &(i[1]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { int i; int j; };\n" "int f() {\n" " A x;\n" " return (&x.i)[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { int i; int j; };\n" @@ -5773,7 +5773,7 @@ class TestBufferOverrun : public TestFixture { " A x;\n" " int * i = &x.i;\n" " return i[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -5781,7 +5781,7 @@ class TestBufferOverrun : public TestFixture { " std::map m;\n" " m[0] = &x;\n" " m[1] = &x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f() {\n" @@ -5789,7 +5789,7 @@ class TestBufferOverrun : public TestFixture { " std::map m;\n" " m[0] = &x;\n" " return m[0][1];\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:10] -> [test.cpp:5:14]: (error) The address of variable 'x' is accessed at non-zero index. [objectIndex]\n", errout_str()); @@ -5799,7 +5799,7 @@ class TestBufferOverrun : public TestFixture { " std::map m;\n" " m[0] = &x;\n" " return m[0][1];\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:10] -> [test.cpp:5:14]: (error) The address of variable 'x' is accessed at non-zero index. [objectIndex]\n", errout_str()); @@ -5810,7 +5810,7 @@ class TestBufferOverrun : public TestFixture { " m[0] = &x;\n" " m[1] = y;\n" " return m[1][1];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void print(char** test);\n" @@ -5880,7 +5880,7 @@ class TestBufferOverrun : public TestFixture { "void h() {\n" " const uint8_t u = 4;\n" " f(&u, N);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("uint32_t f(uint32_t u) {\n" // #10154 @@ -5974,7 +5974,7 @@ class TestBufferOverrun : public TestFixture { "if (pipe(pipefd) == -1) {\n" " return;\n" " }\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:10]: (error) Buffer is accessed out of bounds: pipefd [bufferAccessOutOfBounds]\n", errout_str()); check("void f(){\n" @@ -5982,7 +5982,7 @@ class TestBufferOverrun : public TestFixture { "if (pipe(pipefd) == -1) {\n" " return;\n" " }\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); check("void f(){\n" @@ -5990,7 +5990,7 @@ class TestBufferOverrun : public TestFixture { "if (pipe((int*)pipefd) == -1) {\n" " return;\n" " }\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("[test.cpp:3:10]: (error) Buffer is accessed out of bounds: (int*)pipefd [bufferAccessOutOfBounds]\n", errout_str()); check("void f(){\n" @@ -5998,7 +5998,7 @@ class TestBufferOverrun : public TestFixture { "if (pipe((int*)pipefd) == -1) {\n" " return;\n" " }\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); } }; diff --git a/test/testcharvar.cpp b/test/testcharvar.cpp index 7d4a17489fc..0c9c8dd4b5b 100644 --- a/test/testcharvar.cpp +++ b/test/testcharvar.cpp @@ -57,7 +57,7 @@ class TestCharVar : public TestFixture { "{\n" " unsigned char ch = 0x80;\n" " buf[ch] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int buf[256];\n" @@ -65,7 +65,7 @@ class TestCharVar : public TestFixture { "{\n" " char ch = 0x80;\n" " buf[ch] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5]: (portability) 'char' type used as array index. [unknownSignCharArrayIndex]\n", errout_str()); check("int buf[256];\n" @@ -73,7 +73,7 @@ class TestCharVar : public TestFixture { "{\n" " char ch = 0;\n" " buf[ch] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int buf[256];\n" @@ -81,7 +81,7 @@ class TestCharVar : public TestFixture { "{\n" " signed char ch = 0;\n" " buf[ch] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int buf[256];\n" @@ -89,67 +89,67 @@ class TestCharVar : public TestFixture { "{\n" " char ch = 0x80;\n" " buf[ch] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5]: (portability) 'char' type used as array index. [unknownSignCharArrayIndex]\n", errout_str()); check("int buf[256];\n" "void foo(signed char ch)\n" "{\n" " buf[ch] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int buf[256];\n" "void foo(char ch)\n" "{\n" " buf[ch] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char* buf)\n" "{\n" " char ch = 0x80;" " buf[ch] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:24]: (portability) 'char' type used as array index. [unknownSignCharArrayIndex]\n", errout_str()); check("void foo(char* buf)\n" "{\n" " char ch = 0;" " buf[ch] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char* buf)\n" "{\n" " buf['A'] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char* buf, char ch)\n" "{\n" " buf[ch] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int flags[256];\n" "void foo(const char* str)\n" "{\n" " flags[*str] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int flags[256];\n" "void foo(const char* str)\n" "{\n" " flags[(unsigned char)*str] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(const char str[])\n" "{\n" " map[str] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -159,7 +159,7 @@ class TestCharVar : public TestFixture { "void bar(int i) {\n" " const char *s = \"abcde\";\n" " foo(s[i]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -167,32 +167,32 @@ class TestCharVar : public TestFixture { check("void foo(int *result) {\n" " signed char ch = -1;\n" " *result = a | ch;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:17]: (warning) When using 'char' variables in bit operations, sign extension can generate unexpected results. [charBitOp]\n", errout_str()); check("void foo(int *result) {\n" " unsigned char ch = -1;\n" " *result = a | ch;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char *result) {\n" " signed char ch = -1;\n" " *result = a | ch;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // 0x03 & .. check("void foo(int *result) {\n" " signed char ch = -1;\n" " *result = 0x03 | ch;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:20]: (warning) When using 'char' variables in bit operations, sign extension can generate unexpected results. [charBitOp]\n", errout_str()); check("void foo(int *result) {\n" " signed char ch = -1;\n" " *result = 0x03 & ch;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } }; diff --git a/test/testclass.cpp b/test/testclass.cpp index 457ab5932fe..451502c2164 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -282,25 +282,25 @@ class TestClass : public TestFixture { "{\n" " A(const A& other) { }\n" " A& operator=(const A& other) { return *this; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkCopyCtorAndEqOperator("class A\n" "{\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkCopyCtorAndEqOperator("class A\n" "{\n" " A(const A& other) { }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkCopyCtorAndEqOperator("class A\n" "{\n" " A& operator=(const A& other) { return *this; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -308,7 +308,7 @@ class TestClass : public TestFixture { "{\n" " A(const A& other) { }\n" " int x;\n" - "};"); + "};\n"); TODO_ASSERT_EQUALS("[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\n", "", errout_str()); // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator' @@ -316,7 +316,7 @@ class TestClass : public TestFixture { "{\n" " A& operator=(const A& other) { return *this; }\n" " int x;\n" - "};"); + "};\n"); TODO_ASSERT_EQUALS("[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\n", "", errout_str()); // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor' @@ -324,7 +324,7 @@ class TestClass : public TestFixture { "{\n" " A& operator=(const int &x) { this->x = x; return *this; }\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkCopyCtorAndEqOperator("class A {\n" @@ -344,7 +344,7 @@ class TestClass : public TestFixture { " B(const B & b) :A(b) { }\n" "private:\n" " static int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // #7987 - Don't show warning when there is a move constructor @@ -355,14 +355,14 @@ class TestClass : public TestFixture { " test = std::move(s.test);\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // #8337 - False positive in copy constructor detection checkCopyCtorAndEqOperator("struct StaticListNode {\n" " StaticListNode(StaticListNode*& prev) : m_next(0) {}\n" " StaticListNode* m_next;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -386,7 +386,7 @@ class TestClass : public TestFixture { " explicit Class(int i) { }\n" " explicit Class(const std::string&) { }\n" " Class(int a, int b) { }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkExplicitConstructors("class Class {\n" @@ -394,7 +394,7 @@ class TestClass : public TestFixture { " explicit Class(const Class& other) { }\n" " explicit Class(Class&& other) { }\n" " virtual int i() = 0;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkExplicitConstructors("class Class {\n" @@ -402,37 +402,37 @@ class TestClass : public TestFixture { " Class(const Class& other) = delete;\n" " Class(Class&& other) = delete;\n" " virtual int i() = 0;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkExplicitConstructors("class Class {\n" " Class(int i) { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:2:5]: (style) Class 'Class' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\n", errout_str()); checkExplicitConstructors("class Class {\n" " Class(const Class& other) { }\n" " virtual int i() = 0;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkExplicitConstructors("class Class {\n" " Class(Class&& other) { }\n" " virtual int i() = 0;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // #6585 checkExplicitConstructors("class Class {\n" " private: Class(const Class&);\n" " virtual int i() = 0;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkExplicitConstructors("class Class {\n" " public: Class(const Class&);\n" " virtual int i() = 0;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // #7465: Error properly reported in templates @@ -443,7 +443,7 @@ class TestClass : public TestFixture { "int main() {\n" " Test test;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:3]: (style) Struct 'Test < int >' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\n", errout_str()); // #7465: No error for copy or move constructors @@ -456,7 +456,7 @@ class TestClass : public TestFixture { "int main() {\n" " Test test;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #8600 @@ -464,12 +464,12 @@ class TestClass : public TestFixture { "struct A::B {\n" " B() = default;\n" " B(const B&) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkExplicitConstructors("struct A{" - " A(int, int y=2) {}" - "};"); + " A(int, int y=2) {}\n" + "};\n"); ASSERT_EQUALS("[test.cpp:1:14]: (style) Struct 'A' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\n", errout_str()); checkExplicitConstructors("struct Foo {\n" // #10515 @@ -541,7 +541,7 @@ class TestClass : public TestFixture { "};\n" "struct Derived : Base {\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkDuplInheritedMembers("class Base {\n" @@ -550,7 +550,7 @@ class TestClass : public TestFixture { "};\n" "struct Derived : Base {\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\n", errout_str()); checkDuplInheritedMembers("class Base {\n" @@ -559,7 +559,7 @@ class TestClass : public TestFixture { "};\n" "struct Derived : public Base {\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:6:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'. [duplInheritedMember]\n", errout_str()); checkDuplInheritedMembers("class Base0 {\n" @@ -570,7 +570,7 @@ class TestClass : public TestFixture { "};\n" "struct Derived : Base0, Base1 {\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkDuplInheritedMembers("class Base0 {\n" @@ -582,7 +582,7 @@ class TestClass : public TestFixture { "};\n" "struct Derived : Base0, Base1 {\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:9:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\n", errout_str()); checkDuplInheritedMembers("class Base0 {\n" @@ -595,7 +595,7 @@ class TestClass : public TestFixture { "};\n" "struct Derived : Base0, Base1 {\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'. [duplInheritedMember]\n" "[test.cpp:7:8] -> [test.cpp:10:8]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'. [duplInheritedMember]\n", errout_str()); @@ -604,7 +604,7 @@ class TestClass : public TestFixture { "};\n" "struct Derived : Base {\n" " int y;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkDuplInheritedMembers("class A {\n" @@ -612,20 +612,20 @@ class TestClass : public TestFixture { "};\n" "struct B {\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // Unknown 'Base' class checkDuplInheritedMembers("class Derived : public UnknownBase {\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkDuplInheritedMembers("class Base {\n" " int x;\n" "};\n" "class Derived : public Base {\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // #6692 @@ -637,7 +637,7 @@ class TestClass : public TestFixture { " struct SWibble : public test1::wibble {\n" " int Value;\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9957 @@ -651,12 +651,12 @@ class TestClass : public TestFixture { "};\n" "class Derived2 : public Derived1 {\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:13] -> [test.cpp:10:9]: (warning) The class 'Derived2' defines member variable with name 'i' also defined in its parent class 'Base'. [duplInheritedMember]\n", errout_str()); // don't crash on recursive template checkDuplInheritedMembers("template\n" - "struct BitInt : public BitInt { };"); + "struct BitInt : public BitInt { };\n"); ASSERT_EQUALS("", errout_str()); // don't crash on recursive template @@ -671,7 +671,7 @@ class TestClass : public TestFixture { " template \n" " struct fn_traits\n" " : public fn_traits {};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #10594 @@ -776,7 +776,7 @@ class TestClass : public TestFixture { " }\n" " F&operator=(const F&);\n" " ~F();\n" - "};"); + "};\n"); TODO_ASSERT_EQUALS("[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n", "", errout_str()); checkCopyConstructor("class F {\n" @@ -789,7 +789,7 @@ class TestClass : public TestFixture { " }\n" " ~F();\n" " F& operator=(const F&f);\n" - "};"); + "};\n"); TODO_ASSERT_EQUALS("[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\n" "[test.cpp:3] -> [test.cpp:7]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\n", "[test.cpp:4:7]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory. [copyCtorPointerCopying]\n" @@ -809,7 +809,7 @@ class TestClass : public TestFixture { " }\n" " ~F();\n" " F& operator=(const F&f);\n" - "};"); + "};\n"); TODO_ASSERT_EQUALS("[test.cpp:5]: (warning) Value of pointer 'p', which points to allocated memory, is copied in copy constructor instead of allocating new memory.\n" "[test.cpp:5] -> [test.cpp:10]: (warning) Copy constructor does not allocate memory for member 'p' although memory has been allocated in other constructors.\n", "" @@ -839,7 +839,7 @@ class TestClass : public TestFixture { " }\n" " ~kalci();\n" " kalci& operator=(const kalci&kalci);\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkCopyConstructor("class F\n" @@ -864,7 +864,7 @@ class TestClass : public TestFixture { " }\n" " ~F();\n" " F& operator=(const F&f);\n" - "};"); + "};\n"); TODO_ASSERT_EQUALS("[test.cpp:14] -> [test.cpp:11]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\n", "", errout_str()); checkCopyConstructor("class F {\n" @@ -878,7 +878,7 @@ class TestClass : public TestFixture { " }\n" " ~F();\n" " F& operator=(const F&f);\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkCopyConstructor("class F {\n" @@ -892,7 +892,7 @@ class TestClass : public TestFixture { " }\n" " ~F();\n" " F& operator=(const F&f);\n" - "};"); + "};\n"); TODO_ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:4]: (warning) Copy constructor does not allocate memory for member 'd' although memory has been allocated in other constructors.\n", "", errout_str()); checkCopyConstructor("class F\n" @@ -907,7 +907,7 @@ class TestClass : public TestFixture { " }\n" " ~F();\n" " F& operator=(const F&f);\n" - "};"); + "};\n"); TODO_ASSERT_EQUALS("[test.cpp:8]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management.\n", "", errout_str()); checkCopyConstructor("class F\n" @@ -931,7 +931,7 @@ class TestClass : public TestFixture { " }\n" " ~F();\n" " F& operator=(const F&f);\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkCopyConstructor("class F : E\n" @@ -942,7 +942,7 @@ class TestClass : public TestFixture { " }\n" " ~F();\n" " F& operator=(const F&f);\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkCopyConstructor("class E { E(E&); };\n" // non-copyable @@ -954,7 +954,7 @@ class TestClass : public TestFixture { " }\n" " ~F();\n" " F& operator=(const F&f);\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkCopyConstructor("class E {};\n" @@ -965,7 +965,7 @@ class TestClass : public TestFixture { " }\n" " ~F();\n" " F& operator=(const F&f);\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:7]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\n", errout_str()); checkCopyConstructor("class F {\n" @@ -976,7 +976,7 @@ class TestClass : public TestFixture { " F(F& f);\n" " ~F();\n" " F& operator=(const F&f);\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkCopyConstructor("class F {\n" @@ -984,7 +984,7 @@ class TestClass : public TestFixture { " F() : p(malloc(100)) {}\n" " ~F();\n" " F& operator=(const F&f);\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (warning) Class 'F' does not have a copy constructor which is recommended since it has dynamic memory/resource management. [noCopyConstructor]\n", errout_str()); // #7198 @@ -993,7 +993,7 @@ class TestClass : public TestFixture { " F() {\n" " p = malloc(100);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1010,7 +1010,7 @@ class TestClass : public TestFixture { " ~Vector();\n" " Vector& operator=(const Vector&v);\n" " _Tp* _M_finish;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1021,7 +1021,7 @@ class TestClass : public TestFixture { " F(const F &f) = delete;\n" " F&operator=(const F &f);\n" " ~F();\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkCopyConstructor("struct F {\n" @@ -1030,7 +1030,7 @@ class TestClass : public TestFixture { " F(const F &f) = default;\n" " F&operator=(const F &f);\n" " ~F();\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The copy constructor is explicitly defaulted but the default copy constructor does not work well. It is recommended to define or delete the copy constructor. [noCopyConstructor]\n", errout_str()); } @@ -1053,7 +1053,7 @@ class TestClass : public TestFixture { " ~Foo() { delete m_ptr; }\n" "private:\n" " int* m_ptr;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1066,7 +1066,7 @@ class TestClass : public TestFixture { " ~Foo() { delete m_ptr; }\n" "private:\n" " int* m_ptr;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkCopyConstructor("class Copyable {};\n" @@ -1077,7 +1077,7 @@ class TestClass : public TestFixture { " ~Foo() { delete m_ptr; }\n" "private:\n" " int* m_ptr;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1148,7 +1148,7 @@ class TestClass : public TestFixture { " F() { c = malloc(100); }\n" " F(const F &f);\n" " ~F();\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (warning) Struct 'F' does not have a operator= which is recommended since it has dynamic memory/resource management. [noOperatorEq]\n", errout_str()); // defaulted operator= @@ -1158,7 +1158,7 @@ class TestClass : public TestFixture { " F(const F &f);\n" " F &operator=(const F &f) = default;\n" " ~F();\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The operator= is explicitly defaulted but the default operator= does not work well. It is recommended to define or delete the operator=. [noOperatorEq]\n", errout_str()); // deleted operator= @@ -1168,7 +1168,7 @@ class TestClass : public TestFixture { " F(const F &f);\n" " F &operator=(const F &f) = delete;\n" " ~F();\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // base class deletes operator= @@ -1177,7 +1177,7 @@ class TestClass : public TestFixture { " F() { c = malloc(100); }\n" " F(const F &f);\n" " ~F();\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkCopyConstructor("struct S {\n" @@ -1196,7 +1196,7 @@ class TestClass : public TestFixture { " F() { c = malloc(100); }\n" " F(const F &f);\n" " F&operator=(const F&);" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\n", errout_str()); checkCopyConstructor("struct F {\n" @@ -1204,7 +1204,7 @@ class TestClass : public TestFixture { " F() { c = new C; }\n" " F(const F &f);\n" " F&operator=(const F&);" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkCopyConstructor("struct F {\n" @@ -1212,7 +1212,7 @@ class TestClass : public TestFixture { " F() { i = new int(); }\n" " F(const F &f);\n" " F& operator=(const F&);" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\n", errout_str()); checkCopyConstructor("struct Data { int x; int y; };\n" @@ -1221,7 +1221,7 @@ class TestClass : public TestFixture { " F() { c = new Data; }\n" " F(const F &f);\n" " F&operator=(const F&);" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:10]: (warning) Struct 'F' does not have a destructor which is recommended since it has dynamic memory/resource management. [noDestructor]\n", errout_str()); // defaulted destructor @@ -1231,7 +1231,7 @@ class TestClass : public TestFixture { " F(const F &f);\n" " F &operator=(const F &f);\n" " ~F() = default;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (warning) Struct 'F' has dynamic memory/resource allocation(s). The destructor is explicitly defaulted but the default destructor does not work well. It is recommended to define the destructor. [noDestructor]\n", errout_str()); // deleted destructor @@ -1241,7 +1241,7 @@ class TestClass : public TestFixture { " F(const F &f);\n" " F &operator=(const F &f);\n" " ~F() = delete;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1264,7 +1264,7 @@ class TestClass : public TestFixture { "{\n" "public:\n" " A & operator=(const A &a) { return *this; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqRetRefThis( @@ -1272,7 +1272,7 @@ class TestClass : public TestFixture { "{\n" "public:\n" " A & operator=(const A &a) { return a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1281,7 +1281,7 @@ class TestClass : public TestFixture { "public:\n" " A & operator=(const A &);\n" "};\n" - "A & A::operator=(const A &a) { return *this; }"); + "A & A::operator=(const A &a) { return *this; }\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqRetRefThis( @@ -1290,7 +1290,7 @@ class TestClass : public TestFixture { "public:\n" " A & operator=(const A &a);\n" "};\n" - "A & A::operator=(const A &a) { return *this; }"); + "A & A::operator=(const A &a) { return *this; }\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqRetRefThis( @@ -1299,7 +1299,7 @@ class TestClass : public TestFixture { "public:\n" " A & operator=(const A &);\n" "};\n" - "A & A::operator=(const A &a) { return a; }"); + "A & A::operator=(const A &a) { return a; }\n"); ASSERT_EQUALS("[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1308,7 +1308,7 @@ class TestClass : public TestFixture { "public:\n" " A & operator=(const A &a);\n" "};\n" - "A & A::operator=(const A &a) { return a; }"); + "A & A::operator=(const A &a) { return a; }\n"); ASSERT_EQUALS("[test.cpp:6:8]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1320,7 +1320,7 @@ class TestClass : public TestFixture { " public:\n" " B & operator=(const B &b) { return *this; }\n" " };\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqRetRefThis( @@ -1332,7 +1332,7 @@ class TestClass : public TestFixture { " public:\n" " B & operator=(const B &b) { return b; }\n" " };\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:7:13]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1345,7 +1345,7 @@ class TestClass : public TestFixture { " B & operator=(const B &);\n" " };\n" "};\n" - "A::B & A::B::operator=(const A::B &b) { return *this; }"); + "A::B & A::B::operator=(const A::B &b) { return *this; }\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqRetRefThis( @@ -1358,7 +1358,7 @@ class TestClass : public TestFixture { " B & operator=(const B &);\n" " };\n" "};\n" - "A::B & A::B::operator=(const A::B &b) { return b; }"); + "A::B & A::B::operator=(const A::B &b) { return b; }\n"); ASSERT_EQUALS("[test.cpp:10:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1368,7 +1368,7 @@ class TestClass : public TestFixture { "class A::B\n" "{\n" " B & operator=(const B & b) { return b; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1379,7 +1379,7 @@ class TestClass : public TestFixture { "{\n" " B & operator=(const B &);\n" "};\n" - "A::B & A::B::operator=(const A::B & b) { return b; }"); + "A::B & A::B::operator=(const A::B & b) { return b; }\n"); ASSERT_EQUALS("[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1389,7 +1389,7 @@ class TestClass : public TestFixture { "class A::B\n" "{\n" " A::B & operator=(const A::B & b) { return b; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1400,7 +1400,7 @@ class TestClass : public TestFixture { "{\n" " A::B & operator=(const A::B &);\n" "};\n" - "A::B & A::B::operator=(const A::B & b) { return b; }"); + "A::B & A::B::operator=(const A::B & b) { return b; }\n"); ASSERT_EQUALS("[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1410,7 +1410,7 @@ class TestClass : public TestFixture { "class A::B\n" "{\n" " B & operator=(const B & b) { return b; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:7]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1421,7 +1421,7 @@ class TestClass : public TestFixture { "{\n" " B & operator=(const B &);\n" "};\n" - "A::B & A::B::operator=(const A::B & b) { return b; }"); + "A::B & A::B::operator=(const A::B & b) { return b; }\n"); ASSERT_EQUALS("[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1431,7 +1431,7 @@ class TestClass : public TestFixture { "class A::B\n" "{\n" " A::B & operator=(const A::B & b) { return b; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:10]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1442,7 +1442,7 @@ class TestClass : public TestFixture { "{\n" " A::B & operator=(const A::B &);\n" "};\n" - "A::B & A::B::operator=(const A::B & b) { return b; }"); + "A::B & A::B::operator=(const A::B & b) { return b; }\n"); ASSERT_EQUALS("[test.cpp:8:14]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( // #11380 @@ -1462,7 +1462,7 @@ class TestClass : public TestFixture { "class szp\n" "{\n" " szp &operator =(int *other) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1470,7 +1470,7 @@ class TestClass : public TestFixture { "{\n" " szp &operator =(int *other);\n" "};\n" - "szp &szp::operator =(int *other) {}"); + "szp &szp::operator =(int *other) {}\n"); ASSERT_EQUALS("[test.cpp:5:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1480,7 +1480,7 @@ class TestClass : public TestFixture { "class NS::szp\n" "{\n" " szp &operator =(int *other) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1491,7 +1491,7 @@ class TestClass : public TestFixture { "{\n" " szp &operator =(int *other);\n" "};\n" - "NS::szp &NS::szp::operator =(int *other) {}"); + "NS::szp &NS::szp::operator =(int *other) {}\n"); ASSERT_EQUALS("[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1501,7 +1501,7 @@ class TestClass : public TestFixture { "class NS::szp\n" "{\n" " NS::szp &operator =(int *other) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:12]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1512,7 +1512,7 @@ class TestClass : public TestFixture { "{\n" " NS::szp &operator =(int *other);\n" "};\n" - "NS::szp &NS::szp::operator =(int *other) {}"); + "NS::szp &NS::szp::operator =(int *other) {}\n"); ASSERT_EQUALS("[test.cpp:8:19]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1522,7 +1522,7 @@ class TestClass : public TestFixture { "class A::szp\n" "{\n" " szp &operator =(int *other) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:8]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1533,7 +1533,7 @@ class TestClass : public TestFixture { "{\n" " szp &operator =(int *other);\n" "};\n" - "A::szp &A::szp::operator =(int *other) {}"); + "A::szp &A::szp::operator =(int *other) {}\n"); ASSERT_EQUALS("[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1543,7 +1543,7 @@ class TestClass : public TestFixture { "class A::szp\n" "{\n" " A::szp &operator =(int *other) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:11]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1554,7 +1554,7 @@ class TestClass : public TestFixture { "{\n" " A::szp &operator =(int *other);\n" "};\n" - "A::szp &A::szp::operator =(int *other) {}"); + "A::szp &A::szp::operator =(int *other) {}\n"); ASSERT_EQUALS("[test.cpp:8:17]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); } @@ -1565,7 +1565,7 @@ class TestClass : public TestFixture { "public:\n" " inline A &operator =(int *other) { return (*this); };\n" " inline A &operator =(long *other) { return (*this = 0); };\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqRetRefThis( @@ -1575,7 +1575,7 @@ class TestClass : public TestFixture { " A &operator =(long *other);\n" "};\n" "A &A::operator =(int *other) { return (*this); };\n" - "A &A::operator =(long *other) { return (*this = 0); };"); + "A &A::operator =(long *other) { return (*this = 0); };\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqRetRefThis( @@ -1583,7 +1583,7 @@ class TestClass : public TestFixture { "public:\n" " inline A &operator =(int *other) { return (*this); };\n" " inline A &operator =(long *other) { return operator = (*(int *)other); };\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqRetRefThis( @@ -1593,7 +1593,7 @@ class TestClass : public TestFixture { " A &operator =(long *other);\n" "};\n" "A &A::operator =(int *other) { return (*this); };\n" - "A &A::operator =(long *other) { return operator = (*(int *)other); };"); + "A &A::operator =(long *other) { return operator = (*(int *)other); };\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqRetRefThis( @@ -1603,7 +1603,7 @@ class TestClass : public TestFixture { " A &operator =(long *other);\n" "};\n" "A &A::operator =(int *other) { return (*this); };\n" - "A &A::operator =(long *other) { return this->operator = (*(int *)other); };"); + "A &A::operator =(long *other) { return this->operator = (*(int *)other); };\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqRetRefThis( // #9045 @@ -1615,7 +1615,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1625,7 +1625,7 @@ class TestClass : public TestFixture { "P& P::operator = (const P& pc)\n" "{\n" " return (P&)(*this += pc);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1635,21 +1635,21 @@ class TestClass : public TestFixture { "class A {\n" "public:\n" " A & operator=(const A &a) { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:9]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); checkOpertorEqRetRefThis( "class A {\n" "protected:\n" " A & operator=(const A &a) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( "class A {\n" "private:\n" " A & operator=(const A &a) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:9]: (style) 'operator=' should return reference to 'this' instance. [operatorEqRetRefThis]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1659,7 +1659,7 @@ class TestClass : public TestFixture { " rand();\n" " throw std::exception();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1669,7 +1669,7 @@ class TestClass : public TestFixture { " rand();\n" " abort();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:9]: (style) 'operator=' should either return reference to 'this' instance or be declared private and left unimplemented. [operatorEqShouldBeLeftUnimplemented]\n", errout_str()); checkOpertorEqRetRefThis( @@ -1677,7 +1677,7 @@ class TestClass : public TestFixture { "public:\n" " A & operator=(const A &a);\n" "};\n" - "A & A :: operator=(const A &a) { }"); + "A & A :: operator=(const A &a) { }\n"); ASSERT_EQUALS("[test.cpp:5:10]: (error) No 'return' statement in non-void function causes undefined behavior. [operatorEqMissingReturnStatement]\n", errout_str()); } @@ -1694,7 +1694,7 @@ class TestClass : public TestFixture { "}\n" "UString& UString::operator=( const UString& s ) {\n" " return assign( s );\n" - "}"); + "}\n"); } void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis() @@ -1712,7 +1712,7 @@ class TestClass : public TestFixture { " basic_fbstring& replace() {\n" " return replaceImplDiscr();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1736,7 +1736,7 @@ class TestClass : public TestFixture { "{\n" "public:\n" " A & operator=(const A &a) { if (&a != this) { } return *this; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // this test doesn't have an assignment test but it is not needed @@ -1745,7 +1745,7 @@ class TestClass : public TestFixture { "{\n" "public:\n" " A & operator=(const A &a) { return *this; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // this test needs an assignment test and has it @@ -1763,7 +1763,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // this class needs an assignment test but doesn't have it @@ -1778,7 +1778,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test has an assignment test but doesn't need it @@ -1788,7 +1788,7 @@ class TestClass : public TestFixture { "public:\n" " A & operator=(const A &);\n" "};\n" - "A & A::operator=(const A &a) { if (&a != this) { } return *this; }"); + "A & A::operator=(const A &a) { if (&a != this) { } return *this; }\n"); ASSERT_EQUALS("", errout_str()); // this test doesn't have an assignment test but doesn't need it @@ -1798,7 +1798,7 @@ class TestClass : public TestFixture { "public:\n" " A & operator=(const A &);\n" "};\n" - "A & A::operator=(const A &a) { return *this; }"); + "A & A::operator=(const A &a) { return *this; }\n"); ASSERT_EQUALS("", errout_str()); // this test needs an assignment test and has it @@ -1817,7 +1817,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // this test needs an assignment test and has the inverse test @@ -1836,7 +1836,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test needs an assignment test and has the inverse test @@ -1855,7 +1855,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test needs an assignment test and has the inverse test @@ -1874,7 +1874,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test needs an assignment test and has the inverse test @@ -1893,7 +1893,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test needs an assignment test and has the inverse test @@ -1912,7 +1912,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test needs an assignment test and has the inverse test @@ -1934,7 +1934,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test needs an assignment test and has the inverse test @@ -1955,7 +1955,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); @@ -1972,7 +1972,7 @@ class TestClass : public TestFixture { " free(s);\n" " s = strdup(a.s);\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // ticket #1224 @@ -1990,7 +1990,7 @@ class TestClass : public TestFixture { " tree = new CodeTree(b);\n" " delete oldtree;\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2006,7 +2006,7 @@ class TestClass : public TestFixture { " public:\n" " B & operator=(const B &b) { if (&b != this) { } return *this; }\n" " };\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // this test doesn't have an assignment test but doesn't need it @@ -2019,7 +2019,7 @@ class TestClass : public TestFixture { " public:\n" " B & operator=(const B &b) { return *this; }\n" " };\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // this test needs an assignment test but has it @@ -2039,7 +2039,7 @@ class TestClass : public TestFixture { " return *this;\n" " }\n" " };\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // this test needs an assignment test but doesn't have it @@ -2058,7 +2058,7 @@ class TestClass : public TestFixture { " return *this;\n" " }\n" " };\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:8:13]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); // this test has an assignment test but doesn't need it @@ -2072,7 +2072,7 @@ class TestClass : public TestFixture { " B & operator=(const B &);\n" " };\n" "};\n" - "A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }"); + "A::B & A::B::operator=(const A::B &b) { if (&b != this) { } return *this; }\n"); ASSERT_EQUALS("", errout_str()); // this test doesn't have an assignment test but doesn't need it @@ -2086,7 +2086,7 @@ class TestClass : public TestFixture { " B & operator=(const B &);\n" " };\n" "};\n" - "A::B & A::B::operator=(const A::B &b) { return *this; }"); + "A::B & A::B::operator=(const A::B &b) { return *this; }\n"); ASSERT_EQUALS("", errout_str()); // this test needs an assignment test and has it @@ -2109,7 +2109,7 @@ class TestClass : public TestFixture { " s = strdup(b.s);\n" " }\n" " return *this;\n" - " }"); + " }\n"); ASSERT_EQUALS("", errout_str()); // this test needs an assignment test but doesn't have it @@ -2129,7 +2129,7 @@ class TestClass : public TestFixture { " free(s);\n" " s = strdup(b.s);\n" " return *this;\n" - " }"); + " }\n"); ASSERT_EQUALS("[test.cpp:11:14]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); } @@ -2140,7 +2140,7 @@ class TestClass : public TestFixture { "{\n" "public:\n" " A & operator=(const A &a) { return *this; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it @@ -2155,7 +2155,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it @@ -2165,7 +2165,7 @@ class TestClass : public TestFixture { "public:\n" " A & operator=(const A &);\n" "};\n" - "A & A::operator=(const A &a) { return *this; }"); + "A & A::operator=(const A &a) { return *this; }\n"); ASSERT_EQUALS("", errout_str()); // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it @@ -2181,7 +2181,7 @@ class TestClass : public TestFixture { " free(s);\n" " s = strdup(a.s);\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2196,7 +2196,7 @@ class TestClass : public TestFixture { " public:\n" " B & operator=(const B &b) { return *this; }\n" " };\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it @@ -2215,7 +2215,7 @@ class TestClass : public TestFixture { " return *this;\n" " }\n" " };\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it @@ -2229,7 +2229,7 @@ class TestClass : public TestFixture { " B & operator=(const B &);\n" " };\n" "};\n" - "A::B & A::B::operator=(const A::B &b) { return *this; }"); + "A::B & A::B::operator=(const A::B &b) { return *this; }\n"); ASSERT_EQUALS("", errout_str()); // this test has multiple inheritance and needs an assignment test but there is no trivial way to test for it @@ -2249,7 +2249,7 @@ class TestClass : public TestFixture { " free(s);\n" " s = strdup(b.s);\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2269,7 +2269,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2286,7 +2286,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2303,7 +2303,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2320,7 +2320,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2337,7 +2337,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2354,7 +2354,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2371,7 +2371,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2388,7 +2388,7 @@ class TestClass : public TestFixture { " }\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2406,7 +2406,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2424,7 +2424,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2442,7 +2442,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2460,7 +2460,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2478,7 +2478,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2496,7 +2496,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2514,7 +2514,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2532,7 +2532,7 @@ class TestClass : public TestFixture { " s = strdup(a.s);\n" " }\n" " return *this;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOpertorEqToSelf( @@ -2544,7 +2544,7 @@ class TestClass : public TestFixture { " free(s);\n" " s = strdup(a.s);\n" " return *this;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2563,7 +2563,7 @@ class TestClass : public TestFixture { " }\n" "private:\n" " char * data;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); checkOpertorEqToSelf( @@ -2580,7 +2580,7 @@ class TestClass : public TestFixture { " data = new char[strlen(a.data) + 1];\n" " strcpy(data, a.data);\n" " return *this;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); checkOpertorEqToSelf( @@ -2596,7 +2596,7 @@ class TestClass : public TestFixture { " }\n" "private:\n" " char * data;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:9]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); checkOpertorEqToSelf( @@ -2613,7 +2613,7 @@ class TestClass : public TestFixture { " data = new char;\n" " *data = *a.data;\n" " return *this;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:8:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory. [operatorEqToSelf]\n", errout_str()); } @@ -2630,7 +2630,7 @@ class TestClass : public TestFixture { " {\n" " return assign(a);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2649,7 +2649,7 @@ class TestClass : public TestFixture { "FMat& FMat::operator=(const FMat& in)\n" "{\n" " return copy(in);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2668,7 +2668,7 @@ class TestClass : public TestFixture { "Foo& Foo::operator=(Foo& other)\n" "{\n" " return Foo::operator=(&other);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2697,12 +2697,12 @@ class TestClass : public TestFixture { checkVirtualDestructor("class Derived : public Base { };\n" "Base *base = new Derived;\n" - "delete base;"); + "delete base;\n"); ASSERT_EQUALS("", errout_str()); checkVirtualDestructor("class Derived : Base { };\n" "Base *base = new Derived;\n" - "delete base;"); + "delete base;\n"); ASSERT_EQUALS("", errout_str()); } @@ -2710,27 +2710,27 @@ class TestClass : public TestFixture { // Base class doesn't have a destructor checkVirtualDestructor("class Base { };\n" - "class Derived : public Base { public: ~Derived() { (void)11; } };" + "class Derived : public Base { public: ~Derived() { (void)11; } };\n" "Base *base = new Derived;\n" - "delete base;"); + "delete base;\n"); ASSERT_EQUALS("[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); checkVirtualDestructor("class Base { };\n" - "class Derived : protected Base { public: ~Derived() { (void)11; } };" + "class Derived : protected Base { public: ~Derived() { (void)11; } };\n" "Base *base = new Derived;\n" - "delete base;"); + "delete base;\n"); ASSERT_EQUALS("[test.cpp:1:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); checkVirtualDestructor("class Base { };\n" - "class Derived : private Base { public: ~Derived() { (void)11; } };" + "class Derived : private Base { public: ~Derived() { (void)11; } };\n" "Base *base = new Derived;\n" - "delete base;"); + "delete base;\n"); ASSERT_EQUALS("", errout_str()); checkVirtualDestructor("class Base { };\n" - "class Derived : Base { public: ~Derived() { (void)11; } };" + "class Derived : Base { public: ~Derived() { (void)11; } };\n" "Base *base = new Derived;\n" - "delete base;"); + "delete base;\n"); ASSERT_EQUALS("", errout_str()); // #9104 @@ -2751,7 +2751,7 @@ class TestClass : public TestFixture { "{\n" " Base* p = new Derived();\n" " delete p;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); checkVirtualDestructor("using namespace std;\n" @@ -2772,7 +2772,7 @@ class TestClass : public TestFixture { "{\n" " Base* p = new Derived();\n" " delete p;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); } @@ -2780,21 +2780,21 @@ class TestClass : public TestFixture { // Base class has a destructor, but it's not virtual checkVirtualDestructor("class Base { public: ~Base(); };\n" - "class Derived : public Base { public: ~Derived() { (void)11; } };" + "class Derived : public Base { public: ~Derived() { (void)11; } };\n" "Base *base = new Derived;\n" - "delete base;"); + "delete base;\n"); ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); checkVirtualDestructor("class Base { public: ~Base(); };\n" - "class Derived : protected Base { public: ~Derived() { (void)11; } };" + "class Derived : protected Base { public: ~Derived() { (void)11; } };\n" "Base *base = new Derived;\n" - "delete base;"); + "delete base;\n"); ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); checkVirtualDestructor("class Base { public: ~Base(); };\n" - "class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };" + "class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };\n" "Base *base = new Derived;\n" - "delete base;"); + "delete base;\n"); ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); } @@ -2802,15 +2802,15 @@ class TestClass : public TestFixture { // Derived class doesn't have a destructor => undefined behaviour according to paragraph 3 in [expr.delete] checkVirtualDestructor("class Base { public: ~Base(); };\n" - "class Derived : public Base { };" + "class Derived : public Base { };\n" "Base *base = new Derived;\n" - "delete base;"); + "delete base;\n"); ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); checkVirtualDestructor("class Base { public: ~Base(); };\n" - "class Derived : private Fred, public Base { };" + "class Derived : private Fred, public Base { };\n" "Base *base = new Derived;\n" - "delete base;"); + "delete base;\n"); ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); } @@ -2818,15 +2818,15 @@ class TestClass : public TestFixture { // Derived class has empty destructor => undefined behaviour according to paragraph 3 in [expr.delete] checkVirtualDestructor("class Base { public: ~Base(); };\n" - "class Derived : public Base { public: ~Derived() {} };" + "class Derived : public Base { public: ~Derived() {} };\n" "Base *base = new Derived;\n" - "delete base;"); + "delete base;\n"); ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); checkVirtualDestructor("class Base { public: ~Base(); };\n" - "class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}" + "class Derived : public Base { public: ~Derived(); }; Derived::~Derived() {}\n" "Base *base = new Derived;\n" - "delete base;"); + "delete base;\n"); ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); } @@ -2835,7 +2835,7 @@ class TestClass : public TestFixture { // points at derived class checkVirtualDestructor("class Base { public: ~Base(); };\n" - "class Derived : public Base { public: ~Derived() { (void)11; } };"); + "class Derived : public Base { public: ~Derived() { (void)11; } };\n"); ASSERT_EQUALS("", errout_str()); } @@ -2852,7 +2852,7 @@ class TestClass : public TestFixture { "{\n" "public:\n" " ~B() { int a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2873,7 +2873,7 @@ class TestClass : public TestFixture { "{\n" "public:\n" " ~B() { int a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // class A inherits virtual destructor from struct Base -> no error @@ -2891,7 +2891,7 @@ class TestClass : public TestFixture { "{\n" "public:\n" " ~B() { int a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // Unknown Base class -> it could have virtual destructor, so ignore @@ -2905,7 +2905,7 @@ class TestClass : public TestFixture { "{\n" "public:\n" " ~B() { int a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // Virtual destructor is inherited -> no error @@ -2926,7 +2926,7 @@ class TestClass : public TestFixture { "{\n" "public:\n" " ~B() { int a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // class A doesn't inherit virtual destructor from class Base -> error @@ -2945,7 +2945,7 @@ class TestClass : public TestFixture { "{\n" "public:\n" " ~B() { int a; }\n" - "};"); + "};\n"); TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Class 'Base' which is inherited by class 'B' does not have a virtual destructor.\n", "", errout_str()); } @@ -2967,7 +2967,7 @@ class TestClass : public TestFixture { " ~B(){int a;}\n" "};\n" "\n" - "AA *p = new B; delete p;"); + "AA *p = new B; delete p;\n"); ASSERT_EQUALS("[test.cpp:9:3]: (error) Class 'AA < double >' which is inherited by class 'B' does not have a virtual destructor. [virtualDestructor]\n", errout_str()); } @@ -3037,7 +3037,7 @@ class TestClass : public TestFixture { "{\n" " Fred fred;\n" " memset(&fred, 0, sizeof(Fred));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkNoMemset("class Fred\n" @@ -3048,7 +3048,7 @@ class TestClass : public TestFixture { "{\n" " Fred fred;\n" " memset(&fred, 0, sizeof(Fred));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkNoMemset("class Fred\n" @@ -3059,7 +3059,7 @@ class TestClass : public TestFixture { "{\n" " Fred fred;\n" " memset(&fred, 0, sizeof(Fred));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkNoMemset("class Fred\n" @@ -3070,7 +3070,7 @@ class TestClass : public TestFixture { "{\n" " Fred fred;\n" " memset(&fred, 0, sizeof(Fred));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("class Fred\n" @@ -3081,7 +3081,7 @@ class TestClass : public TestFixture { "{\n" " Fred fred;\n" " memset(&fred, 0, sizeof(Fred));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("class Fred {\n" @@ -3090,7 +3090,7 @@ class TestClass : public TestFixture { "};\n" "void Fred::f() {\n" " memset(this, 0, sizeof(*this));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("class Fred\n" @@ -3100,7 +3100,7 @@ class TestClass : public TestFixture { "{\n" " Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkNoMemset("class Fred\n" @@ -3111,7 +3111,7 @@ class TestClass : public TestFixture { "{\n" " Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("class Fred\n" @@ -3123,7 +3123,7 @@ class TestClass : public TestFixture { "{\n" " Pebbles pebbles;\n" " memset(&pebbles, 0, sizeof(pebbles));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("class Fred\n" @@ -3134,7 +3134,7 @@ class TestClass : public TestFixture { "{\n" " Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\n", errout_str()); checkNoMemset("class Fred\n" @@ -3145,7 +3145,7 @@ class TestClass : public TestFixture { "{\n" " static Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\n", errout_str()); checkNoMemset("class Fred\n" @@ -3160,7 +3160,7 @@ class TestClass : public TestFixture { "{\n" " Pebbles pebbles;\n" " memset(&pebbles, 0, sizeof(pebbles));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:12:5]: (error) Using 'memset' on class that contains a virtual function. [memsetClass]\n", errout_str()); // Fred not defined in scope @@ -3174,7 +3174,7 @@ class TestClass : public TestFixture { "{\n" " Fred fred;\n" " memset(&fred, 0, sizeof(Fred));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Fred with namespace qualifier @@ -3188,7 +3188,7 @@ class TestClass : public TestFixture { "{\n" " n1::Fred fred;\n" " memset(&fred, 0, sizeof(n1::Fred));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\n", errout_str()); // Fred with namespace qualifier @@ -3202,7 +3202,7 @@ class TestClass : public TestFixture { "{\n" " n1::Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:5]: (error) Using 'memset' on class that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("class A {\n" @@ -3213,7 +3213,7 @@ class TestClass : public TestFixture { " const int N = 10;\n" " A** arr = new A*[N];\n" " memset(arr, 0, N * sizeof(A*));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkNoMemset("class A {\n" // #5116 - nested class data is mixed in the SymbolDatabase @@ -3222,7 +3222,7 @@ class TestClass : public TestFixture { "};\n" "void f(A::B *b) {\n" " memset(b,0,4);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #4461 Warn about memset/memcpy on class with references as members @@ -3232,7 +3232,7 @@ class TestClass : public TestFixture { "void f() {\n" " A a;\n" " memset(&a, 0, sizeof(a));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\n", errout_str()); checkNoMemset("class A {\n" " const B&b;\n" @@ -3240,7 +3240,7 @@ class TestClass : public TestFixture { "void f() {\n" " A a;\n" " memset(&a, 0, sizeof(a));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:3]: (error) Using 'memset' on class that contains a reference. [memsetClassReference]\n", errout_str()); // #7456 @@ -3254,7 +3254,7 @@ class TestClass : public TestFixture { "void func() {\n" " B b[4];\n" " memset(b, 0, sizeof(b));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #8619 @@ -3309,11 +3309,11 @@ class TestClass : public TestFixture { " } vid;\n" " };\n" " } hdr;\n" - "};" + "};\n" "void parseHeader() {\n" " ASFStreamHeader strhdr;\n" " memset(&strhdr, 0, sizeof(strhdr));\n" - "}"); + "}\n"); } void memsetOnStruct() { @@ -3324,7 +3324,7 @@ class TestClass : public TestFixture { "{\n" " A a;\n" " memset(&a, 0, sizeof(A));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkNoMemset("struct A\n" @@ -3334,7 +3334,7 @@ class TestClass : public TestFixture { "{\n" " struct A a;\n" " memset(&a, 0, sizeof(struct A));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkNoMemset("struct A\n" @@ -3344,14 +3344,14 @@ class TestClass : public TestFixture { "{\n" " struct A a;\n" " memset(&a, 0, sizeof(A));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkNoMemset("void f()\n" "{\n" " struct sockaddr_in6 fail;\n" " memset(&fail, 0, sizeof(struct sockaddr_in6));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkNoMemset("struct A\n" @@ -3364,7 +3364,7 @@ class TestClass : public TestFixture { "{\n" " struct A fail;\n" " memset(&fail, 0, sizeof(struct A));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:2]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("struct Fred\n" @@ -3375,7 +3375,7 @@ class TestClass : public TestFixture { "{\n" " Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\n", errout_str()); checkNoMemset("struct Stringy {\n" @@ -3387,7 +3387,7 @@ class TestClass : public TestFixture { "int main() {\n" " Foo foo;\n" " memset(&foo, 0, sizeof(Foo));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\n", errout_str()); } @@ -3400,7 +3400,7 @@ class TestClass : public TestFixture { "{\n" " A a;\n" " memset(&a, 0, sizeof(A));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("struct A\n" @@ -3410,7 +3410,7 @@ class TestClass : public TestFixture { "{\n" " A a;\n" " memset(&a, 0, sizeof(A));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("struct A\n" @@ -3420,7 +3420,7 @@ class TestClass : public TestFixture { "{\n" " A a;\n" " memset(&a, 0, sizeof(struct A));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("struct A\n" @@ -3430,7 +3430,7 @@ class TestClass : public TestFixture { "{\n" " A a;\n" " memset(&a, 0, sizeof(a));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("class A\n" @@ -3440,7 +3440,7 @@ class TestClass : public TestFixture { "{\n" " A a;\n" " memset(&a, 0, sizeof(A));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on class that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("struct A\n" @@ -3450,7 +3450,7 @@ class TestClass : public TestFixture { "{\n" " A a;\n" " memset(&a, 0, sizeof(A));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("struct A\n" @@ -3460,7 +3460,7 @@ class TestClass : public TestFixture { "{\n" " A a;\n" " memset(&a, 0, sizeof(a));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("struct A\n" @@ -3470,7 +3470,7 @@ class TestClass : public TestFixture { "{\n" " A a;\n" " memset(&a, 0, sizeof(A));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:5]: (error) Using 'memset' on struct that contains a 'std::vector'. [memsetClass]\n", errout_str()); checkNoMemset("struct A {\n" @@ -3480,7 +3480,7 @@ class TestClass : public TestFixture { "void f() {\n" " A a;\n" " memset(a, 0, 100);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #4460 checkNoMemset("struct C {\n" @@ -3498,7 +3498,7 @@ class TestClass : public TestFixture { " memset(*c4, 0, 10);\n" " memset(c2, 0, 10);\n" " memset(c3, 0, 10);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\n" "[test.cpp:11:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\n" "[test.cpp:12:5]: (error) Using 'memset' on struct that contains a 'std::string'. [memsetClass]\n" @@ -3514,7 +3514,7 @@ class TestClass : public TestFixture { " multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\n" " memset(d, 0, sizeof(multilevel_data));\n" " return (void*) d;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:3]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\n", errout_str()); } @@ -3532,7 +3532,7 @@ class TestClass : public TestFixture { "void f() {\n" " A a;\n" " memset(&a, 0, sizeof(A));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // std::array is POD (#5481) checkNoMemset("struct st {\n" @@ -3543,7 +3543,7 @@ class TestClass : public TestFixture { "void f() {\n" " st s;\n" " std::memset(&s, 0, sizeof(st));\n" - "}", settings); + "}\n", settings); ASSERT_EQUALS("", errout_str()); } @@ -3554,7 +3554,7 @@ class TestClass : public TestFixture { "void f() {\n" " A a;\n" " memset(&a, 0, sizeof(A));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\n", errout_str()); checkNoMemset("struct A {\n" @@ -3563,7 +3563,7 @@ class TestClass : public TestFixture { "void f() {\n" " A a;\n" " memset(&a, 0, sizeof(A));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:5]: (portability) Using memset() on struct which contains a floating point number. [memsetClassFloat]\n", errout_str()); checkNoMemset("struct A {\n" @@ -3572,7 +3572,7 @@ class TestClass : public TestFixture { "void f(const A& b) {\n" " A a;\n" " memcpy(&a, &b, sizeof(A));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkNoMemset("struct A {\n" @@ -3581,7 +3581,7 @@ class TestClass : public TestFixture { "void f() {\n" " A a;\n" " memset(&a, 0, sizeof(A));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3589,7 +3589,7 @@ class TestClass : public TestFixture { checkNoMemset("void clang_tokenize(CXToken **Tokens) {\n" " *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());\n" " memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3597,49 +3597,49 @@ class TestClass : public TestFixture { checkNoMemset("class C { C() {} };\n" "void foo(C*& p) {\n" " p = malloc(sizeof(C));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\n", errout_str()); checkNoMemset("class C { C(int z, Foo bar) { bar(); } };\n" "void foo(C*& p) {\n" " p = malloc(sizeof(C));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with malloc(), but class provides constructors. [mallocOnClassWarning]\n", errout_str()); checkNoMemset("struct C { C() {} };\n" "void foo(C*& p) {\n" " p = realloc(p, sizeof(C));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5] -> [test.cpp:1:1]: (warning) Memory for class instance allocated with realloc(), but class provides constructors. [mallocOnClassWarning]\n", errout_str()); checkNoMemset("struct C { virtual void bar(); };\n" "void foo(C*& p) {\n" " p = malloc(sizeof(C));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a virtual function. [mallocOnClassError]\n", errout_str()); checkNoMemset("struct C { std::string s; };\n" "void foo(C*& p) {\n" " p = malloc(sizeof(C));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:1:1]: (error) Memory for class instance allocated with malloc(), but class contains a 'std::string'. [mallocOnClassError]\n", errout_str()); checkNoMemset("class C { };\n" // C-Style class/struct "void foo(C*& p) {\n" " p = malloc(sizeof(C));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkNoMemset("struct C { C() {} };\n" "void foo(C*& p) {\n" " p = new C();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkNoMemset("class C { C() {} };\n" "void foo(D*& p) {\n" // Unknown type " p = malloc(sizeof(C));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkNoMemset("class AutoCloseFD {\n" @@ -3650,7 +3650,7 @@ class TestClass : public TestFixture { "};\n" "void f() {\n" " AutoCloseFD fd = open(\"abc\", O_RDONLY | O_CLOEXEC);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkNoMemset("struct C {\n" // #12313 @@ -3659,7 +3659,7 @@ class TestClass : public TestFixture { "};\n" "void f() {\n" " C c = strdup(\"abc\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3676,19 +3676,19 @@ class TestClass : public TestFixture { } void this_subtraction() { - checkThisSubtraction("; this-x ;"); + checkThisSubtraction("; this-x ;\n"); ASSERT_EQUALS("[test.cpp:1:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\n", errout_str()); - checkThisSubtraction("; *this = *this-x ;"); + checkThisSubtraction("; *this = *this-x ;\n"); ASSERT_EQUALS("", errout_str()); checkThisSubtraction("; *this = *this-x ;\n" - "this-x ;"); + "this-x ;\n"); ASSERT_EQUALS("[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\n", errout_str()); checkThisSubtraction("; *this = *this-x ;\n" "this-x ;\n" - "this-x ;"); + "this-x ;\n"); ASSERT_EQUALS("[test.cpp:2:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\n" "[test.cpp:3:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'? [thisSubtraction]\n", errout_str()); } @@ -3719,18 +3719,18 @@ class TestClass : public TestFixture { checkConst("class Fred {\n" " int a;\n" " int getA() { return a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:9]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\n", errout_str()); checkConst("class Fred {\n" " const std::string foo() { return \"\"; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:2:23]: (style) The member function 'Fred::foo' can be static. [functionStatic]\n", errout_str()); checkConst("class Fred {\n" " std::string s;\n" " const std::string & foo() { return \"\"; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:25]: (style) The member function 'Fred::foo' can be static. [functionStatic]\n", errout_str()); // constructors can't be const.. @@ -3738,14 +3738,14 @@ class TestClass : public TestFixture { " int a;\n" "public:\n" " Fred() { }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // assignment through |=.. checkConst("class Fred {\n" " int a;\n" " int setA() { a |= true; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // functions with a call to a member function can only be const, if that member function is const, too.. (#1305) @@ -3754,7 +3754,7 @@ class TestClass : public TestFixture { " int x;\n" " void a() { x = 1; }\n" " void b() { a(); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" @@ -3762,14 +3762,14 @@ class TestClass : public TestFixture { " int x;\n" " int a() const { return x; }\n" " void b() { a(); }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:10]: (style, inconclusive) Technically the member function 'Fred::b' can be const. [functionConst]\n", errout_str()); checkConst("class Fred {\n" "public:\n" " int x;\n" " void b() { a(); }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:10]: (style) The member function 'Fred::b' can be static. [functionStatic]\n", errout_str()); // static functions can't be const.. @@ -3778,12 +3778,12 @@ class TestClass : public TestFixture { "public:\n" " static unsigned get()\n" " { return 0; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " const std::string foo() const throw() { return \"\"; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:2:23]: (style) The member function 'Fred::foo' can be static. [functionStatic]\n", errout_str()); } @@ -3793,49 +3793,49 @@ class TestClass : public TestFixture { checkConst("class Fred {\n" " std::string s;\n" " void foo() { s = \"\"; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // assignment to function argument reference can be const checkConst("class Fred {\n" " std::string s;\n" " void foo(std::string & a) { a = s; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable can't be const checkConst("class Fred {\n" " std::string s;\n" " void foo(std::string & a) { s = a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // assignment to function argument references can be const checkConst("class Fred {\n" " std::string s;\n" " void foo(std::string & a, std::string & b) { a = s; b = s; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable, can't be const checkConst("class Fred {\n" " std::string s;\n" " void foo(std::string & a, std::string & b) { s = a; s = b; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // assignment to variable, can't be const checkConst("class Fred {\n" " std::string s;\n" " void foo(std::string & a, std::string & b) { s = a; b = a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // assignment to variable, can't be const checkConst("class Fred {\n" " std::string s;\n" " void foo(std::string & a, std::string & b) { a = s; s = b; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3844,42 +3844,42 @@ class TestClass : public TestFixture { checkConst("class Fred {\n" " int s;\n" " void foo(int * a) { *a = s; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable, can't be const checkConst("class Fred {\n" " int s;\n" " void foo(int * a) { s = *a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // assignment to function argument pointers can be const checkConst("class Fred {\n" " std::string s;\n" " void foo(std::string * a, std::string * b) { *a = s; *b = s; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable, can't be const checkConst("class Fred {\n" " std::string s;\n" " void foo(std::string * a, std::string * b) { s = *a; s = *b; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // assignment to variable, can't be const checkConst("class Fred {\n" " std::string s;\n" " void foo(std::string * a, std::string * b) { s = *a; *b = s; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // assignment to variable, can't be const checkConst("class Fred {\n" " std::string s;\n" " void foo(std::string * a, std::string * b) { *a = s; s = b; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3888,14 +3888,14 @@ class TestClass : public TestFixture { " int a;\n" " int getA();\n" "};\n" - "int Fred::getA() { return a; }"); + "int Fred::getA() { return a; }\n"); ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:5:11]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\n", errout_str()); checkConst("class Fred {\n" " std::string s;\n" " const std::string & foo();\n" "};\n" - "const std::string & Fred::foo() { return \"\"; }"); + "const std::string & Fred::foo() { return \"\"; }\n"); ASSERT_EQUALS("[test.cpp:3:25] -> [test.cpp:5:27]: (style) The member function 'Fred::foo' can be static. [functionStatic]\n", errout_str()); // functions with a function call to a non-const member can't be const.. (#1305) @@ -3906,7 +3906,7 @@ class TestClass : public TestFixture { " void a() { x = 1; }\n" " void b();\n" "};\n" - "void Fred::b() { a(); }"); + "void Fred::b() { a(); }\n"); ASSERT_EQUALS("", errout_str()); // static functions can't be const.. @@ -3915,7 +3915,7 @@ class TestClass : public TestFixture { "public:\n" " static unsigned get();\n" "};\n" - "static unsigned Fred::get() { return 0; }"); + "static unsigned Fred::get() { return 0; }\n"); ASSERT_EQUALS("", errout_str()); // assignment to variable can't be const @@ -3923,7 +3923,7 @@ class TestClass : public TestFixture { " std::string s;\n" " void foo();\n" "};\n" - "void Fred::foo() { s = \"\"; }"); + "void Fred::foo() { s = \"\"; }\n"); ASSERT_EQUALS("", errout_str()); // assignment to function argument reference can be const @@ -3931,7 +3931,7 @@ class TestClass : public TestFixture { " std::string s;\n" " void foo(std::string & a);\n" "};\n" - "void Fred::foo(std::string & a) { a = s; }"); + "void Fred::foo(std::string & a) { a = s; }\n"); ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable can't be const @@ -3939,7 +3939,7 @@ class TestClass : public TestFixture { " std::string s;\n" " void foo(std::string & a);\n" "};\n" - "void Fred::foo(std::string & a) { s = a; }"); + "void Fred::foo(std::string & a) { s = a; }\n"); ASSERT_EQUALS("", errout_str()); // assignment to function argument references can be const @@ -3947,7 +3947,7 @@ class TestClass : public TestFixture { " std::string s;\n" " void foo(std::string & a, std::string & b);\n" "};\n" - "void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }"); + "void Fred::foo(std::string & a, std::string & b) { a = s; b = s; }\n"); ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable, can't be const @@ -3955,7 +3955,7 @@ class TestClass : public TestFixture { " std::string s;\n" " void foo(std::string & a, std::string & b);\n" "};\n" - "void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }"); + "void Fred::foo(std::string & a, std::string & b) { s = a; s = b; }\n"); ASSERT_EQUALS("", errout_str()); // assignment to variable, can't be const @@ -3963,7 +3963,7 @@ class TestClass : public TestFixture { " std::string s;\n" " void foo(std::string & a, std::string & b);\n" "};\n" - "void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }"); + "void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }\n"); ASSERT_EQUALS("", errout_str()); // assignment to variable, can't be const @@ -3971,7 +3971,7 @@ class TestClass : public TestFixture { " std::string s;\n" " void foo(std::string & a, std::string & b);\n" "};\n" - "void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }"); + "void Fred::foo(std::string & a, std::string & b) { a = s; s = b; }\n"); ASSERT_EQUALS("", errout_str()); // assignment to function argument pointer can be const @@ -3979,7 +3979,7 @@ class TestClass : public TestFixture { " int s;\n" " void foo(int * a);\n" "};\n" - "void Fred::foo(int * a) { *a = s; }"); + "void Fred::foo(int * a) { *a = s; }\n"); ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable, can't be const @@ -3987,7 +3987,7 @@ class TestClass : public TestFixture { " int s;\n" " void foo(int * a);\n" "};\n" - "void Fred::foo(int * a) { s = *a; }"); + "void Fred::foo(int * a) { s = *a; }\n"); ASSERT_EQUALS("", errout_str()); // assignment to function argument pointers can be const @@ -3995,7 +3995,7 @@ class TestClass : public TestFixture { " std::string s;\n" " void foo(std::string * a, std::string * b);\n" "};\n" - "void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }"); + "void Fred::foo(std::string * a, std::string * b) { *a = s; *b = s; }\n"); ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:5:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // assignment to variable, can't be const @@ -4003,7 +4003,7 @@ class TestClass : public TestFixture { " std::string s;\n" " void foo(std::string * a, std::string * b);\n" "};\n" - "void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }"); + "void Fred::foo(std::string * a, std::string * b) { s = *a; s = *b; }\n"); ASSERT_EQUALS("", errout_str()); // assignment to variable, can't be const @@ -4011,7 +4011,7 @@ class TestClass : public TestFixture { " std::string s;\n" " void foo(std::string * a, std::string * b);\n" "};\n" - "void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }"); + "void Fred::foo(std::string * a, std::string * b) { s = *a; *b = s; }\n"); ASSERT_EQUALS("", errout_str()); // assignment to variable, can't be const @@ -4019,7 +4019,7 @@ class TestClass : public TestFixture { " std::string s;\n" " void foo(std::string * a, std::string * b);\n" "};\n" - "void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }"); + "void Fred::foo(std::string * a, std::string * b) { *a = s; s = b; }\n"); ASSERT_EQUALS("", errout_str()); // check functions with same name @@ -4029,11 +4029,11 @@ class TestClass : public TestFixture { " void foo(std::string & a);\n" " void foo(const std::string & a);\n" "};\n" - "void Fred::foo() { }" - "void Fred::foo(std::string & a) { a = s; }" - "void Fred::foo(const std::string & a) { s = a; }"); + "void Fred::foo() { }\n" + "void Fred::foo(std::string & a) { a = s; }\n" + "void Fred::foo(const std::string & a) { s = a; }\n"); ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:7:12]: (style) The member function 'Fred::foo' can be static. [functionStatic]\n" - "[test.cpp:4:10] -> [test.cpp:7:32]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); + "[test.cpp:4:10] -> [test.cpp:8:12]: (style, inconclusive) Technically the member function 'Fred::foo' can be const. [functionConst]\n", errout_str()); // check functions with different or missing parameter names checkConst("class Fred {\n" @@ -4048,7 +4048,7 @@ class TestClass : public TestFixture { "void Fred::foo2(int c, int d) { }\n" "void Fred::foo3(int a, int b) { }\n" "void Fred::foo4(int a, int b) { }\n" - "void Fred::foo5(int, int) { }"); + "void Fred::foo5(int, int) { }\n"); ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:9:12]: (style) The member function 'Fred::foo1' can be static. [functionStatic]\n" "[test.cpp:4:10] -> [test.cpp:10:12]: (style) The member function 'Fred::foo2' can be static. [functionStatic]\n" "[test.cpp:5:10] -> [test.cpp:11:12]: (style) The member function 'Fred::foo3' can be static. [functionStatic]\n" @@ -4061,7 +4061,7 @@ class TestClass : public TestFixture { " int a;\n" " int getA() { return a; }\n" " };\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\n", errout_str()); checkConst("class Fred {\n" @@ -4070,7 +4070,7 @@ class TestClass : public TestFixture { " int getA();\n" " };\n" " int A::getA() { return a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:13] -> [test.cpp:6:12]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\n", errout_str()); checkConst("class Fred {\n" @@ -4079,7 +4079,7 @@ class TestClass : public TestFixture { " int getA();\n" " };\n" "};\n" - "int Fred::A::getA() { return a; }"); + "int Fred::A::getA() { return a; }\n"); ASSERT_EQUALS("[test.cpp:4:13] -> [test.cpp:7:14]: (style, inconclusive) Technically the member function 'Fred::A::getA' can be const. [functionConst]\n", errout_str()); // check deeply nested classes @@ -4092,7 +4092,7 @@ class TestClass : public TestFixture { " int getA() { return a; }\n" " };\n" " };\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:13]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\n" "[test.cpp:7:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\n" , errout_str()); @@ -4108,7 +4108,7 @@ class TestClass : public TestFixture { " int A::getA() { return a; }\n" " };\n" " int B::getB() { return b; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\n" "[test.cpp:7:17] -> [test.cpp:9:16]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\n", errout_str()); @@ -4123,7 +4123,7 @@ class TestClass : public TestFixture { " };\n" " int B::A::getA() { return a; }\n" " int B::getB() { return b; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:13] -> [test.cpp:11:12]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\n" "[test.cpp:7:17] -> [test.cpp:10:15]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\n", errout_str()); @@ -4138,7 +4138,7 @@ class TestClass : public TestFixture { " };\n" "};\n" "int Fred::B::A::getA() { return a; }\n" - "int Fred::B::getB() { return b; }"); + "int Fred::B::getB() { return b; }\n"); ASSERT_EQUALS("[test.cpp:4:13] -> [test.cpp:12:14]: (style, inconclusive) Technically the member function 'Fred::B::getB' can be const. [functionConst]\n" "[test.cpp:7:17] -> [test.cpp:11:17]: (style, inconclusive) Technically the member function 'Fred::B::A::getA' can be const. [functionConst]\n", errout_str()); } @@ -4148,7 +4148,7 @@ class TestClass : public TestFixture { checkConst("struct Fred {\n" " int a;\n" " bool operator<(const Fred &f) { return a < f.a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const. [functionConst]\n", errout_str()); } @@ -4163,7 +4163,7 @@ class TestClass : public TestFixture { " {\n" " foo << 123;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("struct Foo {\n" @@ -4175,7 +4175,7 @@ class TestClass : public TestFixture { " {\n" " std::cout << foo << 123;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Fred::x' can be const. [functionConst]\n", errout_str()); } @@ -4184,13 +4184,13 @@ class TestClass : public TestFixture { " int array[10];\n" " int const & operator [] (unsigned int index) const { return array[index]; }\n" " int & operator [] (unsigned int index) { return array[index]; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("struct Fred {\n" " int array[10];\n" " int const & operator [] (unsigned int index) { return array[index]; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:17]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const. [functionConst]\n", errout_str()); } @@ -4200,14 +4200,14 @@ class TestClass : public TestFixture { " int c;\n" "public:\n" " operator int*() { return &c; };\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class A {\n" " int c;\n" "public:\n" " operator const int*() { return &c; };\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const. [functionConst]\n", errout_str()); // #2375 @@ -4215,14 +4215,14 @@ class TestClass : public TestFixture { " int array[10];\n" " typedef int* (Fred::*UnspecifiedBoolType);\n" " operator UnspecifiedBoolType() { };\n" - "};"); + "};\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\n", "", errout_str()); checkConst("struct Fred {\n" " int array[10];\n" " typedef int* (Fred::*UnspecifiedBoolType);\n" " operator UnspecifiedBoolType() { array[0] = 0; };\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4231,21 +4231,21 @@ class TestClass : public TestFixture { " int c;\n" "public:\n" " operator int& () {return c}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class A {\n" " int c;\n" "public:\n" " operator const int& () {return c}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorconstint&' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" " int c;\n" "public:\n" " operator int () {return c}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (style, inconclusive) Technically the member function 'A::operatorint' can be const. [functionConst]\n", errout_str()); } @@ -4253,7 +4253,7 @@ class TestClass : public TestFixture { checkConst("class A {\n" " int c;\n" " void f() { os >> *this; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4267,7 +4267,7 @@ class TestClass : public TestFixture { " same = (i == a);\n" " return same;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\n", errout_str()); } @@ -4276,14 +4276,14 @@ class TestClass : public TestFixture { checkConst("class foo {\n" "public:\n" "};\n" - "void bar() {}"); + "void bar() {}\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred\n" "{\n" "public:\n" " void foo() { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:10]: (style) The member function 'Fred::foo' can be static. [functionStatic]\n", errout_str()); checkConst("struct fast_string\n" @@ -4297,7 +4297,7 @@ class TestClass : public TestFixture { "inline void fast_string::set_type(char t)\n" "{\n" " buff[10] = t;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -4308,7 +4308,7 @@ class TestClass : public TestFixture { " void set(int i) { a = i; }\n" " void set(const foo & f) { *this = f; }\n" "};\n" - "void bar() {}"); + "void bar() {}\n"); ASSERT_EQUALS("", errout_str()); } @@ -4320,7 +4320,7 @@ class TestClass : public TestFixture { " std::string strGetString() { return m_strValue; }\n" "private:\n" " std::string m_strValue;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:17]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\n", errout_str()); } @@ -4331,7 +4331,7 @@ class TestClass : public TestFixture { " void SetExitCode(wxThread::ExitCode exitcode) { m_exitcode = exitcode; }\n" "private:\n" " wxThread::ExitCode m_exitcode;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4342,7 +4342,7 @@ class TestClass : public TestFixture { " int foo() { return x = 0; }\n" "private:\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class A {\n" @@ -4350,7 +4350,7 @@ class TestClass : public TestFixture { " int foo() { return x ? x : x = 0; }\n" "private:\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class A {\n" @@ -4358,7 +4358,7 @@ class TestClass : public TestFixture { " int foo() { return x ? x = 0 : x; }\n" "private:\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4369,7 +4369,7 @@ class TestClass : public TestFixture { " void set(struct tm time) { m_time = time; }\n" "private:\n" " struct tm m_time;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4380,7 +4380,7 @@ class TestClass : public TestFixture { " int foo() { x = 0; }\n" "private:\n" " mutable int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:9]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\n", errout_str()); } @@ -4394,7 +4394,7 @@ class TestClass : public TestFixture { "private:\n" " std::vector m_vec;\n" " std::pair m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:22]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\n" "[test.cpp:5:27]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); @@ -4406,7 +4406,7 @@ class TestClass : public TestFixture { "private:\n" " std::vector m_vec;\n" " std::pair m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:30]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\n" "[test.cpp:5:35]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); } @@ -4419,7 +4419,7 @@ class TestClass : public TestFixture { " std::pair,double> GetPair() {return m_pair;}\n" "private:\n" " std::pair,double> m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" @@ -4428,7 +4428,7 @@ class TestClass : public TestFixture { " const std::pair,double>& GetPair() {return m_pair;}\n" "private:\n" " std::pair,double> m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" @@ -4437,7 +4437,7 @@ class TestClass : public TestFixture { " std::pair,double>& GetPair() {return m_pair;}\n" "private:\n" " std::pair,double> m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -4448,7 +4448,7 @@ class TestClass : public TestFixture { " pair GetPair() {return m_pair;}\n" "private:\n" " pair m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:23]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("using namespace std;" @@ -4458,7 +4458,7 @@ class TestClass : public TestFixture { " const pair & GetPair() {return m_pair;}\n" "private:\n" " pair m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("using namespace std;" @@ -4468,7 +4468,7 @@ class TestClass : public TestFixture { " pair & GetPair() {return m_pair;}\n" "private:\n" " pair m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -4478,7 +4478,7 @@ class TestClass : public TestFixture { " std::pair< int,std::vector > GetPair() {return m_pair;}\n" "private:\n" " std::pair< int,std::vector > m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:40]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" @@ -4487,7 +4487,7 @@ class TestClass : public TestFixture { " const std::pair< int,std::vector >& GetPair() {return m_pair;}\n" "private:\n" " std::pair< int,std::vector > m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:47]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" @@ -4496,7 +4496,7 @@ class TestClass : public TestFixture { " std::pair< int,std::vector >& GetPair() {return m_pair;}\n" "private:\n" " std::pair< int,std::vector > m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -4507,7 +4507,7 @@ class TestClass : public TestFixture { " pair< vector, int > GetPair() {return m_pair;}\n" "private:\n" " pair< vector, int > m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:31]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("using namespace std;" @@ -4517,7 +4517,7 @@ class TestClass : public TestFixture { " const pair< vector, int >& GetPair() {return m_pair;}\n" "private:\n" " pair< vector, int > m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:38]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("using namespace std;" @@ -4527,7 +4527,7 @@ class TestClass : public TestFixture { " pair< vector, int >& GetPair() {return m_pair;}\n" "private:\n" " pair< vector, int > m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class A {\n" @@ -4536,7 +4536,7 @@ class TestClass : public TestFixture { " std::pair< std::vector,std::vector > GetPair() {return m_pair;}\n" "private:\n" " std::pair< std::vector,std::vector > m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:53]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" @@ -4545,7 +4545,7 @@ class TestClass : public TestFixture { " const std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\n" "private:\n" " std::pair< std::vector,std::vector > m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:60]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" @@ -4554,7 +4554,7 @@ class TestClass : public TestFixture { " std::pair< std::vector,std::vector >& GetPair() {return m_pair;}\n" "private:\n" " std::pair< std::vector,std::vector > m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -4565,7 +4565,7 @@ class TestClass : public TestFixture { " std::pair< std::pair < int, char > , int > GetPair() {return m_pair;}\n" "private:\n" " std::pair< std::pair < int, char > , int > m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" @@ -4574,7 +4574,7 @@ class TestClass : public TestFixture { " const std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\n" "private:\n" " std::pair< std::pair < int, char > , int > m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" @@ -4583,7 +4583,7 @@ class TestClass : public TestFixture { " std::pair< std::pair < int, char > , int > & GetPair() {return m_pair;}\n" "private:\n" " std::pair< std::pair < int, char > , int > m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -4593,7 +4593,7 @@ class TestClass : public TestFixture { " std::pair< int , std::pair < int, char > > GetPair() {return m_pair;}\n" "private:\n" " std::pair< int , std::pair < int, char > > m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:49]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" @@ -4602,7 +4602,7 @@ class TestClass : public TestFixture { " const std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\n" "private:\n" " std::pair< int , std::pair < int, char > > m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:56]: (style, inconclusive) Technically the member function 'A::GetPair' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" @@ -4611,7 +4611,7 @@ class TestClass : public TestFixture { " std::pair< int , std::pair < int, char > >& GetPair() {return m_pair;}\n" "private:\n" " std::pair< int , std::pair < int, char > > m_pair;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -4622,7 +4622,7 @@ class TestClass : public TestFixture { " vector GetVec() {return m_Vec;}\n" "private:\n" " vector m_Vec;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:18]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\n", errout_str()); checkConst("using namespace std;" @@ -4632,7 +4632,7 @@ class TestClass : public TestFixture { " const vector& GetVec() {return m_Vec;}\n" "private:\n" " vector m_Vec;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:25]: (style, inconclusive) Technically the member function 'A::GetVec' can be const. [functionConst]\n", errout_str()); checkConst("using namespace std;" @@ -4642,7 +4642,7 @@ class TestClass : public TestFixture { " vector& GetVec() {return m_Vec;}\n" "private:\n" " vector m_Vec;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -4651,7 +4651,7 @@ class TestClass : public TestFixture { " int * * foo() { return &x; }\n" "private:\n" " const int * x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class A {\n" @@ -4659,7 +4659,7 @@ class TestClass : public TestFixture { " const int ** foo() { return &x; }\n" "private:\n" " const int * x;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:18]: (style, inconclusive) Technically the member function 'A::foo' can be const. [functionConst]\n", errout_str()); } @@ -4667,7 +4667,7 @@ class TestClass : public TestFixture { checkConst("class Fred {\n" " unsigned long long int a;\n" " unsigned long long int getA() { return a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:28]: (style, inconclusive) Technically the member function 'Fred::getA' can be const. [functionConst]\n", errout_str()); // constructors can't be const.. @@ -4675,14 +4675,14 @@ class TestClass : public TestFixture { " unsigned long long int a;\n" "public:\n" " Fred() { }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // assignment through |=.. checkConst("class Fred {\n" " unsigned long long int a;\n" " unsigned long long int setA() { a |= true; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // static functions can't be const.. @@ -4691,7 +4691,7 @@ class TestClass : public TestFixture { "public:\n" " static unsigned long long int get()\n" " { return 0; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4700,7 +4700,7 @@ class TestClass : public TestFixture { checkConst("class Fred {\n" " int a;\n" " void set(int i) { Fred::a = i; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4711,7 +4711,7 @@ class TestClass : public TestFixture { " void set(int i, int j) { a[i].k = i; }\n" "private:\n" " struct { int k; } a[4];\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4720,7 +4720,7 @@ class TestClass : public TestFixture { "static int x;\n" "public:\n" " void set(int i) { x = i; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:10]: (style) The member function 'Fred::set' can be static. [functionStatic]\n", errout_str()); } @@ -4732,7 +4732,7 @@ class TestClass : public TestFixture { " std::string s;\n" "public:\n" " void set(std::string ss) { s = ss; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4742,35 +4742,35 @@ class TestClass : public TestFixture { " int x : 3;\n" "public:\n" " void set(int i) { x = i; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " list x;\n" "public:\n" " list get() { return x; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " list x;\n" "public:\n" " list get() { return x; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:23]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\n", errout_str()); checkConst("class Fred {\n" " std::list x;\n" "public:\n" " std::list get() { return x; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " std::list x;\n" "public:\n" " std::list get() { return x; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:36]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\n", errout_str()); } @@ -4786,7 +4786,7 @@ class TestClass : public TestFixture { " for (int i = 0 ; i < 10; l1[i] = NULL, i++);\n" " }\n" " void f1() { l1[0] = \"Hello\"; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4797,7 +4797,7 @@ class TestClass : public TestFixture { " B::C * v1;\n" "public:\n" " void f1() { v1 = 0; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class A\n" @@ -4806,7 +4806,7 @@ class TestClass : public TestFixture { " B::C * v1[0];\n" "public:\n" " void f1() { v1[0] = 0; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4818,7 +4818,7 @@ class TestClass : public TestFixture { " void set_member(Type2 m) { _m = m; }\n" "private:\n" " Type2 _m;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4831,7 +4831,7 @@ class TestClass : public TestFixture { "}\n" "private:\n" " std::map *m_pSettings;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4846,7 +4846,7 @@ class TestClass : public TestFixture { "{return m_strVal.c_str();}\n" "private:\n" "std::string m_strVal;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class A{\n" @@ -4856,7 +4856,7 @@ class TestClass : public TestFixture { "{return m_strVal.c_str();}\n" "private:\n" "std::string m_strVal;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:13]: (style, inconclusive) Technically the member function 'A::strGetString' can be const. [functionConst]\n", errout_str()); checkConst("class A{\n" @@ -4866,7 +4866,7 @@ class TestClass : public TestFixture { "{return m_strVal.c_str();}\n" "private:\n" "std::string m_strVal;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:19]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const. [functionConst]\n", errout_str()); checkConst("class A{\n" @@ -4876,7 +4876,7 @@ class TestClass : public TestFixture { "{return m_strVec.size();}\n" "private:\n" "std::vector m_strVec;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:8]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const. [functionConst]\n", errout_str()); checkConst("class A{\n" @@ -4886,7 +4886,7 @@ class TestClass : public TestFixture { "{return m_strVec.empty();}\n" "private:\n" "std::vector m_strVec;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:6]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const. [functionConst]\n", errout_str()); } @@ -4897,7 +4897,7 @@ class TestClass : public TestFixture { " std::swap(delays_[index1], delays_[index2]);\n" "}\n" "float delays_[4];\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("struct DelayBase {\n" @@ -4905,7 +4905,7 @@ class TestClass : public TestFixture { " return delays_[index1];\n" " }\n" " float delays_[4];\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const. [functionConst]\n", errout_str()); } @@ -4923,7 +4923,7 @@ class TestClass : public TestFixture { " if( m_d != 0 )\n" " return m_iRealVal / m_d;\n" " return dRet;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:12] -> [test.cpp:9:12]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const. [functionConst]\n", errout_str()); } @@ -4940,7 +4940,7 @@ class TestClass : public TestFixture { " x=xPos;\n" " y=yPos;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class AA : public P {\n" @@ -4950,7 +4950,7 @@ class TestClass : public TestFixture { " {\n" " UnknownScope::x = x_;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class AA {\n" @@ -4960,7 +4960,7 @@ class TestClass : public TestFixture { " {\n" " UnknownScope::x = x_;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:17]: (style) The member function 'AA::vSetXPos' can be static. [functionStatic]\n", errout_str()); } @@ -4985,7 +4985,7 @@ class TestClass : public TestFixture { "char* test::get()\n" "{\n" " return value_;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -5000,7 +5000,7 @@ class TestClass : public TestFixture { " int get() {\n" " return a;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:7:9]: (style, inconclusive) Technically the member function 'Derived::get' can be const. [functionConst]\n", errout_str()); checkConst("class Base1 {\n" @@ -5019,7 +5019,7 @@ class TestClass : public TestFixture { " int getB() {\n" " return b;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Derived::getA' can be const. [functionConst]\n" "[test.cpp:14:9]: (style, inconclusive) Technically the member function 'Derived::getB' can be const. [functionConst]\n", errout_str()); @@ -5033,7 +5033,7 @@ class TestClass : public TestFixture { " int get() {\n" " return a;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:8:9]: (style, inconclusive) Technically the member function 'Derived2::get' can be const. [functionConst]\n", errout_str()); checkConst("class Base {\n" @@ -5048,7 +5048,7 @@ class TestClass : public TestFixture { " int get() {\n" " return a;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:10:9]: (style, inconclusive) Technically the member function 'Derived4::get' can be const. [functionConst]\n", errout_str()); // check for false positives @@ -5061,7 +5061,7 @@ class TestClass : public TestFixture { " int get() const {\n" " return a;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Base1 {\n" @@ -5080,7 +5080,7 @@ class TestClass : public TestFixture { " int getB() const {\n" " return b;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Base {\n" @@ -5093,7 +5093,7 @@ class TestClass : public TestFixture { " int get() const {\n" " return a;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Base {\n" @@ -5108,7 +5108,7 @@ class TestClass : public TestFixture { " int get() const {\n" " return a;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5118,7 +5118,7 @@ class TestClass : public TestFixture { "public:\n" " int a;\n" " int get() { return a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:9]: (style, inconclusive) Technically the member function 'Fred::get' can be const. [functionConst]\n", errout_str()); } @@ -5127,7 +5127,7 @@ class TestClass : public TestFixture { "public:\n" " std::string a[10];\n" " void seta() { a[0] = \"\"; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5135,7 +5135,7 @@ class TestClass : public TestFixture { checkConst("class derived : public base {\n" "public:\n" " void f(){}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) Either there is a missing 'override', or the member function 'derived::f' can be static. [functionStatic]\n", errout_str()); } @@ -5144,7 +5144,7 @@ class TestClass : public TestFixture { " void init(Foo * foo) {\n" " foo.bar = this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5163,7 +5163,7 @@ class TestClass : public TestFixture { " int getResourceName() { return var; }\n" " int var;\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:12:21]: (style, inconclusive) Technically the member function 'N::Derived::getResourceName' can be const. [functionConst]\n", errout_str()); checkConst("namespace N\n" @@ -5175,7 +5175,7 @@ class TestClass : public TestFixture { " int var;\n" " };\n" "}\n" - "int N::Base::getResourceName() { return var; }"); + "int N::Base::getResourceName() { return var; }\n"); ASSERT_EQUALS("[test.cpp:6:21] -> [test.cpp:10:14]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\n", errout_str()); checkConst("namespace N\n" @@ -5190,7 +5190,7 @@ class TestClass : public TestFixture { "namespace N\n" "{\n" " int Base::getResourceName() { return var; }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:21] -> [test.cpp:12:19]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\n", errout_str()); checkConst("namespace N\n" @@ -5203,7 +5203,7 @@ class TestClass : public TestFixture { " };\n" "}\n" "using namespace N;\n" - "int Base::getResourceName() { return var; }"); + "int Base::getResourceName() { return var; }\n"); ASSERT_EQUALS("[test.cpp:6:21] -> [test.cpp:11:11]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const. [functionConst]\n", errout_str()); } @@ -5215,7 +5215,7 @@ class TestClass : public TestFixture { " {\n" " m_MaxQueueSize = a_MaxQueueSize;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5230,7 +5230,7 @@ class TestClass : public TestFixture { " }\n" "private:\n" " std::string m_str;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:17]: (style, inconclusive) Technically the member function 'A::operator+' can be const. [functionConst]\n", errout_str()); checkConst("class Fred\n" @@ -5244,7 +5244,7 @@ class TestClass : public TestFixture { " bool isValid() {\n" " return (x == 0x11224488);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:9:10]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const. [functionConst]\n", errout_str()); } @@ -5260,7 +5260,7 @@ class TestClass : public TestFixture { "void Foo::MyMethod()\n" "{\n" " (*oArq) << \"\";\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -5280,7 +5280,7 @@ class TestClass : public TestFixture { "int * Foo::f()\n" "{\n" " return p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -5297,7 +5297,7 @@ class TestClass : public TestFixture { " {\n" " pView = aView;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5311,7 +5311,7 @@ class TestClass : public TestFixture { " {\n" " m_name = name;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -5323,7 +5323,7 @@ class TestClass : public TestFixture { " {\n" " pNum = apNum;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -5338,7 +5338,7 @@ class TestClass : public TestFixture { " {\n" " pNum = apNum;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -5355,7 +5355,7 @@ class TestClass : public TestFixture { " {\n" " pNum = apNum;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -5373,7 +5373,7 @@ class TestClass : public TestFixture { " {\n" " pNum = apNum;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5387,7 +5387,7 @@ class TestClass : public TestFixture { "};\n" "bool Fred::f(Fred::AB * ab)\n" "{\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:10] -> [test.cpp:7:12]: (style) The member function 'Fred::f' can be static. [functionStatic]\n", errout_str()); @@ -5401,7 +5401,7 @@ class TestClass : public TestFixture { "};\n" "bool Fred::f(Fred::AB::CD * cd)\n" "{\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:10] -> [test.cpp:9:12]: (style) The member function 'Fred::f' can be static. [functionStatic]\n", errout_str()); @@ -5417,7 +5417,7 @@ class TestClass : public TestFixture { " bool Fred::f(Fred::AB::CD * cd)\n" " {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:14] -> [test.cpp:10:16]: (style) The member function 'NS::Fred::f' can be static. [functionStatic]\n", errout_str()); @@ -5433,7 +5433,7 @@ class TestClass : public TestFixture { "}\n" "bool NS::Fred::f(NS::Fred::AB::CD * cd)\n" "{\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:14] -> [test.cpp:11:16]: (style) The member function 'NS::Fred::f' can be static. [functionStatic]\n", errout_str()); @@ -5449,7 +5449,7 @@ class TestClass : public TestFixture { "};\n" "bool Foo::Fred::f(Foo::Fred::AB::CD * cd)\n" "{\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:14] -> [test.cpp:11:17]: (style) The member function 'Foo::Fred::f' can be static. [functionStatic]\n", errout_str()); } @@ -5464,7 +5464,7 @@ class TestClass : public TestFixture { "void A::foo( AA::BB::CC::DD b )\n" "{\n" " a = b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); @@ -5488,7 +5488,7 @@ class TestClass : public TestFixture { " {\n" " a = b;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -5508,7 +5508,7 @@ class TestClass : public TestFixture { " {\n" " a = b;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5521,7 +5521,7 @@ class TestClass : public TestFixture { " {\n" " return 0 != (bOn = bOn);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5538,7 +5538,7 @@ class TestClass : public TestFixture { " {\n" " }\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:13]: (style) The member function 'tools::WorkspaceControl::toGrid' can be static. [functionStatic]\n", errout_str()); } @@ -5553,7 +5553,7 @@ class TestClass : public TestFixture { " int fun2() {\n" " b++;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:9]: (style) The member function 'Altren::fun1' can be static. [functionStatic]\n" "[test.cpp:7:9]: (style) The member function 'Altren::fun2' can be static. [functionStatic]\n", errout_str()); @@ -5565,7 +5565,7 @@ class TestClass : public TestFixture { " void foo() { delete this; }\n" " void foo(int i) const { }\n" " void bar() { foo(); }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:8]: (style) The member function 'Altren::foo' can be static. [functionStatic]\n", errout_str()); @@ -5574,7 +5574,7 @@ class TestClass : public TestFixture { " void foo() { delete this; }\n" " void foo(int i) const { }\n" " void bar() { foo(1); }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:8]: (style) The member function 'Altren::foo' can be static. [functionStatic]\n" "[test.cpp:5:8]: (style, inconclusive) Technically the member function 'Altren::bar' can be const. [functionConst]\n", errout_str()); @@ -5597,7 +5597,7 @@ class TestClass : public TestFixture { "};\n" "bool TextIterator::setTagColour() {\n" " mSave = mCurrent;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -5612,7 +5612,7 @@ class TestClass : public TestFixture { " {\n" " return _hash[key];\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5627,7 +5627,7 @@ class TestClass : public TestFixture { "{\n" " if (mTileSize.height > 0) return;\n" " if (mEmptyView) return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -5641,7 +5641,7 @@ class TestClass : public TestFixture { " void SetSection(uint num) { pesdata()[6] = num; }\n" "private:\n" " unsigned char *_pesdata;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class PESPacket {\n" @@ -5656,7 +5656,7 @@ class TestClass : public TestFixture { "{\n" "public:\n" " void SetSection(uint num) { pesdata()[6] = num; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5666,7 +5666,7 @@ class TestClass : public TestFixture { " void DoSomethingElse() { DoSomething(bar); }\n" "private:\n" " int bar;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style) The member function 'foo::DoSomething' can be static. [functionStatic]\n", errout_str()); } @@ -5682,7 +5682,7 @@ class TestClass : public TestFixture { " public:\n" " B() {};\n" " bool One(bool b = false) { return false; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5690,7 +5690,7 @@ class TestClass : public TestFixture { checkConst("class Example {\n" " public:\n" " void Clear(void) { Example tmp; (*this) = tmp; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5700,7 +5700,7 @@ class TestClass : public TestFixture { " MyObject() : tmp(0) {}\n" "public:\n" " void set(std::stringstream &in) { in >> tmp; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5710,7 +5710,7 @@ class TestClass : public TestFixture { " void foo(int x) {\n" " switch (x) { }\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'MyObject::foo' can be static. [functionStatic]\n", errout_str()); checkConst("class A\n" @@ -5750,7 +5750,7 @@ class TestClass : public TestFixture { " }\n" "\n" " return RET_NOK;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:24] -> [test.cpp:9:19]: (style) The member function 'A::f' can be static. [functionStatic]\n", errout_str()); checkConst("class MyObject {\n" @@ -5758,7 +5758,7 @@ class TestClass : public TestFixture { " void foo(int x) {\n" " for (int i = 0; i < 5; i++) { }\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'MyObject::foo' can be static. [functionStatic]\n", errout_str()); } @@ -5783,7 +5783,7 @@ class TestClass : public TestFixture { " }\n" "private:\n" " MyGUI::IntCoord mCoordValue;\n" - "};"); + "};\n"); TODO_ASSERT_EQUALS("[test.cpp:7:13]: (style) The member function 'MyGUI::types::TCoord::size' can be static. [functionStatic]\n" "[test.cpp:15]: (style, inconclusive) Technically the member function 'SelectorControl::getSize' can be const.\n", "[test.cpp:7:13]: (style) The member function 'MyGUI::types::TCoord::size' can be static. [functionStatic]\n", errout_str()); @@ -5793,7 +5793,7 @@ class TestClass : public TestFixture { " void foo(Foo f) {\n" " b.run();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("struct Bar {\n" @@ -5805,7 +5805,7 @@ class TestClass : public TestFixture { " void foo(Foo f) {\n" " b.run();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("struct Bar {\n" @@ -5816,7 +5816,7 @@ class TestClass : public TestFixture { " void foo(Foo f) {\n" " b.run();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style) The member function 'Bar::run' can be static. [functionStatic]\n" "[test.cpp:6:10]: (style, inconclusive) Technically the member function 'Foo::foo' can be const. [functionConst]\n", errout_str()); } @@ -5826,14 +5826,14 @@ class TestClass : public TestFixture { " void foo(Foo f) {\n" " f.clear();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style) The member function 'MyObject::foo' can be static. [functionStatic]\n", errout_str()); checkConst("struct MyObject {\n" " int foo(Foo f) {\n" " return f.length();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) The member function 'MyObject::foo' can be static. [functionStatic]\n", errout_str()); checkConst("struct MyObject {\n" @@ -5841,7 +5841,7 @@ class TestClass : public TestFixture { " int foo() {\n" " return f.length();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("struct MyObject {\n" @@ -5849,7 +5849,7 @@ class TestClass : public TestFixture { " int foo() {\n" " return f.length();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:9]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const. [functionConst]\n", errout_str()); } @@ -5861,7 +5861,7 @@ class TestClass : public TestFixture { "protected:\n" " int re;\n" " int im;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5876,7 +5876,7 @@ class TestClass : public TestFixture { " MyString append( const MyString& str )\n" " { return operator+=( str ); }\n" " char *m_ptr;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class MyString {\n" "public:\n" @@ -5885,7 +5885,7 @@ class TestClass : public TestFixture { " MyString append( const MyString& str )\n" " { return operator+=( str ); }\n" " char *m_ptr;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5896,14 +5896,14 @@ class TestClass : public TestFixture { "};\n" "int MixerParticipant::GetAudioFrame() {\n" " return 0;\n" - "}"); + "}\n"); // this code is invalid so a false negative is OK checkConst("class MixerParticipant : public MixerParticipant {\n" " bool InitializeFileReader() {\n" " printf(\"music\");\n" " }\n" - "};"); + "};\n"); // Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc() // A more complete example including a template declaration like @@ -5936,7 +5936,7 @@ class TestClass : public TestFixture { " {\n" " return _hash[key];\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -5947,7 +5947,7 @@ class TestClass : public TestFixture { " std::string* p = &s;\n" " p->clear();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("struct A {\n" @@ -5956,7 +5956,7 @@ class TestClass : public TestFixture { " std::string& r = s;\n" " r.clear();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("struct A {\n" @@ -5965,7 +5965,7 @@ class TestClass : public TestFixture { " std::string& r = sth; r = s;\n" " r.clear();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\n", errout_str()); checkConst("struct A {\n" @@ -5974,7 +5974,7 @@ class TestClass : public TestFixture { " const std::string* p = &s;\n" " p->somefunction();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\n", errout_str()); checkConst("struct A {\n" @@ -5983,7 +5983,7 @@ class TestClass : public TestFixture { " const std::string& r = s;\n" " r.somefunction();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style, inconclusive) Technically the member function 'A::clear' can be const. [functionConst]\n", errout_str()); } @@ -5998,7 +5998,7 @@ class TestClass : public TestFixture { " }\n" " ::B::D::DKIPtr membervariable;\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -6017,7 +6017,7 @@ class TestClass : public TestFixture { " TemplateClass a;\n" " TemplateClass b;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -6027,7 +6027,7 @@ class TestClass : public TestFixture { " void f(int v) { g((char *) &v); }\n" " void g(char *) { n++; }\n" " int n;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -6041,7 +6041,7 @@ class TestClass : public TestFixture { "public:\n" " const std::list>& get() { return m_test.m_list; }\n" " TestList> m_test;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:8:44]: (style, inconclusive) Technically the member function 'Test::get' can be const. [functionConst]\n", errout_str()); } @@ -6071,7 +6071,7 @@ class TestClass : public TestFixture { " call();\n" " call(1, 2, 3);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -6084,7 +6084,7 @@ class TestClass : public TestFixture { " void test() {\n" " call(1, 2);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -6219,7 +6219,7 @@ class TestClass : public TestFixture { " void bar(void) {\n" " for(std::vector::const_iterator it = m_str.begin(); it != m_str.end(); ++it) {;}\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:10]: (style, inconclusive) Technically the member function 'A::bar' can be const. [functionConst]\n", errout_str()); // Don't crash @@ -7074,7 +7074,7 @@ class TestClass : public TestFixture { " int bar6() {\n" " return foo3();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:11:9]: (style) The member function 'Foo::bar3' can be static. [functionStatic]\n" "[test.cpp:14:9]: (style) The member function 'Foo::bar4' can be static. [functionStatic]\n", errout_str()); } @@ -7085,7 +7085,7 @@ class TestClass : public TestFixture { " Bar b;\n" " b.takeFoo(this);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("struct Foo {\n" @@ -7093,7 +7093,7 @@ class TestClass : public TestFixture { " Foo f;\n" " f.foo();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style) The member function 'Foo::foo' can be static. [functionStatic]\n", errout_str()); checkConst("struct A;\n" // #5839 - operator() @@ -7104,7 +7104,7 @@ class TestClass : public TestFixture { " void dostuff() {\n" " B()(this);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -7116,7 +7116,7 @@ class TestClass : public TestFixture { " {\n" " v = 0;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -7128,7 +7128,7 @@ class TestClass : public TestFixture { " {\n" " v[0] = \"Happy new year!\";\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -7137,49 +7137,49 @@ class TestClass : public TestFixture { checkConst("class Fred {\n" " int a;\n" " void nextA() { return ++a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " int a;\n" " void nextA() { return --a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " int a;\n" " void nextA() { return a++; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " int a;\n" " void nextA() { return a--; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return ++a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return --a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return a++; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return a--; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("struct S {\n" // #10077 @@ -7195,61 +7195,61 @@ class TestClass : public TestFixture { checkConst("class Fred {\n" " int a;\n" " void nextA() { return a=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " int a;\n" " void nextA() { return a-=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " int a;\n" " void nextA() { return a+=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " int a;\n" " void nextA() { return a*=-1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " int a;\n" " void nextA() { return a/=-2; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return a=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return a-=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return a+=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return a*=-1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("int a;\n" "class Fred {\n" " void nextA() { return a/=-2; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); } @@ -7257,90 +7257,90 @@ class TestClass : public TestFixture { checkConst("class Fred {\n" " struct A { int a; } s;\n" " void nextA() { return s.a=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " struct A { int a; } s;\n" " void nextA() { return s.a-=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " struct A { int a; } s;\n" " void nextA() { return s.a+=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " struct A { int a; } s;\n" " void nextA() { return s.a*=-1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("struct A { int a; } s;\n" "class Fred {\n" " void nextA() { return s.a=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("struct A { int a; } s;\n" "class Fred {\n" " void nextA() { return s.a-=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("struct A { int a; } s;\n" "class Fred {\n" " void nextA() { return s.a+=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("struct A { int a; } s;\n" "class Fred {\n" " void nextA() { return s.a*=-1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("struct A { int a; } s;\n" "class Fred {\n" " void nextA() { return s.a/=-2; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("struct A { int a; };\n" "class Fred {\n" " A s;\n" " void nextA() { return s.a=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("struct A { int a; };\n" "class Fred {\n" " A s;\n" " void nextA() { return s.a-=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("struct A { int a; };\n" "class Fred {\n" " A s;\n" " void nextA() { return s.a+=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("struct A { int a; };\n" "class Fred {\n" " A s;\n" " void nextA() { return s.a*=-1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("struct A { int a; };\n" "class Fred {\n" " A s;\n" " void nextA() { return s.a/=-2; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -7349,49 +7349,49 @@ class TestClass : public TestFixture { checkConst("class Fred {\n" " int a[2];\n" " void nextA() { return ++a[0]; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " int a[2];\n" " void nextA() { return --a[0]; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " int a[2];\n" " void nextA() { return a[0]++; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " int a[2];\n" " void nextA() { return a[0]--; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return ++a[0]; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return --a[0]; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return a[0]++; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return a[0]--; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); } @@ -7399,61 +7399,61 @@ class TestClass : public TestFixture { checkConst("class Fred {\n" " int a[2];\n" " void nextA() { return a[0]=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " int a[2];\n" " void nextA() { return a[0]-=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " int a[2];\n" " void nextA() { return a[0]+=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " int a[2];\n" " void nextA() { return a[0]*=-1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class Fred {\n" " int a[2];\n" " void nextA() { return a[0]/=-2; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return a[0]=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return a[0]-=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return a[0]+=1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return a[0]*=-1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); checkConst("int a[2];\n" "class Fred {\n" " void nextA() { return a[0]/=-2; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'Fred::nextA' can be static. [functionStatic]\n", errout_str()); } @@ -7462,8 +7462,8 @@ class TestClass : public TestFixture { checkConst("class Fred {\n" " int a;\n" " int &getR() { return a; }\n" - " int *getP() { return &a; }" - "};"); + " int *getP() { return &a; }\n" + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -7472,7 +7472,7 @@ class TestClass : public TestFixture { checkConst("class Fred {\n" " int *a;\n" " void clean() { delete a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -7480,14 +7480,14 @@ class TestClass : public TestFixture { void constLPVOID() { checkConst("class Fred {\n" " UNKNOWN a() { return 0; };\n" - "};"); + "};\n"); TODO_ASSERT_EQUALS("[test.cpp:2]: (style) The member function 'Fred::a' can be static.\n", "", errout_str()); // #1579 - HDC checkConst("class Fred {\n" " foo bar;\n" " UNKNOWN a() { return b; };\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -7496,7 +7496,7 @@ class TestClass : public TestFixture { checkConst("class Fred {\n" " void f() const { };\n" " void a() { f(); };\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style) The member function 'Fred::f' can be static. [functionStatic]\n" "[test.cpp:3:10]: (style, inconclusive) Technically the member function 'Fred::a' can be const. [functionConst]\n", errout_str()); @@ -7507,7 +7507,7 @@ class TestClass : public TestFixture { "public:\n" " A(){}\n" " unsigned int GetVecSize() {return m_v.size();}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:17]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const. [functionConst]\n", errout_str()); checkConst("class A\n" @@ -7516,7 +7516,7 @@ class TestClass : public TestFixture { "public:\n" " A(){}\n" " bool GetVecEmpty() {return m_v.empty();}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:9]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const. [functionConst]\n", errout_str()); } @@ -7528,7 +7528,7 @@ class TestClass : public TestFixture { "public:\n" " B() : b(0) { }\n" " int func() { return b; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\n", errout_str()); checkConst("class A { };\n" @@ -7538,7 +7538,7 @@ class TestClass : public TestFixture { " B() : b(0) { }\n" " int func();\n" "};\n" - "int B::func() { return b; }"); + "int B::func() { return b; }\n"); ASSERT_EQUALS("[test.cpp:6:8] -> [test.cpp:8:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\n", errout_str()); // base class has no virtual function @@ -7551,7 +7551,7 @@ class TestClass : public TestFixture { "public:\n" " B() : b(0) { }\n" " int func() { return b; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:9:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\n", errout_str()); checkConst("class A {\n" @@ -7564,7 +7564,7 @@ class TestClass : public TestFixture { " B() : b(0) { }\n" " int func();\n" "};\n" - "int B::func() { return b; }"); + "int B::func() { return b; }\n"); ASSERT_EQUALS("[test.cpp:9:9] -> [test.cpp:11:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\n", errout_str()); // base class has virtual function @@ -7577,7 +7577,7 @@ class TestClass : public TestFixture { "public:\n" " B() : b(0) { }\n" " int func() { return b; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class A {\n" @@ -7590,7 +7590,7 @@ class TestClass : public TestFixture { " B() : b(0) { }\n" " int func();\n" "};\n" - "int B::func() { return b; }"); + "int B::func() { return b; }\n"); ASSERT_EQUALS("", errout_str()); checkConst("class A {\n" @@ -7603,7 +7603,7 @@ class TestClass : public TestFixture { " B() : b(0) { }\n" " int func();\n" "};\n" - "int B::func() { return b; }"); + "int B::func() { return b; }\n"); ASSERT_EQUALS("", errout_str()); // base class has no virtual function @@ -7624,7 +7624,7 @@ class TestClass : public TestFixture { "public:\n" " C() : c(0) { }\n" " int func() { return c; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:9]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\n" "[test.cpp:11:9]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\n" "[test.cpp:17:9]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\n", errout_str()); @@ -7649,7 +7649,7 @@ class TestClass : public TestFixture { " C() : c(0) { }\n" " int func();\n" "};\n" - "int C::func() { return c; }"); + "int C::func() { return c; }\n"); ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'A::func' can be const. [functionConst]\n" "[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'B::func' can be const. [functionConst]\n" "[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'C::func' can be const. [functionConst]\n", errout_str()); @@ -7672,7 +7672,7 @@ class TestClass : public TestFixture { "public:\n" " C() : c(0) { }\n" " int func() { return c; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkConst("class A {\n" @@ -7695,7 +7695,7 @@ class TestClass : public TestFixture { " C() : c(0) { }\n" " int func();\n" "};\n" - "int C::func() { return c; }"); + "int C::func() { return c; }\n"); ASSERT_EQUALS("", errout_str()); // ticket #1311 @@ -7716,7 +7716,7 @@ class TestClass : public TestFixture { "public:\n" " Z(int x, int y, int z) : Y(x, y), z(z) { }\n" " int getZ() { return z; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:9]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\n" "[test.cpp:11:9]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\n" "[test.cpp:17:9]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\n", errout_str()); @@ -7741,7 +7741,7 @@ class TestClass : public TestFixture { " Z(int x, int y, int z) : Y(x, y), z(z) { }\n" " int getZ();\n" "};\n" - "int Z::getZ() { return z; }"); + "int Z::getZ() { return z; }\n"); ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:7:8]: (style, inconclusive) Technically the member function 'X::getX' can be const. [functionConst]\n" "[test.cpp:12:9] -> [test.cpp:14:8]: (style, inconclusive) Technically the member function 'Y::getY' can be const. [functionConst]\n" "[test.cpp:19:9] -> [test.cpp:21:8]: (style, inconclusive) Technically the member function 'Z::getZ' can be const. [functionConst]\n", errout_str()); @@ -7755,7 +7755,7 @@ class TestClass : public TestFixture { //" i = 4;\n" //"endif\n" " }\n" - "};"; + "};\n"; checkConst(code); ASSERT_EQUALS("[test.cpp:3:10]: (style) The member function 'foo::f' can be static. [functionStatic]\n", errout_str()); @@ -7767,7 +7767,7 @@ class TestClass : public TestFixture { void constFriend() { // ticket #1921 const char code[] = "class foo {\n" " friend void f() { }\n" - "};"; + "};\n"; checkConst(code); ASSERT_EQUALS("", errout_str()); } @@ -7782,7 +7782,7 @@ class TestClass : public TestFixture { " void setf(float x) {\n" " d.f = x;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -7799,7 +7799,7 @@ class TestClass : public TestFixture { " T c() {\n" " return y[1][6];\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:10:7]: (style, inconclusive) Technically the member function 'foo::c' can be const. [functionConst]\n", errout_str()); } @@ -7819,7 +7819,7 @@ class TestClass : public TestFixture { " for (decltype(auto) e : array)\n" " foo(e);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:8:10]: (style, inconclusive) Technically the member function 'Fred::f2' can be const. [functionConst]\n", errout_str()); checkConst("struct T {\n" // #14390 @@ -7844,7 +7844,7 @@ class TestClass : public TestFixture { " std::shared_ptr data;\n" "};\n" "\n" - "std::shared_ptr Fred::getData() { return data; }"); + "std::shared_ptr Fred::getData() { return data; }\n"); ASSERT_EQUALS("", errout_str()); } @@ -7852,7 +7852,7 @@ class TestClass : public TestFixture { checkConst("class Fred {\n" "public:\n" " const char *const *data;\n" - " const char *const *getData() { return data; }\n}"); + " const char *const *getData() { return data; }\n}\n"); ASSERT_EQUALS("[test.cpp:4:24]: (style, inconclusive) Technically the member function 'Fred::getData' can be const. [functionConst]\n", errout_str()); } @@ -7860,7 +7860,7 @@ class TestClass : public TestFixture { checkConst("struct A {\n" " int x = 1;\n" " auto get() -> int & { return x; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -7919,7 +7919,7 @@ class TestClass : public TestFixture { " int a, b, c;\n" "public:\n" " Fred() : c(0), b(0), a(0) { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\n" "[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\n", errout_str()); @@ -7927,14 +7927,14 @@ class TestClass : public TestFixture { " int a, b, c;\n" "public:\n" " Fred() : c{0}, b{0}, a{0} { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:20] -> [test.cpp:2:12]: (style, inconclusive) Member variable 'Fred::b' is in the wrong place in the initializer list. [initializerList]\n" "[test.cpp:4:26] -> [test.cpp:2:9]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list. [initializerList]\n", errout_str()); checkInitializerListOrder("struct S {\n" " S() : b(a = 1) {}\n" " int a, b;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializerListOrder("struct S {\n" @@ -7957,7 +7957,7 @@ class TestClass : public TestFixture { " : B(\"abc\", s.nRows(), s.nCols())\n" " , m_i(_i)\n" " {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -7968,41 +7968,41 @@ class TestClass : public TestFixture { " C() : b(&a) {}\n" " B b;\n" " const A a;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:11] -> [test.cpp:5:7]: (style, inconclusive) Member variable 'C::b' uses an uninitialized argument 'a' due to the order of declarations. [initializerList]\n", errout_str()); checkInitializerListOrder("struct S {\n" " S(const std::string& f, std::string i, int b, int c) : a(0), b(b), c(c) {}\n" " int a, b, c;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializerListOrder("struct S {\n" " S() : p(a) {}\n" " int* p;\n" " int a[1];\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializerListOrder("struct S {\n" " S() : p(&i) {}\n" " int* p;\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializerListOrder("struct S {\n" " S() : a(b = 1) {}\n" " int a, b;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializerListOrder("struct S {\n" " S() : r(i) {}\n" " int& r;\n" " int i{};\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializerListOrder("struct B {\n" @@ -8011,7 +8011,7 @@ class TestClass : public TestFixture { "struct D : B {\n" " D() : B(), j(b) {}\n" " int j;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializerListOrder("struct S {\n" @@ -8019,13 +8019,13 @@ class TestClass : public TestFixture { " int a;\n" " static int i;\n" "};\n" - "int S::i = 0;"); + "int S::i = 0;\n"); ASSERT_EQUALS("", errout_str()); checkInitializerListOrder("struct S {\n" " S(int b) : a(b) {}\n" " int a, b{};\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializerListOrder("class Foo {\n" // #3524 @@ -8075,113 +8075,113 @@ class TestClass : public TestFixture { " int* b;\n" // No message for pointers: No performance gain " Enum c;\n" // No message for enums: No performance gain " Fred() { a = 0; b = 0; c = C; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("class Fred {\n" " std::string s;\n" " Fred() { a = 0; s = \"foo\"; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:21]: (performance) Variable 's' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\n", errout_str()); checkInitializationListUsage("class Fred {\n" " std::string& s;\n" // Message is invalid for references, since their initialization in initializer list is required anyway and behaves different from assignment (#5004) " Fred(const std::string& s_) : s(s_) { s = \"foo\"; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("class Fred {\n" " std::vector v;\n" " Fred() { v = unknown; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:14]: (performance) Variable 'v' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\n", errout_str()); checkInitializationListUsage("class C { std::string s; };\n" "class Fred {\n" " C c;\n" " Fred() { c = unknown; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\n", errout_str()); checkInitializationListUsage("class C;\n" "class Fred {\n" " C c;\n" " Fred() { c = unknown; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:14]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\n", errout_str()); checkInitializationListUsage("class C;\n" "class Fred {\n" " C c;\n" " Fred(Fred const & other) { c = other.c; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:32]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\n", errout_str()); checkInitializationListUsage("class C;\n" "class Fred {\n" " C c;\n" " Fred(Fred && other) { c = other.c; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:27]: (performance) Variable 'c' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\n", errout_str()); checkInitializationListUsage("class C;\n" "class Fred {\n" " C a;\n" " Fred() { initB(); a = b; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("class C;\n" "class Fred {\n" " C a;\n" " Fred() : a(0) { if(b) a = 0; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("class C;\n" "class Fred {\n" " C a[5];\n" " Fred() { for(int i = 0; i < 5; i++) a[i] = 0; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("class C;\n" "class Fred {\n" " C a; int b;\n" " Fred() : b(5) { a = b; }\n" // Don't issue a message here: You actually could move it to the initialization list, but it would cause problems if you change the order of the variable declarations. - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("class C;\n" "class Fred {\n" " C a;\n" " Fred() { try { a = new int; } catch(...) {} }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("class Fred {\n" " std::string s;\n" " Fred() { s = toString((size_t)this); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("class Fred {\n" " std::string a;\n" " std::string foo();\n" " Fred() { a = foo(); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("class Fred {\n" " std::string a;\n" " Fred() { a = foo(); }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:14]: (performance) Variable 'a' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]\n", errout_str()); checkInitializationListUsage("class Fred {\n" // #4332 " static std::string s;\n" " Fred() { s = \"foo\"; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("class Fred {\n" // #5640 @@ -8192,7 +8192,7 @@ class TestClass : public TestFixture { " str[1] = 0;\n" " s = str;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("class B {\n" // #5640 @@ -8200,7 +8200,7 @@ class TestClass : public TestFixture { " B(const B& other) : _d(std::make_shared()) {\n" " *_d = *other._d;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("class Bar {\n" // #8466 @@ -8209,7 +8209,7 @@ class TestClass : public TestFixture { " explicit Bar(const char s) : s{s} {}\n" "private:\n" " char s;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("unsigned bar(std::string);\n" // #8291 @@ -8218,7 +8218,7 @@ class TestClass : public TestFixture { " int a_, b_;\n" " Foo(int a, int b) : a_(a), b_(b) {}\n" " Foo(int a, const std::string& b) : Foo(a, bar(b)) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("class Fred {\n" // #8111 @@ -8228,7 +8228,7 @@ class TestClass : public TestFixture { " ostr << x;\n" " a = ostr.str();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // bailout: multi line lambda in rhs => do not warn @@ -8239,7 +8239,7 @@ class TestClass : public TestFixture { " return 1;\n" " };\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // don't warn if some other instance's members are assigned to @@ -8248,7 +8248,7 @@ class TestClass : public TestFixture { " C(C& c) : m_i(c.m_i) { c.m_i = (Foo)-1; }\n" "private:\n" " Foo m_i;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("class A {\n" // #9821 - delegate constructor @@ -8261,7 +8261,7 @@ class TestClass : public TestFixture { "\n" "private:\n" " std::string st;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkInitializationListUsage("struct S {\n" // #14189 @@ -8276,7 +8276,7 @@ class TestClass : public TestFixture { " p = std::make_unique(s);\n" " }\n" " std::unique_ptr p;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -8297,14 +8297,14 @@ class TestClass : public TestFixture { " int i;\n" " Fred() : i(i) {\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\n", errout_str()); checkSelfInitialization("class Fred {\n" " int i;\n" " Fred() : i{i} {\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:12]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\n", errout_str()); checkSelfInitialization("class Fred {\n" @@ -8312,7 +8312,7 @@ class TestClass : public TestFixture { " Fred();\n" "};\n" "Fred::Fred() : i(i) {\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:14]: (error) Member variable 'i' is initialized by itself. [selfInitialization]\n", errout_str()); checkSelfInitialization("class A {\n" // #10427 @@ -8335,56 +8335,56 @@ class TestClass : public TestFixture { " std::string s;\n" " Fred() : s(s) {\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:12]: (error) Member variable 's' is initialized by itself. [selfInitialization]\n", errout_str()); checkSelfInitialization("class Fred {\n" " int x;\n" " Fred(int x);\n" "};\n" - "Fred::Fred(int x) : x(x) { }"); + "Fred::Fred(int x) : x(x) { }\n"); ASSERT_EQUALS("", errout_str()); checkSelfInitialization("class Fred {\n" " int x;\n" " Fred(int x);\n" "};\n" - "Fred::Fred(int x) : x{x} { }"); + "Fred::Fred(int x) : x{x} { }\n"); ASSERT_EQUALS("", errout_str()); checkSelfInitialization("class Fred {\n" " std::string s;\n" " Fred(const std::string& s) : s(s) {\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkSelfInitialization("class Fred {\n" " std::string s;\n" " Fred(const std::string& s) : s{s} {\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkSelfInitialization("struct Foo : Bar {\n" " int i;\n" " Foo(int i)\n" " : Bar(\"\"), i(i) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkSelfInitialization("struct Foo : std::Bar {\n" // #6073 " int i;\n" " Foo(int i)\n" " : std::Bar(\"\"), i(i) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkSelfInitialization("struct Foo : std::Bar {\n" // #6073 " int i;\n" " Foo(int i)\n" " : std::Bar(\"\"), i{i} {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -8409,21 +8409,21 @@ class TestClass : public TestFixture { " A();\n" "};\n" "A::A()\n" - "{f();}"); + "{f();}\n"); ASSERT_EQUALS("[test.cpp:7:2] -> [test.cpp:3:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used. [virtualCallInConstructor]\n", errout_str()); checkVirtualFunctionCall("class A {\n" " virtual int f();\n" " A() {f();}\n" "};\n" - "int A::f() { return 1; }"); + "int A::f() { return 1; }\n"); ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:2:17]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\n", errout_str()); checkVirtualFunctionCall("class A : B {\n" " int f() override;\n" " A() {f();}\n" "};\n" - "int A::f() { return 1; }"); + "int A::f() { return 1; }\n"); ASSERT_EQUALS("[test.cpp:3:10] -> [test.cpp:2:9]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used. [virtualCallInConstructor]\n", errout_str()); checkVirtualFunctionCall("class B {\n" @@ -8433,14 +8433,14 @@ class TestClass : public TestFixture { " int f();\n" // <- not explicitly virtual " A() {f();}\n" "};\n" - "int A::f() { return 1; }"); + "int A::f() { return 1; }\n"); ASSERT_EQUALS("", errout_str()); checkVirtualFunctionCall("class A\n" "{\n" " A() { A::f(); }\n" " virtual void f() {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkVirtualFunctionCall("class A : B {\n" @@ -8526,7 +8526,7 @@ class TestClass : public TestFixture { " A();\n" "};\n" "A::A()\n" - "{pure();}"); + "{pure();}\n"); ASSERT_EQUALS("[test.cpp:7:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\n", errout_str()); checkVirtualFunctionCall("class A\n" @@ -8536,7 +8536,7 @@ class TestClass : public TestFixture { " int m;\n" "};\n" "A::A():m(A::pure())\n" - "{}"); + "{}\n"); ASSERT_EQUALS("[test.cpp:7:13] -> [test.cpp:3:17]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\n", errout_str()); checkVirtualFunctionCall("namespace N {\n" @@ -8557,7 +8557,7 @@ class TestClass : public TestFixture { " int m;\n" "};\n" "A::~A()\n" - "{pure();}"); + "{pure();}\n"); ASSERT_EQUALS("[test.cpp:8:2] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\n", errout_str()); checkVirtualFunctionCall("class A\n" @@ -8568,7 +8568,7 @@ class TestClass : public TestFixture { " A();\n" "};\n" "A::A()\n" - "{nonpure();}"); + "{nonpure();}\n"); ASSERT_EQUALS("[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\n", errout_str()); checkVirtualFunctionCall("class A\n" @@ -8580,7 +8580,7 @@ class TestClass : public TestFixture { " int m;\n" "};\n" "A::A():m(nonpure())\n" - "{}"); + "{}\n"); TODO_ASSERT_EQUALS("[test.cpp:9:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\n", "", errout_str()); checkVirtualFunctionCall("class A\n" @@ -8592,7 +8592,7 @@ class TestClass : public TestFixture { " int m;\n" "};\n" "A::~A()\n" - "{nonpure();}"); + "{nonpure();}\n"); ASSERT_EQUALS("[test.cpp:10:2] -> [test.cpp:5:6] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\n", errout_str()); checkVirtualFunctionCall("class A\n" @@ -8601,7 +8601,7 @@ class TestClass : public TestFixture { " A(bool b);\n" "};\n" "A::A(bool b)\n" - "{if (b) pure();}"); + "{if (b) pure();}\n"); ASSERT_EQUALS("[test.cpp:7:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in constructor. [pureVirtualCall]\n", errout_str()); checkVirtualFunctionCall("class A\n" @@ -8611,7 +8611,7 @@ class TestClass : public TestFixture { " int m;\n" "};\n" "A::~A()\n" - "{if (b) pure();}"); + "{if (b) pure();}\n"); ASSERT_EQUALS("[test.cpp:8:9] -> [test.cpp:3:18]: (warning) Call of pure virtual function 'pure' in destructor. [pureVirtualCall]\n", errout_str()); // #5831 @@ -8619,7 +8619,7 @@ class TestClass : public TestFixture { "public:\n" " virtual ~abc() throw() {}\n" " virtual void def(void* g) throw () = 0;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // #4992 @@ -8630,7 +8630,7 @@ class TestClass : public TestFixture { " m_callback = [this]() { return VirtualMethod(); };\n" " }\n" " virtual void VirtualMethod() = 0;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // #10559 @@ -8649,7 +8649,7 @@ class TestClass : public TestFixture { " A(const A & a);\n" "};\n" "A::A(const A & a)\n" - "{a.pure();}"); + "{a.pure();}\n"); ASSERT_EQUALS("", errout_str()); checkVirtualFunctionCall("class A\n" @@ -8662,7 +8662,7 @@ class TestClass : public TestFixture { " virtual void pure()=0;\n" "};\n" "A::A()\n" - "{B b; b.pure();}"); + "{B b; b.pure();}\n"); ASSERT_EQUALS("", errout_str()); } @@ -8675,7 +8675,7 @@ class TestClass : public TestFixture { "A::A()\n" "{pureWithBody();}\n" "void A::pureWithBody()\n" - "{}"); + "{}\n"); ASSERT_EQUALS("", errout_str()); checkVirtualFunctionCall("class A\n" @@ -8688,7 +8688,7 @@ class TestClass : public TestFixture { "A::A()\n" "{nonpure();}\n" "void A::pureWithBody()\n" - "{}"); + "{}\n"); ASSERT_EQUALS("", errout_str()); } @@ -8702,7 +8702,7 @@ class TestClass : public TestFixture { " A();\n" "};\n" "A::A()\n" - "{nonpure(false);}"); + "{nonpure(false);}\n"); ASSERT_EQUALS("", errout_str()); checkVirtualFunctionCall("class A\n" @@ -8713,7 +8713,7 @@ class TestClass : public TestFixture { " A();\n" "};\n" "A::A()\n" - "{nonpure(false);}"); + "{nonpure(false);}\n"); ASSERT_EQUALS("", errout_str()); checkVirtualFunctionCall("class A\n" @@ -8728,7 +8728,7 @@ class TestClass : public TestFixture { " A();\n" "};\n" "A::A()\n" - "{nonpure(false);}"); + "{nonpure(false);}\n"); ASSERT_EQUALS("", errout_str()); } @@ -8749,15 +8749,15 @@ class TestClass : public TestFixture { void override1() { checkOverride("class Base { virtual void f(); };\n" - "class Derived : Base { virtual void f(); };"); + "class Derived : Base { virtual void f(); };\n"); ASSERT_EQUALS("[test.cpp:1:27] -> [test.cpp:2:37]: (style) The function 'f' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\n", errout_str()); checkOverride("class Base { virtual void f(); };\n" - "class Derived : Base { virtual void f() override; };"); + "class Derived : Base { virtual void f() override; };\n"); ASSERT_EQUALS("", errout_str()); checkOverride("class Base { virtual void f(); };\n" - "class Derived : Base { virtual void f() final; };"); + "class Derived : Base { virtual void f() final; };\n"); ASSERT_EQUALS("", errout_str()); checkOverride("class Base {\n" @@ -8769,7 +8769,7 @@ class TestClass : public TestFixture { "public :\n" " auto foo( ) const -> size_t { return 0; }\n" " auto bar( ) const -> size_t override { return 0; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:18] -> [test.cpp:8:10]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier. [missingOverride]\n", errout_str()); checkOverride("namespace Test {\n" @@ -8781,7 +8781,7 @@ class TestClass : public TestFixture { "class C : Test::C {\n" "public:\n" " ~C();\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:18] -> [test.cpp:9:6]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]\n", errout_str()); checkOverride("struct Base {\n" @@ -8791,7 +8791,7 @@ class TestClass : public TestFixture { "struct Derived: public Base {\n" " void foo() override;\n" " void foo(int);\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOverride("struct B {\n" // #9092 @@ -8929,19 +8929,19 @@ class TestClass : public TestFixture { void overrideCVRefQualifiers() { checkOverride("class Base { virtual void f(); };\n" - "class Derived : Base { void f() const; }"); + "class Derived : Base { void f() const; }\n"); ASSERT_EQUALS("", errout_str()); checkOverride("class Base { virtual void f(); };\n" - "class Derived : Base { void f() volatile; }"); + "class Derived : Base { void f() volatile; }\n"); ASSERT_EQUALS("", errout_str()); checkOverride("class Base { virtual void f(); };\n" - "class Derived : Base { void f() &; }"); + "class Derived : Base { void f() &; }\n"); ASSERT_EQUALS("", errout_str()); checkOverride("class Base { virtual void f(); };\n" - "class Derived : Base { void f() &&; }"); + "class Derived : Base { void f() &&; }\n"); ASSERT_EQUALS("", errout_str()); } @@ -8963,51 +8963,51 @@ class TestClass : public TestFixture { checkUselessOverride("struct B { virtual int f() { return 5; } };\n" // #11757 "struct D : B {\n" " int f() override { return B::f(); }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\n", errout_str()); checkUselessOverride("struct B { virtual void f(); };\n" "struct D : B {\n" " void f() override { B::f(); }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:1:25] -> [test.cpp:3:10]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\n", errout_str()); checkUselessOverride("struct B { virtual int f() = 0; };\n" "int B::f() { return 5; }\n" "struct D : B {\n" " int f() override { return B::f(); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkUselessOverride("struct B { virtual int f(int i); };\n" "struct D : B {\n" " int f(int i) override { return B::f(i); }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:1:24] -> [test.cpp:3:9]: (style) The function 'f' overrides a function in a base class but just delegates back to the base class. [uselessOverride]\n", errout_str()); checkUselessOverride("struct B { virtual int f(int i); };\n" "struct D : B {\n" " int f(int i) override { return B::f(i + 1); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkUselessOverride("struct B { virtual int f(int i, int j); };\n" "struct D : B {\n" " int f(int i, int j) override { return B::f(j, i); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkUselessOverride("struct B { virtual int f(); };\n" "struct I { virtual int f() = 0; };\n" "struct D : B, I {\n" " int f() override { return B::f(); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkUselessOverride("struct S { virtual void f(); };\n" "struct D : S {\n" " void f() final { S::f(); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkUselessOverride("struct S {\n" @@ -9017,7 +9017,7 @@ class TestClass : public TestFixture { "struct D : S {\n" "public:\n" " void f() override { S::f(); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkUselessOverride("struct B { virtual void f(int, int, int) const; };\n" // #11799 @@ -9027,7 +9027,7 @@ class TestClass : public TestFixture { "};\n" "void D::f(int a, int b, int c) const {\n" " B::f(a, b, m);\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkUselessOverride("struct B {\n" // #11803 @@ -9038,7 +9038,7 @@ class TestClass : public TestFixture { " void f() override { B::f(); }\n" " void f(int i) override;\n" " void g() { f(); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkUselessOverride("struct B { virtual void f(); };\n" // #11808 @@ -9047,7 +9047,7 @@ class TestClass : public TestFixture { " void f() override {\n" " B::f();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkUselessOverride("struct B {\n" @@ -9061,7 +9061,7 @@ class TestClass : public TestFixture { " int g() override { return 7; }\n" " int h(int j, int i) override { return i + j; }\n" " int j(int i, int j) override { return i + j; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:17] -> [test.cpp:9:9]: (style) The function 'g' overrides a function in a base class but is identical to the overridden function [uselessOverride]\n" "[test.cpp:5:17] -> [test.cpp:11:9]: (style) The function 'j' overrides a function in a base class but is identical to the overridden function [uselessOverride]\n", errout_str()); @@ -9150,7 +9150,7 @@ class TestClass : public TestFixture { } void unsafeClassRefMember() { - checkUnsafeClassRefMember("class C { C(const std::string &s) : s(s) {} const std::string &s; };"); + checkUnsafeClassRefMember("class C { C(const std::string &s) : s(s) {} const std::string &s; };\n"); ASSERT_EQUALS("[test.cpp:1:37]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. [unsafeClassRefMember]\n", errout_str()); } @@ -9177,7 +9177,7 @@ class TestClass : public TestFixture { "private:\n" " static C *mInstance;\n" " void hello() {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:38]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\n" "[test.cpp:5:13]: note: Assuming 'mInstance' is used as 'this'\n" "[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\n" @@ -9190,7 +9190,7 @@ class TestClass : public TestFixture { "private:\n" " static std::shared_ptr mInstance;\n" " void hello() {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\n" "[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\n" "[test.cpp:3:20]: note: Delete 'mInstance', invalidating 'this'\n" @@ -9204,7 +9204,7 @@ class TestClass : public TestFixture { " static std::shared_ptr mInstance;\n" " void hello();\n" " void reset() { mInstance.reset(); }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:29]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\n" "[test.cpp:5:29]: note: Assuming 'mInstance' is used as 'this'\n" "[test.cpp:7:18]: note: Delete 'mInstance', invalidating 'this'\n" @@ -9218,7 +9218,7 @@ class TestClass : public TestFixture { "private:\n" " static C *self;\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\n" "[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\n" "[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\n" @@ -9231,7 +9231,7 @@ class TestClass : public TestFixture { "private:\n" " static C *self;\n" " std::map x;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:33]: warning: Using member 'x' when 'this' might be invalid [thisUseAfterFree]\n" "[test.cpp:5:13]: note: Assuming 'self' is used as 'this'\n" "[test.cpp:3:20]: note: Delete 'self', invalidating 'this'\n" @@ -9246,7 +9246,7 @@ class TestClass : public TestFixture { "private:\n" " std::shared_ptr mInstance;\n" " void hello() {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:39]: warning: Calling method 'hello()' when 'this' might be invalid [thisUseAfterFree]\n" "[test.cpp:6:22]: note: Assuming 'mInstance' is used as 'this'\n" "[test.cpp:4:20]: note: Delete 'mInstance', invalidating 'this'\n" @@ -9260,7 +9260,7 @@ class TestClass : public TestFixture { "private:\n" " C *self;\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkThisUseAfterFree("class C {\n" @@ -9270,7 +9270,7 @@ class TestClass : public TestFixture { "private:\n" " std::shared_ptr mInstance;\n" " void hello() {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkThisUseAfterFree("class C\n" @@ -9287,7 +9287,7 @@ class TestClass : public TestFixture { " static C* instanceSingleton;\n" "};\n" "\n" - "C* C::instanceSingleton;"); + "C* C::instanceSingleton;\n"); ASSERT_EQUALS("", errout_str()); // Avoid false positive when pointer is deleted in lambda @@ -9303,7 +9303,7 @@ class TestClass : public TestFixture { " auto done = [this] () { delete p; };\n" " dostuff();\n" " done();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkThisUseAfterFree("class C {\n" // #13311 @@ -9319,7 +9319,7 @@ class TestClass : public TestFixture { " if (self)\n" " delete self;\n" " self = new C();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -9348,19 +9348,19 @@ class TestClass : public TestFixture { } void ctuOneDefinitionRule() { - ctu({"class C { C() { std::cout << 0; } };", "class C { C() { std::cout << 1; } };"}); + ctu({"class C { C() { std::cout << 0; } };\n", "class C { C() { std::cout << 1; } };\n"}); ASSERT_EQUALS("[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\n", errout_str()); - ctu({"class C { C(); }; C::C() { std::cout << 0; }", "class C { C(); }; C::C() { std::cout << 1; }"}); + ctu({"class C { C(); }; C::C() { std::cout << 0; }\n", "class C { C(); }; C::C() { std::cout << 1; }\n"}); ASSERT_EQUALS("[1.cpp:1:1] -> [0.cpp:1:1]: (error) The one definition rule is violated, different classes/structs have the same name 'C' [ctuOneDefinitionRuleViolation]\n", errout_str()); ctu({"class C { C() {} };\n", "class C { C() {} };\n"}); ASSERT_EQUALS("", errout_str()); - ctu({"class C { C(); }; C::C(){}", "class C { C(); }; C::C(){}"}); + ctu({"class C { C(); }; C::C(){}\n", "class C { C(); }; C::C(){}\n"}); ASSERT_EQUALS("", errout_str()); - ctu({"class A::C { C() { std::cout << 0; } };", "class B::C { C() { std::cout << 1; } };"}); + ctu({"class A::C { C() { std::cout << 0; } };\n", "class B::C { C() { std::cout << 1; } };\n"}); ASSERT_EQUALS("", errout_str()); // 11435 - template specialisations @@ -9386,8 +9386,8 @@ class TestClass : public TestFixture { } void testGetFileInfo() { - getFileInfo("void foo() { union { struct { }; }; }"); // don't crash - getFileInfo("struct sometype { sometype(); }; sometype::sometype() = delete;"); // don't crash + getFileInfo("void foo() { union { struct { }; }; }\n"); // don't crash + getFileInfo("struct sometype { sometype(); }; sometype::sometype() = delete;\n"); // don't crash } #define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 8567d9b11a7..6d62b644043 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -172,59 +172,59 @@ class TestCondition : public TestFixture { "{\n" " int y = x & 4;\n" " if (y == 3);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\n", errout_str()); check("void foo(int x)\n" "{\n" " int y = x & 4;\n" " if (y != 3);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y!=3' is always true. [assignIfError]\n", errout_str()); // | check("void foo(int x) {\n" " int y = x | 0x14;\n" " if (y == 0x710);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==0x710' is always false. [assignIfError]\n", errout_str()); check("void foo(int x) {\n" " int y = x | 0x14;\n" " if (y == 0x71f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // various simple assignments check("void foo(int x) {\n" " int y = (x+1) | 1;\n" " if (y == 2);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\n", errout_str()); check("void foo() {\n" " int y = 1 | x();\n" " if (y == 2);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:8]: (style) Mismatching assignment and comparison, comparison 'y==2' is always false. [assignIfError]\n", errout_str()); // multiple conditions check("void foo(int x) {\n" " int y = x & 4;\n" " if ((y == 3) && (z == 1));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\n", errout_str()); check("void foo(int x) {\n" " int y = x & 4;\n" " if ((x==123) || ((y == 3) && (z == 1)));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:22]: (style) Mismatching assignment and comparison, comparison 'y==3' is always false. [assignIfError]\n", errout_str()); check("void f(int x) {\n" " int y = x & 7;\n" " if (setvalue(&y) && y != 8);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // recursive checking into scopes @@ -232,20 +232,20 @@ class TestCondition : public TestFixture { " int y = x & 7;\n" " if (z) y=0;\n" " else { if (y==8); }\n" // always false - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:4:15]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\n", errout_str()); // while check("void f(int x) {\n" " int y = x & 7;\n" " while (y==8);\n" // local variable => always false - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:11]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\n", errout_str()); check("void f(int x) {\n" " extern int y; y = x & 7;\n" " while (y==8);\n" // non-local variable => no error - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" @@ -254,7 +254,7 @@ class TestCondition : public TestFixture { " int y = 16 | a;\n" " while (y != 0) y--;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void g(int x);\n" @@ -264,7 +264,7 @@ class TestCondition : public TestFixture { " int y = 16 | a;\n" " while (y != 0) g(y);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:5:15] -> [test.cpp:6:15]: (style) Mismatching assignment and comparison, comparison 'y!=0' is always true. [assignIfError]\n", errout_str()); @@ -276,7 +276,7 @@ class TestCondition : public TestFixture { " int y = 16 | a;\n" " while (y != 0) g(y);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // calling function @@ -284,14 +284,14 @@ class TestCondition : public TestFixture { " int y = x & 7;\n" " do_something();\n" " if (y==8);\n" // local variable => always false - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\n", errout_str()); check("void f(int x) {\n" " int y = x & 7;\n" " do_something(&y);\n" // passing variable => no error " if (y==8);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void do_something(int);\n" @@ -299,14 +299,14 @@ class TestCondition : public TestFixture { " int y = x & 7;\n" " do_something(y);\n" " if (y==8);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:5:8]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false. [assignIfError]\n", errout_str()); check("void f(int x) {\n" " extern int y; y = x & 7;\n" " do_something();\n" " if (y==8);\n" // non-local variable => no error - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #4434 : false positive: ?: @@ -314,28 +314,28 @@ class TestCondition : public TestFixture { " x = x & 1;\n" " x = x & 1 ? 1 : -1;\n" " if(x != -1) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #4735 check("void f() {\n" " int x = *(char*)&0x12345678;\n" " if (x==18) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // bailout: no variable info check("void foo(int x) {\n" " y = 2 | x;\n" // y not declared => no error " if(y == 1) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // bailout: negative number check("void foo(int x) {\n" " int y = -2 | x;\n" // negative number => no error " if (y==1) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // bailout: pass variable to function @@ -343,7 +343,7 @@ class TestCondition : public TestFixture { " int y = 2 | x;\n" " bar(&y);\n" // pass variable to function => no error " if (y==1) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // no crash on unary operator& (#5643) @@ -351,7 +351,7 @@ class TestCondition : public TestFixture { check("SdrObject* ApplyGraphicToObject() {\n" " if (&rHitObject) {}\n" " else if (rHitObject.IsClosedObj() && !&rHitObject) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Condition '&rHitObject' is always true [knownConditionTrueFalse]\n" "[test.cpp:3:42]: (style) Condition '!&rHitObject' is always false [knownConditionTrueFalse]\n", errout_str()); @@ -364,7 +364,7 @@ class TestCondition : public TestFixture { " if (c == 4)\n" " c = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int a) {\n" // #6662 @@ -372,7 +372,7 @@ class TestCondition : public TestFixture { " while (x <= 4) {\n" " if (x != 5) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:8]: (style) Mismatching assignment and comparison, comparison 'x!=5' is always true. [assignIfError]\n", errout_str()); check("void f(int a) {\n" // #6662 @@ -380,7 +380,7 @@ class TestCondition : public TestFixture { " while ((x += 4) < 10) {\n" " if (x != 5) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -388,7 +388,7 @@ class TestCondition : public TestFixture { " while (x) {\n" " g(x);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void g(int x);\n" @@ -397,7 +397,7 @@ class TestCondition : public TestFixture { " while (x) {\n" " g(x);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:12]: (style) Condition 'x' is always true [knownConditionTrueFalse]\n", errout_str()); check("void g(int & x);\n" @@ -406,7 +406,7 @@ class TestCondition : public TestFixture { " while (x) {\n" " g(x);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -415,13 +415,13 @@ class TestCondition : public TestFixture { check("void f(int a) {\n" " int b = a & 0xf0;\n" " b &= 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:5]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\n", errout_str()); check("void f(int a) {\n" " int b = a & 0xf0;\n" " int c = b & 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:9]: (style) Mismatching bitmasks. Result is always 0 (X = Y & 0xf0; Z = X & 0x1; => Z=0). [mismatchingBitAnd]\n", errout_str()); check("void f(int a) {\n" @@ -430,67 +430,67 @@ class TestCondition : public TestFixture { " case 1: b &= 1; break;\n" " case 2: b &= 2; break;\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void comparison() { // CheckCondition::comparison test cases // '==' - check("void f(int a) {\n assert( (a & 0x07) == 8U );\n}"); + check("void f(int a) {\n assert( (a & 0x07) == 8U );\n}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X & 0x7) == 0x8' is always false. [comparisonError]\n",errout_str()); - check("void f(int a) {\n assert( (a & b & 4 & c ) == 3 );\n}"); + check("void f(int a) {\n assert( (a & b & 4 & c ) == 3 );\n}\n"); ASSERT_EQUALS("[test.cpp:2:21]: (style) Expression '(X & 0x4) == 0x3' is always false. [comparisonError]\n", errout_str()); - check("void f(int a) {\n assert( (a | 0x07) == 8U );\n}"); + check("void f(int a) {\n assert( (a | 0x07) == 8U );\n}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X | 0x7) == 0x8' is always false. [comparisonError]\n",errout_str()); - check("void f(int a) {\n assert( (a & 0x07) == 7U );\n}"); + check("void f(int a) {\n assert( (a & 0x07) == 7U );\n}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(int a) {\n assert( (a | 0x01) == -15 );\n}"); + check("void f(int a) {\n assert( (a | 0x01) == -15 );\n}\n"); ASSERT_EQUALS("", errout_str()); // '!=' - check("void f(int a) {\n assert( (a & 0x07) != 8U );\n}"); + check("void f(int a) {\n assert( (a & 0x07) != 8U );\n}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X & 0x7) != 0x8' is always true. [comparisonError]\n",errout_str()); - check("void f(int a) {\n assert( (a | 0x07) != 8U );\n}"); + check("void f(int a) {\n assert( (a | 0x07) != 8U );\n}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X | 0x7) != 0x8' is always true. [comparisonError]\n",errout_str()); - check("void f(int a) {\n assert( (a & 0x07) != 7U );\n}"); + check("void f(int a) {\n assert( (a & 0x07) != 7U );\n}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(int a) {\n assert( (a | 0x07) != 7U );\n}"); + check("void f(int a) {\n assert( (a | 0x07) != 7U );\n}\n"); ASSERT_EQUALS("", errout_str()); // '>=' - check("void f(int a) {\n assert( (a & 0x07) >= 8U );\n}"); + check("void f(int a) {\n assert( (a & 0x07) >= 8U );\n}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X & 0x7) >= 0x8' is always false. [comparisonError]\n",errout_str()); - check("void f(unsigned int a) {\n assert( (a | 0x7) >= 7U );\n}"); + check("void f(unsigned int a) {\n assert( (a | 0x7) >= 7U );\n}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X | 0x7) >= 0x7' is always true. [comparisonError]\n",errout_str()); - check("void f(int a) {\n assert( (a & 0x07) >= 7U );\n}"); + check("void f(int a) {\n assert( (a & 0x07) >= 7U );\n}\n"); ASSERT_EQUALS("",errout_str()); - check("void f(int a) {\n assert( (a | 0x07) >= 8U );\n}"); + check("void f(int a) {\n assert( (a | 0x07) >= 8U );\n}\n"); ASSERT_EQUALS("",errout_str()); //correct for negative 'a' // '>' - check("void f(int a) {\n assert( (a & 0x07) > 7U );\n}"); + check("void f(int a) {\n assert( (a & 0x07) > 7U );\n}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X & 0x7) > 0x7' is always false. [comparisonError]\n",errout_str()); - check("void f(unsigned int a) {\n assert( (a | 0x7) > 6U );\n}"); + check("void f(unsigned int a) {\n assert( (a | 0x7) > 6U );\n}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X | 0x7) > 0x6' is always true. [comparisonError]\n",errout_str()); - check("void f(int a) {\n assert( (a & 0x07) > 6U );\n}"); + check("void f(int a) {\n assert( (a & 0x07) > 6U );\n}\n"); ASSERT_EQUALS("",errout_str()); - check("void f(int a) {\n assert( (a | 0x07) > 7U );\n}"); + check("void f(int a) {\n assert( (a | 0x07) > 7U );\n}\n"); ASSERT_EQUALS("",errout_str()); //correct for negative 'a' // '<=' - check("void f(int a) {\n assert( (a & 0x07) <= 7U );\n}"); + check("void f(int a) {\n assert( (a & 0x07) <= 7U );\n}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X & 0x7) <= 0x7' is always true. [comparisonError]\n",errout_str()); - check("void f(unsigned int a) {\n assert( (a | 0x08) <= 7U );\n}"); + check("void f(unsigned int a) {\n assert( (a | 0x08) <= 7U );\n}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X | 0x8) <= 0x7' is always false. [comparisonError]\n",errout_str()); - check("void f(int a) {\n assert( (a & 0x07) <= 6U );\n}"); + check("void f(int a) {\n assert( (a & 0x07) <= 6U );\n}\n"); ASSERT_EQUALS("",errout_str()); - check("void f(int a) {\n assert( (a | 0x08) <= 7U );\n}"); + check("void f(int a) {\n assert( (a | 0x08) <= 7U );\n}\n"); ASSERT_EQUALS("",errout_str()); //correct for negative 'a' // '<' - check("void f(int a) {\n assert( (a & 0x07) < 8U );\n}"); + check("void f(int a) {\n assert( (a & 0x07) < 8U );\n}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X & 0x7) < 0x8' is always true. [comparisonError]\n",errout_str()); - check("void f(unsigned int a) {\n assert( (a | 0x07) < 7U );\n}"); + check("void f(unsigned int a) {\n assert( (a | 0x07) < 7U );\n}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Expression '(X | 0x7) < 0x7' is always false. [comparisonError]\n",errout_str()); - check("void f(int a) {\n assert( (a & 0x07) < 3U );\n}"); + check("void f(int a) {\n assert( (a & 0x07) < 3U );\n}\n"); ASSERT_EQUALS("",errout_str()); - check("void f(int a) {\n assert( (a | 0x07) < 7U );\n}"); + check("void f(int a) {\n assert( (a | 0x07) < 7U );\n}\n"); ASSERT_EQUALS("",errout_str()); //correct for negative 'a' check("void f(int i) {\n" // #11998 @@ -536,14 +536,14 @@ class TestCondition : public TestFixture { "{\n" " if (x & 7);\n" " else { if (x == 1); }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\n", errout_str()); check("void foo(int x)\n" "{\n" " if (x & 7);\n" " else { if (x & 1); }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\n", errout_str()); check("extern int bar() __attribute__((pure));\n" @@ -551,7 +551,7 @@ class TestCondition : public TestFixture { "{\n" " if ( bar() >1 && b) {}\n" " else if (bar() >1 && b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\n", errout_str()); checkPureFunction("extern int bar();\n" @@ -559,14 +559,14 @@ class TestCondition : public TestFixture { "{\n" " if ( bar() >1 && b) {}\n" " else if (bar() >1 && b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:23]: (style) Expression is always false because 'else if' condition matches previous condition at line 4. [multiCondition]\n", errout_str()); // 7284 check("void foo() {\n" " if (a) {}\n" " else if (!!a) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); // #11059 @@ -593,53 +593,53 @@ class TestCondition : public TestFixture { check("void f(int a, int &b) {\n" " if (a) { b = 1; }\n" " else { if (a) { b = 2; } }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(int a, int &b) {\n" " if (a) { b = 1; }\n" " else { if (a) { b = 2; } }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(int a, int &b) {\n" " if (a == 1) { b = 1; }\n" " else { if (a == 2) { b = 2; }\n" " else { if (a == 1) { b = 3; } } }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(int a, int &b) {\n" " if (a == 1) { b = 1; }\n" " else { if (a == 2) { b = 2; }\n" " else { if (a == 2) { b = 3; } } }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:18]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\n", errout_str()); check("void f(int a, int &b) {\n" " if (a++) { b = 1; }\n" " else { if (a++) { b = 2; }\n" " else { if (a++) { b = 3; } } }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int a, int &b) {\n" " if (!strtok(NULL, \" \")) { b = 1; }\n" " else { if (!strtok(NULL, \" \")) { b = 2; } }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); { check("void f(Class &c) {\n" " if (c.dostuff() == 3) {}\n" " else { if (c.dostuff() == 3) {} }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(const Class &c) {\n" " if (c.dostuff() == 3) {}\n" " else { if (c.dostuff() == 3) {} }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:28]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); } @@ -647,13 +647,13 @@ class TestCondition : public TestFixture { " x = x / 2;\n" " if (x < 100) { b = 1; }\n" " else { x = x / 2; if (x < 100) { b = 2; } }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int64_t i) {\n" " if(i == 0x02e2000000 || i == 0xa0c6000000)\n" " foo(i);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // ticket 3689 ( avoid false positive ) @@ -675,13 +675,13 @@ class TestCondition : public TestFixture { " return -1;\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(WIDGET *widget) {\n" " if (dynamic_cast(widget)){}\n" " else if (dynamic_cast(widget)){}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class B { virtual void v() {} };\n" // #11037 @@ -698,67 +698,67 @@ class TestCondition : public TestFixture { check("void f(int x) {\n" // #6482 " if (x & 1) {}\n" " else if (x == 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if (x & 15) {}\n" " else if (x == 40) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(int x) {\n" " if (x == sizeof(double)) {}\n" - " else { if (x == sizeof(long double)) {} }" - "}"); + " else { if (x == sizeof(long double)) {} }\n" + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if (x & 0x08) {}\n" " else if (x & 0xF8) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if (x & 0xF8) {}\n" " else if (x & 0x08) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:14]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( !!b && !!a){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( !!b && a){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( b && !!a){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( b && !(!a)){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:15]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( !!b && !(!a)){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:17]: (style) Expression is always false because 'else if' condition matches previous condition at line 2. [multiCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( !!(b) && !!(a+b)){}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #8168 @@ -770,7 +770,7 @@ class TestCondition : public TestFixture { "void TestFunction(int value) {\n" " if ( value & (int)Value1 ) {}\n" " else if ( value & (int)Value2 ) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(size_t x) {\n" @@ -792,7 +792,7 @@ class TestCondition : public TestFixture { check("void f(int x) {\n" " if (x) {}\n" " else if (!x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 2. [multiCondition]\n" "[test.cpp:2:9]: note: first condition\n" "[test.cpp:3:14]: note: else if condition is opposite to first condition\n", errout_str()); @@ -801,7 +801,7 @@ class TestCondition : public TestFixture { " int y = x;\n" " if (x) {}\n" " else if (!y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:14]: style: Expression is always true because 'else if' condition is opposite to previous condition at line 3. [multiCondition]\n" "[test.cpp:2:13]: note: 'y' is assigned value 'x' here.\n" "[test.cpp:3:9]: note: first condition\n" @@ -812,31 +812,31 @@ class TestCondition : public TestFixture { check("bool f(int x) {\n" " bool b = x | 0x02;\n" " return b;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("bool f(int x) {\n" " bool b = 0x02 | x;\n" " return b;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:19]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("int f(int x) {\n" " int b = x | 0x02;\n" " return b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(int x) {\n" " bool b = x & 0x02;\n" " return b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(int x) {\n" " if(x | 0x02)\n" " return b;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("bool f(int x) {\n" @@ -844,27 +844,27 @@ class TestCondition : public TestFixture { " if(b) y = 0;\n" " if(x | y)\n" " return b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(int x) {\n" " foo(a && (x | 0x02));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("int f(int x) {\n" " return (x | 0x02) ? 0 : 5;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("int f(int x) {\n" " return x ? (x | 0x02) : 5;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(int x) {\n" " return x | 0x02;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("bool f(int x) {\n" @@ -872,19 +872,19 @@ class TestCondition : public TestFixture { " return x | 0x02;\n" " }\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("const bool f(int x) {\n" " return x | 0x02;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("struct F {\n" " static const bool f(int x) {\n" " return x | 0x02;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:16]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("struct F {\n" @@ -892,12 +892,12 @@ class TestCondition : public TestFixture { "};\n" "F::b_t f(int x) {\n" " return x | 0x02;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:12]: (warning) Result of operator '|' is always true if one operand is non-zero. Did you intend to use '&'? [badBitmaskCheck]\n", errout_str()); check("int f(int x) {\n" " return x | 0x02;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void create_rop_masks_4( rop_mask_bits *bits) {\n" @@ -905,7 +905,7 @@ class TestCondition : public TestFixture { "BYTE *and_bits = bits->and;\n" "rop_mask *rop_mask;\n" "and_bits[mask_offset] |= (rop_mask->and & 0x0f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(unsigned a, unsigned b) {\n" @@ -913,7 +913,7 @@ class TestCondition : public TestFixture { " if (cmd1 | a) {\n" " if (b == 0x0C) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int i) {\n" // #11082 @@ -941,7 +941,7 @@ class TestCondition : public TestFixture { "#if BAR_ENABLED\n" " FEATURE_BAR |\n" "#endif\n" - " 0;"); + " 0;\n"); ASSERT_EQUALS("", errout_str()); check("enum precedence { PC0, UNARY };\n" @@ -960,84 +960,84 @@ class TestCondition : public TestFixture { check("void f(int x) {\n" " if ((x != 1) || (x != 3))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (1 != x || 3 != x)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x<0 && !x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (warning) Logical conjunction always evaluates to false: x < 0 && !x. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x==0 && x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (warning) Logical conjunction always evaluates to false: x == 0 && x. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" // ast.. " if (y == 1 && x == 1 && x == 7) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:26]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 7. [incorrectLogicOperator]\n", errout_str()); check("void f(int x, int y) {\n" " if (x != 1 || y != 1)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x, int y) {\n" " if ((y == 1) && (x != 1) || (x != 3))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x, int y) {\n" " if ((x != 1) || (x != 3) && (y == 1))\n" " a++;\n" - "}" + "}\n" ); ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x!=3' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" " if ((x != 1) && (x != 3))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if ((x == 1) || (x == 3))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x, int y) {\n" " if ((x != 1) || (y != 3))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x, int y) {\n" " if ((x != hotdog) || (y != hotdog))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x, int y) {\n" " if ((x != 5) || (y != 5))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if ((x != 5) || (x != 6))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:18]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6. [incorrectLogicOperator]\n", errout_str()); check("void f(unsigned int a, unsigned int b, unsigned int c) {\n" @@ -1046,7 +1046,7 @@ class TestCondition : public TestFixture { " return true;\n" " }\n" " return false;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:23] -> [test.cpp:2:35]: (style) Condition 'c!=a' is always false [knownConditionTrueFalse]\n", errout_str()); } @@ -1054,224 +1054,224 @@ class TestCondition : public TestFixture { check("void f(float x) {\n" " if ((x == 1) && (x == 1.0))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if ((x == 1) && (x == 0x00000001))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:2:24]: (style) Condition 'x==0x00000001' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" " if (x == 1 && x == 3)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x == 1.0 && x == 3.0)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // float comparisons with == and != are not checked right now - such comparison is a bad idea check("void f(float x) {\n" " if (x == 1 && x == 1.0)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void bar(float f) {\n" // #5246 " if ((f > 0) && (f < 1)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if (x < 1 && x > 1)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x < 1.0 && x > 1.0)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 1.0. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x < 1 && x > 1.0)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 1.0. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x >= 1.0 && x <= 1.001)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if (x < 1 && x > 3)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\n", errout_str()); check("void f(float x) {\n" " if (x < 1.0 && x > 3.0)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (warning) Logical conjunction always evaluates to false: x < 1.0 && x > 3.0. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (1 > x && 3 < x)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x < 3 && x > 1)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if (x > 3 || x < 10)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x < 10. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x >= 3 || x <= 10)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 10. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x >= 3 || x < 10)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 10. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x > 3 || x <= 10)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 10. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x > 3 || x < 3)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if (x >= 3 || x <= 3)\n" " a++;\n" - "}" + "}\n" ); ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x <= 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x >= 3 || x < 3)\n" " a++;\n" - "}" + "}\n" ); ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x >= 3 || x < 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x > 3 || x <= 3)\n" " a++;\n" - "}" + "}\n" ); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x > 3 || x <= 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if((x==3) && (x!=4))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\n", errout_str()); check("void f(const std::string &s) {\n" // #8860 " const std::size_t p = s.find(\"42\");\n" " const std::size_t * const ptr = &p;\n" " if(p != std::string::npos && p == 0 && *ptr != 1){;}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:36] -> [test.cpp:4:49]: (style) Condition '*ptr!=1' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" " if ((x!=4) && (x==3))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (style) Redundant condition: The condition 'x != 4' is redundant since 'x == 3' is sufficient. [redundantCondition]\n", errout_str()); check("void f(int x) {\n" " if ((x==3) || (x!=4))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\n", errout_str()); check("void f(int x) {\n" " if ((x!=4) || (x==3))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (style) Redundant condition: The condition 'x == 3' is redundant since 'x != 4' is sufficient. [redundantCondition]\n", errout_str()); check("void f(int x) {\n" " if ((x==3) && (x!=3))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == 3 && x != 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if ((x==6) || (x!=6))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical disjunction always evaluates to true: x == 6 || x != 6. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x > 10 || x < 3)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if (x > 5 && x == 1)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x > 5 && x == 6)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x == 6' is sufficient. [redundantCondition]\n", errout_str()); // #3419 check("void f() {\n" " if ( &q != &a && &q != &b ) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #3676 check("void f(int m_x2, int w, int x) {\n" " if (x + w - 1 > m_x2 || m_x2 < 0 )\n" " m_x2 = x + w - 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(float x) {\n" // x+1 => x " if (x <= 1.0e20 && x >= -1.0e20) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(float x) {\n" // x+1 => x " if (x >= 1.0e20 && x <= 1.0e21) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(float x) {\n" // x+1 => x " if (x <= -1.0e20 && x >= -1.0e21) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1281,7 +1281,7 @@ class TestCondition : public TestFixture { " c = x < 1 && x == 3;\n" " d = x >= 5 && x == 1;\n" " e = x <= 1 && x == 3;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 5 && x == 1. [incorrectLogicOperator]\n" "[test.cpp:3:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x == 3. [incorrectLogicOperator]\n" "[test.cpp:4:16]: (warning) Logical conjunction always evaluates to false: x >= 5 && x == 1. [incorrectLogicOperator]\n" @@ -1292,7 +1292,7 @@ class TestCondition : public TestFixture { check("#define ZERO 0\n" "void f(int x) {\n" " if (x && x != ZERO) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int N) {\n" // #9789 @@ -1307,7 +1307,7 @@ class TestCondition : public TestFixture { void incorrectLogicOperator5() { // complex expressions check("void f(int x) {\n" " if (x+3 > 2 || x+3 < 10) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical disjunction always evaluates to true: x+3 > 2 || x+3 < 10. [incorrectLogicOperator]\n", errout_str()); } @@ -1315,51 +1315,51 @@ class TestCondition : public TestFixture { const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive).build(); check("void f(char x) {\n" " if (x == '1' || x == '2') {}\n" - "}", s); + "}\n", s); ASSERT_EQUALS("", errout_str()); check("void f(char x) {\n" " if (x == '1' && x == '2') {}\n" - "}", s); + "}\n", s); ASSERT_EQUALS("[test.cpp:2:16]: (warning) Logical conjunction always evaluates to false: x == '1' && x == '2'. [incorrectLogicOperator]\n", errout_str()); check("int f(char c) {\n" " return (c >= 'a' && c <= 'z');\n" - "}", s); + "}\n", s); ASSERT_EQUALS("", errout_str()); check("int f(char c) {\n" " return (c <= 'a' && c >= 'z');\n" - "}", s); + "}\n", s); ASSERT_EQUALS("[test.cpp:2:20]: (warning, inconclusive) Logical conjunction always evaluates to false: c <= 'a' && c >= 'z'. [incorrectLogicOperator]\n", errout_str()); check("int f(char c) {\n" " return (c <= 'a' && c >= 'z');\n" - "}"); // TODO: use s? + "}\n"); // TODO: use s? ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:2:25]: (style) Return value 'c>='z'' is always false [knownConditionTrueFalse]\n", errout_str()); } void incorrectLogicOperator7() { // opposite expressions check("void f(int i) {\n" " if (i || !i) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (warning) Logical disjunction always evaluates to true: i || !(i). [incorrectLogicOperator]\n", errout_str()); check("void f(int a, int b) {\n" " if (a>b || a<=b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (warning) Logical disjunction always evaluates to true: a > b || a <= b. [incorrectLogicOperator]\n", errout_str()); check("void f(int a, int b) {\n" " if (a>b || a T icdf( const T uniform ) {\n" " if ((0(obj));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1394,21 +1394,21 @@ class TestCondition : public TestFixture { "void f(Type_t t) {\n" " if ((t == A) && (t == B))\n" " {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: t == 0 && t == 1. [incorrectLogicOperator]\n", errout_str()); } void incorrectLogicOperator11() { - check("void foo(int i, const int n) { if ( i < n && i == n ) {} }"); + check("void foo(int i, const int n) { if ( i < n && i == n ) {} }\n"); ASSERT_EQUALS("[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i < n && i == n. [incorrectLogicOperator]\n", errout_str()); - check("void foo(int i, const int n) { if ( i > n && i == n ) {} }"); + check("void foo(int i, const int n) { if ( i > n && i == n ) {} }\n"); ASSERT_EQUALS("[test.cpp:1:43]: (warning) Logical conjunction always evaluates to false: i > n && i == n. [incorrectLogicOperator]\n", errout_str()); - check("void foo(int i, const int n) { if ( i == n && i > n ) {} }"); + check("void foo(int i, const int n) { if ( i == n && i > n ) {} }\n"); ASSERT_EQUALS("[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i > n. [incorrectLogicOperator]\n", errout_str()); - check("void foo(int i, const int n) { if ( i == n && i < n ) {} }"); + check("void foo(int i, const int n) { if ( i == n && i < n ) {} }\n"); ASSERT_EQUALS("[test.cpp:1:44]: (warning) Logical conjunction always evaluates to false: i == n && i < n. [incorrectLogicOperator]\n", errout_str()); } @@ -1422,7 +1422,7 @@ class TestCondition : public TestFixture { " y.f();\n" " if (a > x && a < y)\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:5:9] -> [test.cpp:6:9] -> [test.cpp:8:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\n", errout_str()); @@ -1436,7 +1436,7 @@ class TestCondition : public TestFixture { " y.f();\n" " if (a > x && a < y)\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(A a, A b) {\n" @@ -1445,7 +1445,7 @@ class TestCondition : public TestFixture { " y.f();\n" " if (a > x && a < y)\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(A a, A b) {\n" @@ -1454,7 +1454,7 @@ class TestCondition : public TestFixture { " y.f();\n" " if (a > x && a < y)\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:15] -> [test.cpp:3:15] -> [test.cpp:5:13]: (warning) Logical conjunction always evaluates to false: a > x && a < y. [incorrectLogicOperator]\n", errout_str()); @@ -1468,7 +1468,7 @@ class TestCondition : public TestFixture { " y.f();\n" " if (a > x && a < y)\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\n" "[test.cpp:8:18]: (style) Condition 'a x && a < y)\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo(A a) {\n" @@ -1491,7 +1491,7 @@ class TestCondition : public TestFixture { " y.f();\n" " if (a > x && a < y)\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\n", errout_str()); check("void foo(A a) {\n" @@ -1500,7 +1500,7 @@ class TestCondition : public TestFixture { " y.f();\n" " if (a > x && a < y)\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9]: (style) Condition 'a>x' is always false [knownConditionTrueFalse]\n" "[test.cpp:5:18]: (style) Condition 'a [test.cpp:3:18]: (warning) Logical conjunction always evaluates to false: v == 1 && x == 2. [incorrectLogicOperator]\n", errout_str()); check("void f2(const int *v) {\n" " const int *x=v;\n" " if ((*v == 1) && (*x == 2)) {;}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:18] -> [test.cpp:3:19]: (warning) Logical conjunction always evaluates to false: *(v) == 1 && *(x) == 2. [incorrectLogicOperator]\n", errout_str()); } @@ -1724,7 +1724,7 @@ class TestCondition : public TestFixture { " if (f && g)\n" " ;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:200:11] -> [test.cpp:200:16]: (style) Condition 'g' is always true [knownConditionTrueFalse]\n", errout_str()); } @@ -1780,31 +1780,31 @@ class TestCondition : public TestFixture { check("void f(void) {\n" // #8892 " const char c[1] = { \'x\' }; \n" " if(c[0] == \'x\'){;}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:13]: (style) Condition 'c[0]=='x'' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" " if (x > 5 && x != 1)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\n", errout_str()); check("void f(int x) {\n" " if (x > 5 && x != 6)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if ((x > 5) && (x != 1))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (style) Redundant condition: The condition 'x != 1' is redundant since 'x > 5' is sufficient. [redundantCondition]\n", errout_str()); check("void f(int x) {\n" " if ((x > 5) && (x != 6))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x, bool& b) {\n" @@ -1812,7 +1812,7 @@ class TestCondition : public TestFixture { " c = x < 5 || x == 4;\n" " d = x >= 3 || x == 4;\n" " e = x <= 5 || x == 4;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x > 3' is sufficient. [redundantCondition]\n" "[test.cpp:3:15]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x < 5' is sufficient. [redundantCondition]\n" "[test.cpp:4:16]: (style) Redundant condition: The condition 'x == 4' is redundant since 'x >= 3' is sufficient. [redundantCondition]\n" @@ -1824,7 +1824,7 @@ class TestCondition : public TestFixture { " c = x < 1 || x != 3;\n" " d = x >= 5 || x != 1;\n" " e = x <= 1 || x != 3;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\n" "[test.cpp:3:15]: (style) Redundant condition: The condition 'x < 1' is redundant since 'x != 3' is sufficient. [redundantCondition]\n" "[test.cpp:4:16]: (style) Redundant condition: The condition 'x >= 5' is redundant since 'x != 1' is sufficient. [redundantCondition]\n" @@ -1836,7 +1836,7 @@ class TestCondition : public TestFixture { " c = x > 5 || x > 6;\n" " d = x < 6 && x < 5;\n" " e = x < 5 || x < 6;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (style) Redundant condition: The condition 'x > 5' is redundant since 'x > 6' is sufficient. [redundantCondition]\n" "[test.cpp:3:15]: (style) Redundant condition: The condition 'x > 6' is redundant since 'x > 5' is sufficient. [redundantCondition]\n" "[test.cpp:4:15]: (style) Redundant condition: The condition 'x < 6' is redundant since 'x < 5' is sufficient. [redundantCondition]\n" @@ -1848,7 +1848,7 @@ class TestCondition : public TestFixture { " c = x > 5.5 || x > 6.5;\n" " d = x < 6.5 && x < 5.5;\n" " e = x < 5.5 || x < 6.5;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (style) Redundant condition: The condition 'x > 5.5' is redundant since 'x > 6.5' is sufficient. [redundantCondition]\n" "[test.cpp:3:17]: (style) Redundant condition: The condition 'x > 6.5' is redundant since 'x > 5.5' is sufficient. [redundantCondition]\n" "[test.cpp:4:17]: (style) Redundant condition: The condition 'x < 6.5' is redundant since 'x < 5.5' is sufficient. [redundantCondition]\n" @@ -1866,49 +1866,49 @@ class TestCondition : public TestFixture { check("void f(int x) {\n" " if (x < 1 && x > 3)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (1 > x && x > 3)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x < 1 && 3 < x)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (1 > x && 3 < x)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x < 1 && x > 3. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x > 3 && x < 1)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (3 < x && x < 1)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (x > 3 && 1 > x)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\n", errout_str()); check("void f(int x) {\n" " if (3 < x && 1 > x)\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1. [incorrectLogicOperator]\n", errout_str()); } @@ -1918,7 +1918,7 @@ class TestCondition : public TestFixture { " b2 = a % c == 100000;\n" " b3 = a % 5 == c;\n" " return a % 5 == 5-p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(bool& b1, bool& b2, bool& b3, bool& b4, bool& b5) {\n" @@ -1928,7 +1928,7 @@ class TestCondition : public TestFixture { " b4 = a % 5 != 5;\n" " b5 = a % 5 >= 5;\n" " return a % 5 > 5;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\n" "[test.cpp:3:16]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\n" @@ -1942,7 +1942,7 @@ class TestCondition : public TestFixture { " b1 = bar() % 5 < 889;\n" " if(x[593] % 5 <= 5)\n" " b2 = x.a % 5 == 5;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:20]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\n" "[test.cpp:3:19]: (warning) Comparison of modulo result is predetermined, because it is always less than 5. [moduloAlwaysTrueFalse]\n" @@ -1952,7 +1952,7 @@ class TestCondition : public TestFixture { check("void f() {\n" " if (a % 2 + b % 2 == 2)\n" " foo();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1961,21 +1961,21 @@ class TestCondition : public TestFixture { " if(a==b)\n" " if(a!=b)\n" " cout << a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("bool foo(int a, int b) {\n" " if(a==b)\n" " return a!=b;\n" " return false;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:17]: (warning) Opposite inner 'return' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void foo(int a, int b) {\n" " if(a==b)\n" " if(b!=a)\n" " cout << a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void foo(int a) {\n" @@ -1985,7 +1985,7 @@ class TestCondition : public TestFixture { " else\n" " cout << 100;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:3:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); // #4186 @@ -1996,7 +1996,7 @@ class TestCondition : public TestFixture { " else\n" " cout << 100;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // 4170 @@ -2015,7 +2015,7 @@ class TestCondition : public TestFixture { " }\n" " void next();\n" " const char *tok;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int i)\n" @@ -2026,7 +2026,7 @@ class TestCondition : public TestFixture { " cout << a;\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int& i) {\n" @@ -2038,7 +2038,7 @@ class TestCondition : public TestFixture { " if(i<5) {\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int& i);\n" @@ -2049,7 +2049,7 @@ class TestCondition : public TestFixture { " if(i<5) {\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int i);\n" @@ -2059,7 +2059,7 @@ class TestCondition : public TestFixture { " if(i<5) {\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void foo(const int &i);\n" @@ -2069,7 +2069,7 @@ class TestCondition : public TestFixture { " if(i<5) {\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:5:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void foo(int i);\n" @@ -2080,7 +2080,7 @@ class TestCondition : public TestFixture { " if(i<5) {\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:6:13]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("class C { void f(int &i) const; };\n" // #7028 - variable is changed by const method @@ -2089,7 +2089,7 @@ class TestCondition : public TestFixture { " c.f(i);\n" " if (i != 5) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // see linux revision 1f80c0cc @@ -2103,7 +2103,7 @@ class TestCondition : public TestFixture { " err = rc;\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:11] -> [test.cpp:7:14]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); @@ -2114,7 +2114,7 @@ class TestCondition : public TestFixture { " array[0] += 5;\n" " if (array[0] > 2) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #6227 - FP caused by simplifications of casts and known variables @@ -2123,7 +2123,7 @@ class TestCondition : public TestFixture { " B *b = dynamic_cast(a);\n" " if(!b) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int a) {\n" @@ -2131,7 +2131,7 @@ class TestCondition : public TestFixture { " int b = a;\n" " if(!b) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:16] -> [test.cpp:2:7] -> [test.cpp:4:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void foo(unsigned u) {\n" @@ -2141,7 +2141,7 @@ class TestCondition : public TestFixture { " u = x;\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #8186 @@ -2149,7 +2149,7 @@ class TestCondition : public TestFixture { " for (int i=0;i<4;i++) {\n" " if (i==5) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17] -> [test.cpp:3:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); // #8938 @@ -2158,7 +2158,7 @@ class TestCondition : public TestFixture { " GetActiveCell(&(upperleft.Col), &(upperleft.Row));\n" " if (upperleft.Row == -1) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9702 @@ -2171,7 +2171,7 @@ class TestCondition : public TestFixture { " }\n" " bool IsSet() const { return m_value; }\n" " bool m_value = false;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // #12725 @@ -2193,7 +2193,7 @@ class TestCondition : public TestFixture { " err = rc;\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void Fred::f() {\n" // daca: ace @@ -2201,7 +2201,7 @@ class TestCondition : public TestFixture { " this->next_ = n;\n" " if (this->next_ != map_man_->table_) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void test(float *f) {\n" // #7405 @@ -2209,13 +2209,13 @@ class TestCondition : public TestFixture { " (*f) += 0.1f;\n" " if(*f<10) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int * f(int * x, int * y) {\n" " if(!x) return x;\n" " return y;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2227,7 +2227,7 @@ class TestCondition : public TestFixture { " fred.dostuff();\n" " if (!fred.isValid()) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:19] -> [test.cpp:5:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("class Fred { public: bool isValid() const; void dostuff() const; };\n" @@ -2237,7 +2237,7 @@ class TestCondition : public TestFixture { " fred.dostuff();\n" // <- dostuff() is const, warn " if (!fred.isValid()) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:19] -> [test.cpp:6:9]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f() {\n" @@ -2246,7 +2246,7 @@ class TestCondition : public TestFixture { " fred.dostuff();\n" " if (!fred.isValid()) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #6385 "crash in Variable::getFlag()" @@ -2257,14 +2257,14 @@ class TestCondition : public TestFixture { " qApp->removeTranslator(mTranslator);\n" " }\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // just don't crash... check("bool f(std::ofstream &CFileStream) {\n" // #8198 " if(!CFileStream.good()) { return; }\n" " CFileStream << \"abc\";\n" " if (!CFileStream.good()) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2275,7 +2275,7 @@ class TestCondition : public TestFixture { " x = do_something();\n" " if (x != -1) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #5750 - another fp when undeclared variable is used @@ -2284,7 +2284,7 @@ class TestCondition : public TestFixture { " r += 3;\n" " if (r > w) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #6574 - another fp when undeclared variable is used @@ -2293,7 +2293,7 @@ class TestCondition : public TestFixture { " i++;\n" " if(!i) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // undeclared array @@ -2302,7 +2302,7 @@ class TestCondition : public TestFixture { " a[x] -= dt;\n" " if (a[x] < 0) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #6313 - false positive: opposite conditions in nested if blocks when condition changed @@ -2312,7 +2312,7 @@ class TestCondition : public TestFixture { " if(!var){}\n" " else {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // daca hyphy @@ -2321,7 +2321,7 @@ class TestCondition : public TestFixture { " rec.Delete(i);\n" " if (rec.lLength!=0) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2335,7 +2335,7 @@ class TestCondition : public TestFixture { " doStuff(&s);\n" " if (hasFailed) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:7]: (style) Condition '!hasFailed' is always true [knownConditionTrueFalse]\n", errout_str()); } @@ -2346,7 +2346,7 @@ class TestCondition : public TestFixture { " if (x<4) {\n" " if (x==5) {}\n" // <- Warning " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f(int x) {\n" @@ -2354,14 +2354,14 @@ class TestCondition : public TestFixture { " if (x<4) {\n" " if (x!=5) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=5' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x<4) {\n" " if (x>5) {}\n" // <- Warning " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f(int x) {\n" @@ -2369,7 +2369,7 @@ class TestCondition : public TestFixture { " if (x<4) {\n" " if (x>=5) {}\n" // <- Warning " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f(int x) {\n" @@ -2377,14 +2377,14 @@ class TestCondition : public TestFixture { " if (x<4) {\n" " if (x<5) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x<4) {\n" " if (x<=5) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=5' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" @@ -2392,49 +2392,49 @@ class TestCondition : public TestFixture { " if (x<5) {\n" " if (x==4) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" "\n" " if (x<5) {\n" " if (x!=4) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" "\n" " if (x<5) {\n" " if (x!=6) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x!=6' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x<5) {\n" " if (x>4) {}\n" // <- Warning " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x<5) {\n" " if (x>=4) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" "\n" " if (x<5) {\n" " if (x<4) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" "\n" " if (x<5) {\n" " if (x<=4) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<=4' is always true [knownConditionTrueFalse]\n", errout_str()); // first comparison: > @@ -2443,35 +2443,35 @@ class TestCondition : public TestFixture { " if (x>4) {\n" " if (x==5) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" "\n" " if (x>4) {\n" " if (x>5) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" "\n" " if (x>4) {\n" " if (x>=5) {}\n" // <- Warning " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=5' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x>4) {\n" " if (x<5) {}\n" // <- Warning " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x<5' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x>4) {\n" " if (x<=5) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" @@ -2479,7 +2479,7 @@ class TestCondition : public TestFixture { " if (x>5) {\n" " if (x==4) {}\n" // <- Warning " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f(int x) {\n" @@ -2487,21 +2487,21 @@ class TestCondition : public TestFixture { " if (x>5) {\n" " if (x>4) {}\n" // <- Warning " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>4' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x>5) {\n" " if (x>=4) {}\n" // <- Warning " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (style) Condition 'x>=4' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" "\n" " if (x>5) {\n" " if (x<4) {}\n" // <- Warning " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f(int x) {\n" @@ -2509,7 +2509,7 @@ class TestCondition : public TestFixture { " if (x>5) {\n" " if (x<=4) {}\n" // <- Warning " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:4:10]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); @@ -2517,62 +2517,62 @@ class TestCondition : public TestFixture { " if (x < 4) {\n" " if (10 < x) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); } void oppositeInnerCondition3() { - check("void f3(char c) { if(c=='x') if(c=='y') {}}"); + check("void f3(char c) { if(c=='x') if(c=='y') {}}\n"); ASSERT_EQUALS("[test.cpp:1:23] -> [test.cpp:1:34]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("void f4(char *p) { if(*p=='x') if(*p=='y') {}}"); + check("void f4(char *p) { if(*p=='x') if(*p=='y') {}}\n"); ASSERT_EQUALS("[test.cpp:1:25] -> [test.cpp:1:37]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("void f5(const char * const p) { if(*p=='x') if(*p=='y') {}}"); + check("void f5(const char * const p) { if(*p=='x') if(*p=='y') {}}\n"); ASSERT_EQUALS("[test.cpp:1:38] -> [test.cpp:1:50]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("void f5(const char * const p) { if('x'==*p) if('y'==*p) {}}"); + check("void f5(const char * const p) { if('x'==*p) if('y'==*p) {}}\n"); ASSERT_EQUALS("[test.cpp:1:39] -> [test.cpp:1:51]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("void f6(char * const p) { if(*p=='x') if(*p=='y') {}}"); + check("void f6(char * const p) { if(*p=='x') if(*p=='y') {}}\n"); ASSERT_EQUALS("[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("void f7(const char * p) { if(*p=='x') if(*p=='y') {}}"); + check("void f7(const char * p) { if(*p=='x') if(*p=='y') {}}\n"); ASSERT_EQUALS("[test.cpp:1:32] -> [test.cpp:1:44]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("void f8(int i) { if(i==4) if(i==2) {}}"); + check("void f8(int i) { if(i==4) if(i==2) {}}\n"); ASSERT_EQUALS("[test.cpp:1:22] -> [test.cpp:1:31]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("void f9(int *p) { if (*p==4) if(*p==2) {}}"); + check("void f9(int *p) { if (*p==4) if(*p==2) {}}\n"); ASSERT_EQUALS("[test.cpp:1:25] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("void f10(int * const p) { if (*p==4) if(*p==2) {}}"); + check("void f10(int * const p) { if (*p==4) if(*p==2) {}}\n"); ASSERT_EQUALS("[test.cpp:1:33] -> [test.cpp:1:43]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("void f11(const int *p) { if (*p==4) if(*p==2) {}}"); + check("void f11(const int *p) { if (*p==4) if(*p==2) {}}\n"); ASSERT_EQUALS("[test.cpp:1:32] -> [test.cpp:1:42]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("void f12(const int * const p) { if (*p==4) if(*p==2) {}}"); + check("void f12(const int * const p) { if (*p==4) if(*p==2) {}}\n"); ASSERT_EQUALS("[test.cpp:1:39] -> [test.cpp:1:49]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("struct foo {\n" " int a;\n" " int b;\n" "};\n" - "void f(foo x) { if(x.a==4) if(x.b==2) {}}"); + "void f(foo x) { if(x.a==4) if(x.b==2) {}}\n"); ASSERT_EQUALS("", errout_str()); check("struct foo {\n" " int a;\n" " int b;\n" "};\n" - "void f(foo x) { if(x.a==4) if(x.b==4) {}}"); + "void f(foo x) { if(x.a==4) if(x.b==4) {}}\n"); ASSERT_EQUALS("", errout_str()); - check("void f3(char a, char b) { if(a==b) if(a==0) {}}"); + check("void f3(char a, char b) { if(a==b) if(a==0) {}}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(int x) { if (x == 1) if (x != 1) {} }"); + check("void f(int x) { if (x == 1) if (x != 1) {} }\n"); ASSERT_EQUALS("[test.cpp:1:23] -> [test.cpp:1:35]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); } @@ -2580,8 +2580,8 @@ class TestCondition : public TestFixture { check("void f(int x) {\n" " if (a>3 && x > 100) {\n" " if (x < 10) {}\n" - " }" - "}"); + " }\n" + "}\n"); ASSERT_EQUALS("[test.cpp:2:16] -> [test.cpp:3:11]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f(bool x, const int a, const int b) {\n" @@ -2632,69 +2632,69 @@ class TestCondition : public TestFixture { } void oppositeInnerConditionEmpty() { - check("void f1(const std::string &s) { if(s.size() > 42) if(s.empty()) {}}"); + check("void f1(const std::string &s) { if(s.size() > 42) if(s.empty()) {}}\n"); ASSERT_EQUALS("[test.cpp:1:45] -> [test.cpp:1:61]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("void f1(const std::string &s) { if(s.size() > 0) if(s.empty()) {}}"); + check("void f1(const std::string &s) { if(s.size() > 0) if(s.empty()) {}}\n"); ASSERT_EQUALS("[test.cpp:1:45] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("void f1(const std::string &s) { if(s.size() < 0) if(s.empty()) {}} "); // <- CheckOther reports: checking if unsigned expression is less than zero + check("void f1(const std::string &s) { if(s.size() < 0) if(s.empty()) {}} \n"); // <- CheckOther reports: checking if unsigned expression is less than zero ASSERT_EQUALS("[test.cpp:1:45] -> [test.cpp:1:60]: (style) Condition 's.empty()' is always false [knownConditionTrueFalse]\n", errout_str()); - check("void f1(const std::string &s) { if(s.empty()) if(s.size() > 42) {}}"); + check("void f1(const std::string &s) { if(s.empty()) if(s.size() > 42) {}}\n"); ASSERT_EQUALS("[test.cpp:1:43] -> [test.cpp:1:59]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("template void f1(const T &s) { if(s.size() > 42) if(s.empty()) {}}"); + check("template void f1(const T &s) { if(s.size() > 42) if(s.empty()) {}}\n"); ASSERT_EQUALS("", errout_str()); //We don't know the type of T so we don't know the relationship between size() and empty(). e.g. s might be a 50 tonne truck with nothing in it. - check("void f2(const std::wstring &s) { if(s.empty()) if(s.size() > 42) {}}"); + check("void f2(const std::wstring &s) { if(s.empty()) if(s.size() > 42) {}}\n"); ASSERT_EQUALS("[test.cpp:1:44] -> [test.cpp:1:60]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("void f1(QString s) { if(s.isEmpty()) if(s.length() > 42) {}}"); + check("void f1(QString s) { if(s.isEmpty()) if(s.length() > 42) {}}\n"); ASSERT_EQUALS("[test.cpp:1:34] -> [test.cpp:1:52]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("void f1(const std::string &s, bool b) { if(s.empty() || ((s.size() == 1) && b)) {}}"); + check("void f1(const std::string &s, bool b) { if(s.empty() || ((s.size() == 1) && b)) {}}\n"); ASSERT_EQUALS("", errout_str()); - check("void f1(const std::string &x, const std::string &y) { if(x.size() > 42) if(y.empty()) {}}"); + check("void f1(const std::string &x, const std::string &y) { if(x.size() > 42) if(y.empty()) {}}\n"); ASSERT_EQUALS("", errout_str()); - check("void f1(const std::string &x, const std::string &y) { if(y.empty()) if(x.size() > 42) {}}"); + check("void f1(const std::string &x, const std::string &y) { if(y.empty()) if(x.size() > 42) {}}\n"); ASSERT_EQUALS("", errout_str()); - check("void f1(const std::string v[10]) { if(v[0].size() > 42) if(v[1].empty()) {}}"); + check("void f1(const std::string v[10]) { if(v[0].size() > 42) if(v[1].empty()) {}}\n"); ASSERT_EQUALS("", errout_str()); - check("void f1(const std::string &s) { if(s.size() <= 1) if(s.empty()) {}}"); + check("void f1(const std::string &s) { if(s.size() <= 1) if(s.empty()) {}}\n"); ASSERT_EQUALS("", errout_str()); - check("void f1(const std::string &s) { if(s.size() <= 2) if(s.empty()) {}}"); + check("void f1(const std::string &s) { if(s.size() <= 2) if(s.empty()) {}}\n"); ASSERT_EQUALS("", errout_str()); - check("void f1(const std::string &s) { if(s.size() < 2) if(s.empty()) {}}"); + check("void f1(const std::string &s) { if(s.size() < 2) if(s.empty()) {}}\n"); ASSERT_EQUALS("", errout_str()); - check("void f1(const std::string &s) { if(s.size() >= 0) if(s.empty()) {}} "); // CheckOther says: Unsigned expression 's.size()' can't be negative so it is unnecessary to test it. [unsignedPositive] + check("void f1(const std::string &s) { if(s.size() >= 0) if(s.empty()) {}} \n"); // CheckOther says: Unsigned expression 's.size()' can't be negative so it is unnecessary to test it. [unsignedPositive] ASSERT_EQUALS("", errout_str()); - check("void f1(const std::string &s) { if(42 < s.size()) if(s.empty()) {}}"); + check("void f1(const std::string &s) { if(42 < s.size()) if(s.empty()) {}}\n"); ASSERT_EQUALS("[test.cpp:1:39] -> [test.cpp:1:61]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); - check("void f1(const std::string &s) { if(s.empty()) if(42 < s.size()) {}}"); + check("void f1(const std::string &s) { if(s.empty()) if(42 < s.size()) {}}\n"); ASSERT_EQUALS("[test.cpp:1:43] -> [test.cpp:1:53]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str()); check("void f(const std::string& s, int n) {\n" // #14716 " if (s.size() < n)\n" " if (s.empty()) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // TODO: These are identical condition since size cannot be negative - check("void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}}"); + check("void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}}\n"); ASSERT_EQUALS("", errout_str()); // TODO: These are identical condition since size cannot be negative - check("void f1(const std::string &s) { if(s.size() < 1) if(s.empty()) {}}"); + check("void f1(const std::string &s) { if(s.size() < 1) if(s.empty()) {}}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2709,7 +2709,7 @@ class TestCondition : public TestFixture { " }\n" " void bar();\n" " int get() const;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct CD {\n" @@ -2737,7 +2737,7 @@ class TestCondition : public TestFixture { " bool b = f();\n" " x += 1;\n" " if (!b && f()) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(double d) {\n" @@ -2766,10 +2766,10 @@ class TestCondition : public TestFixture { } void identicalInnerCondition() { - check("void f1(int a, int b) { if(a==b) if(a==b) {}}"); + check("void f1(int a, int b) { if(a==b) if(a==b) {}}\n"); ASSERT_EQUALS("[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n", errout_str()); - check("void f2(int a, int b) { if(a!=b) if(a!=b) {}}"); + check("void f2(int a, int b) { if(a!=b) if(a!=b) {}}\n"); ASSERT_EQUALS("[test.cpp:1:29] -> [test.cpp:1:38]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n", errout_str()); // #6645 false negative: condition is always false @@ -2778,38 +2778,38 @@ class TestCondition : public TestFixture { " if(a) {}\n" " else {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:6] -> [test.cpp:3:9]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n", errout_str()); check("bool f(int a, int b) {\n" " if(a == b) { return a == b; }\n" " return false;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:2:27]: (warning) Identical inner 'return' condition is always true. [identicalInnerCondition]\n", errout_str()); check("bool f(bool a) {\n" " if(a) { return a; }\n" " return false;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int* f(int* a, int * b) {\n" " if(a) { return a; }\n" " return b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int* f(std::shared_ptr a, std::shared_ptr b) {\n" " if(a.get()) { return a.get(); }\n" " return b.get();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { int * x; };\n" "int* f(A a, int * b) {\n" " if(a.x) { return a.x; }\n" " return b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -2821,7 +2821,7 @@ class TestCondition : public TestFixture { " get_value (&value);\n" " if ((value >> 28) & 1) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkP("#define TYPE_1 \"a\"\n" // #13202 @@ -2833,7 +2833,7 @@ class TestCondition : public TestFixture { " if (s == TYPE_2) {}\n" " else if (s == TYPE_3) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(const int* p, const int* e) {\n" // #14595 @@ -2856,7 +2856,7 @@ class TestCondition : public TestFixture { " if (a[0] == 1) {\n" " if (a[0] == 1) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:14] -> [test.cpp:4:18]: (warning) Identical inner 'if' condition is always true. [identicalInnerCondition]\n", errout_str()); } @@ -2865,53 +2865,53 @@ class TestCondition : public TestFixture { check("void f(int x) {\n" // #8137 " if (x > 100) { return; }\n" " if (x > 100) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("bool f(int x) {\n" " if (x > 100) { return false; }\n" " return x > 100;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Identical condition and return expression 'x>100', return value is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("void f(int x) {\n" " if (x > 100) { return; }\n" " if (x > 100 || y > 100) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("void f(int x) {\n" " if (x > 100) { return; }\n" " if (x > 100 && y > 100) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("void f(int x) {\n" " if (x > 100) { return; }\n" " if (abc) {}\n" " if (x > 100) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("void f(int x) {\n" " if (x > 100) { return; }\n" " while (abc) { y = x; }\n" " if (x > 100) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:9]: (warning) Identical condition 'x>100', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); ASSERT_THROW_INTERNAL(check("void f(int x) {\n" // #8217 - crash for incomplete code " if (x > 100) { return; }\n" " X(do);\n" " if (x > 100) {}\n" - "}"), + "}\n"), SYNTAX); check("void f(const int *i) {\n" " if (!i) return;\n" " if (!num1tok) { *num1 = *num2; }\n" " if (!i) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:7] -> [test.cpp:4:7]: (warning) Identical condition '!i', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("void C::f(Tree &coreTree) {\n" // daca @@ -2919,7 +2919,7 @@ class TestCondition : public TestFixture { " return;\n" " coreTree.dostuff();\n" " if(!coreTree.build()) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct C { void f(const Tree &coreTree); };\n" @@ -2928,7 +2928,7 @@ class TestCondition : public TestFixture { " return;\n" " coreTree.dostuff();\n" " if(!coreTree.build()) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:6] -> [test.cpp:6:6]: (warning) Identical condition '!coreTree.build()', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("void f(int x) {\n" // daca: labplot @@ -2941,7 +2941,7 @@ class TestCondition : public TestFixture { " else return 4;\n" " }\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("static int failed = 0;\n" @@ -2949,14 +2949,14 @@ class TestCondition : public TestFixture { " if (failed) return;\n" " checkBuffer();\n" " if (failed) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // daca icu check("void f(const uint32_t *section, int32_t start) {\n" " if(10<=section[start]) { return; }\n" " if(++start<100 && 10<=section[start]) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // daca iqtree @@ -2966,7 +2966,7 @@ class TestCondition : public TestFixture { " if (ch != '|') return;\n" " in >> ch;\n" " if (ch != '|') {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #8924 @@ -2977,7 +2977,7 @@ class TestCondition : public TestFixture { " if (this->FileIndex < 0) return;\n" " }\n" " int FileIndex;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:29]: (style) Condition 'this->FileIndex<0' is always false [knownConditionTrueFalse]\n", errout_str()); // #8858 - #if @@ -2989,7 +2989,7 @@ class TestCondition : public TestFixture { " ret = bar2();\n" "#endif\n" " return ret;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #10456 @@ -3027,7 +3027,7 @@ class TestCondition : public TestFixture { " x += y;\n" " if (x == 0) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" @@ -3035,7 +3035,7 @@ class TestCondition : public TestFixture { " x += y;\n" " if (x == 1) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int * x, int * y) {\n" @@ -3043,7 +3043,7 @@ class TestCondition : public TestFixture { " (*y)++;\n" " if (x[*y] == 0) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void g(int[]);\n" // #14724 @@ -3052,7 +3052,7 @@ class TestCondition : public TestFixture { " g(a);\n" " if (a[0] == 1) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3061,14 +3061,14 @@ class TestCondition : public TestFixture { " if (x == 1) {\n" " if (x & 7) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:15]: (warning) Overlapping inner 'if' condition is always true. [overlappingInnerCondition]\n", errout_str()); check("void f(int x) {\n" " if (x & 7) {\n" " if (x == 1) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3076,102 +3076,102 @@ class TestCondition : public TestFixture { void clarifyCondition1() { check("void f() {\n" " if (x = b() < 0) {}\n" // don't simplify and verify this code - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:8]: (style) Suspicious condition (assignment + comparison); Clarify expression with parentheses. [clarifyCondition]\n", errout_str()); check("void f(int i) {\n" " for (i = 0; i < 10; i++) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " x = a(); if (x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " if (x = b < 0 ? 1 : 2) {}\n" // don't simplify and verify this code - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int y = rand(), z = rand();\n" " if (y || (!y && z));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\n", errout_str()); check("void f() {\n" " int y = rand(), z = rand();\n" " if (y || !y && z);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11]: (style) Redundant condition: !y. 'y || (!y && z)' is equivalent to 'y || z' [redundantCondition]\n", errout_str()); check("void f() {\n" " if (!a || a && b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (style) Redundant condition: a. '!a || (a && b)' is equivalent to '!a || b' [redundantCondition]\n", errout_str()); check("void f(const Token *tok) {\n" " if (!tok->next()->function() ||\n" " (tok->next()->function() && tok->next()->function()->isConstructor()));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:34]: (style) Redundant condition: tok->next()->function(). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\n", errout_str()); check("void f() {\n" " if (!tok->next()->function() ||\n" " (!tok->next()->function() && tok->next()->function()->isConstructor()));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " if (!tok->next()->function() ||\n" " (!tok2->next()->function() && tok->next()->function()->isConstructor()));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(const Token *tok) {\n" " if (!tok->next(1)->function(1) ||\n" " (tok->next(1)->function(1) && tok->next(1)->function(1)->isConstructor()));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:36]: (style) Redundant condition: tok->next(1)->function(1). '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]\n", errout_str()); check("void f() {\n" " if (!tok->next()->function(1) ||\n" " (tok->next()->function(2) && tok->next()->function()->isConstructor()));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int y = rand(), z = rand();\n" " if (y==0 || y!=0 && z);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:13]: (style) Redundant condition: y!=0. 'y==0 || (y!=0 && z)' is equivalent to 'y==0 || z' [redundantCondition]\n", errout_str()); check("void f() {\n" " if (x>0 || (x<0 && y)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Test Token::expressionString, TODO move this test check("void f() {\n" " if (!dead || (dead && (*it).ticks > 0)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Redundant condition: dead. '!dead || (dead && (*it).ticks>0)' is equivalent to '!dead || (*it).ticks>0' [redundantCondition]\n", errout_str()); check("void f() {\n" " if (!x || (x && (2>(y-1)))) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style) Redundant condition: x. '!x || (x && 2>(y-1))' is equivalent to '!x || 2>(y-1)' [redundantCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if (a || (a && b)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Redundant condition: a. 'a || (a && b)' is equivalent to 'a' [redundantCondition]\n", errout_str()); check("void f(bool a, bool b) {\n" " if (a && (a || b)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Redundant condition: a. 'a && (a || b)' is equivalent to 'a' [redundantCondition]\n", errout_str()); } @@ -3179,14 +3179,14 @@ class TestCondition : public TestFixture { void clarifyCondition2() { check("void f() {\n" " if (x & 3 == 2) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\n" "[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\n" "[test.cpp:2:11]: (style) Condition 'x&3==2' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " if (a & fred1.x == fred2.y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:8]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses. [clarifyCondition]\n" "[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\n" , errout_str()); @@ -3196,50 +3196,50 @@ class TestCondition : public TestFixture { void clarifyCondition3() { check("void f(int w) {\n" " if(!w & 0x8000) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\n", errout_str()); check("void f(int w) {\n" " if((!w) & 0x8000) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " if (x == foo() & 2) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\n", errout_str()); check("void f() {\n" " if (2 & x == foo()) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\n", errout_str()); check("void f() {\n" " if (2 & (x == foo())) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(std::list &ints) { }"); + check("void f(std::list &ints) { }\n"); ASSERT_EQUALS("", errout_str()); - check("void f() { A a; }"); + check("void f() { A a; }\n"); ASSERT_EQUALS("", errout_str()); - check("void f() { a(x there are never templates + check("void f() { a(x there are never templates ASSERT_EQUALS("[test.c:1:17]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses. [clarifyCondition]\n", errout_str()); - check("class A;"); + check("class A;\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " if (result != (char *)&inline_result) { }\n" // don't simplify and verify cast - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #8495 check("void f(bool a, bool b) {\n" " C & a & b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3254,13 +3254,13 @@ class TestCondition : public TestFixture { " {\n" " return left.first < right.first;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void clarifyCondition5() { // ticket #3609 (using | in template instantiation) check("template struct CWinTraits;\n" - "CWinTraits::GetWndStyle(0);"); + "CWinTraits::GetWndStyle(0);\n"); ASSERT_EQUALS("", errout_str()); } @@ -3269,7 +3269,7 @@ class TestCondition : public TestFixture { "SharedPtr& operator=( SharedPtr const & r ) {\n" " px = r.px;\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3278,7 +3278,7 @@ class TestCondition : public TestFixture { check("void f(bool error) {\n" " bool & withoutSideEffects=found.first->second;\n" // Declaring a reference to a boolean; & is no operator at all " execute(secondExpression, &programMemory, &result, &error);\n" // Unary & - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3288,24 +3288,24 @@ class TestCondition : public TestFixture { check("bool a();\n" "bool f(bool b) {\n" " return (a() & b);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(bool *a, bool b) {\n" " return (a[10] & b);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { bool a; };\n" "bool f(struct A a, bool b) {\n" " return (a.a & b);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { bool a; };\n" "bool f(struct A a, bool b) {\n" " return (A::a & b);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3313,7 +3313,7 @@ class TestCondition : public TestFixture { check("void png_parse(uint64_t init, int buf_size) {\n" " if (init == 0x89504e470d0a1a0a || init == 0x8a4d4e470d0a1a0a)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3322,7 +3322,7 @@ class TestCondition : public TestFixture { "void foo() {\n" " if( ( value >= 0x7ff0000000000001ULL )\n" " && ( value <= 0x7fffffffffffffffULL ) );\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3332,7 +3332,7 @@ class TestCondition : public TestFixture { " int x1 = s->x;\n" " int x2 = s->x;\n" " if (x1 == 10 && x2 == 10) {}\n" // << - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10] -> [test.cpp:4:22]: (style) Condition 'x2==10' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f ()\n"// #8220 @@ -3348,27 +3348,27 @@ class TestCondition : public TestFixture { " a ++;\n" " }\n" " ret = b;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:27] -> [test.cpp:8:40]: (style) Condition '8 [test.cpp:2:30]: (style) Return value 'x==0' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" // #6898 (Token::expressionString) " int x = 0;\n" " A(x++ == 1);\n" " A(x++ == 2);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9]: (style) Condition 'x++==1' is always false [knownConditionTrueFalse]\n" "[test.cpp:4:9]: (style) Condition 'x++==2' is always false [knownConditionTrueFalse]\n", errout_str()); @@ -3380,68 +3380,68 @@ class TestCondition : public TestFixture { " if (bar == 2)\n" " ret = true;\n" " return ret;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); - check("void f1(const std::string &s) { if(s.empty()) if(s.size() == 0) {}}"); + check("void f1(const std::string &s) { if(s.empty()) if(s.size() == 0) {}}\n"); ASSERT_EQUALS("[test.cpp:1:43] -> [test.cpp:1:59]: (style) Condition 's.size()==0' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int buf[42];\n" " if( buf != 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:12]: (style) Condition 'buf!=0' is always true [knownConditionTrueFalse]\n", errout_str()); // #8924 check("void f() {\n" " int buf[42];\n" " if( !buf ) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8]: (style) Condition '!buf' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int buf[42];\n" " bool b = buf;\n" " if( b ) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:8]: (style) Condition 'b' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int buf[42];\n" " bool b = buf;\n" " if( !b ) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:8]: (style) Condition '!b' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int buf[42];\n" " int * p = nullptr;\n" " if( buf == p ) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:12]: (style) Condition 'buf==p' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(bool x) {\n" " int buf[42];\n" " if( buf || x ) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8]: (style) Condition 'buf' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int * p) {\n" " int buf[42];\n" " if( buf == p ) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int buf[42];\n" " int p[42];\n" " if( buf == p ) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int buf[42];\n" " if( buf == 1) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Avoid FP when condition comes from macro @@ -3450,7 +3450,7 @@ class TestCondition : public TestFixture { " int x = 0;\n" " if (a) { return; }\n" // <- this is just here to fool simplifyKnownVariabels " if (NOT x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("#define M x != 0\n" @@ -3458,27 +3458,27 @@ class TestCondition : public TestFixture { " int x = 0;\n" " if (a) { return; }\n" // <- this is just here to fool simplifyKnownVariabels " if (M) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("#define IF(X) if (X && x())\n" "void f() {\n" " IF(1) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Avoid FP for sizeof condition check("void f() {\n" " if (sizeof(char) != 123) {}\n" " if (123 != sizeof(char)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int x = 123;\n" " if (sizeof(char) != x) {}\n" " if (x != sizeof(char)) {}\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'sizeof(char)!=x' is always true\n" "[test.cpp:4]: (style) Condition 'x!=sizeof(char)' is always true\n", "", errout_str()); @@ -3487,7 +3487,7 @@ class TestCondition : public TestFixture { check("void f() {\n" " int x = 0;\n" " assert(x == 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9363 - do not warn about value passed to function @@ -3495,7 +3495,7 @@ class TestCondition : public TestFixture { " if (b) {\n" " if (bar(!b)) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); @@ -3510,7 +3510,7 @@ class TestCondition : public TestFixture { " assert((int)(0==0));\n" " assert((int)(0==0) && \"bla\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #7750 char literals in boolean expressions @@ -3519,7 +3519,7 @@ class TestCondition : public TestFixture { " if(L'b'){}\n" " if(1 && 'c'){}\n" " int x = 'd' ? 1 : 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #8206 - knownCondition always false @@ -3527,26 +3527,26 @@ class TestCondition : public TestFixture { "{\n" " if(i > 4)\n" " for( int x = 0; i < 3; ++x){}\n" // << - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:14] -> [test.cpp:4:29]: (style) Condition 'i<3' is always false [knownConditionTrueFalse]\n", errout_str()); // Skip literals - check("void f() { if(true) {} }"); + check("void f() { if(true) {} }\n"); ASSERT_EQUALS("", errout_str()); - check("void f() { if(false) {} }"); + check("void f() { if(false) {} }\n"); ASSERT_EQUALS("", errout_str()); - check("void f() { if(!true) {} }"); + check("void f() { if(!true) {} }\n"); ASSERT_EQUALS("", errout_str()); - check("void f() { if(!false) {} }"); + check("void f() { if(!false) {} }\n"); ASSERT_EQUALS("", errout_str()); - check("void f() { if(0) {} }"); + check("void f() { if(0) {} }\n"); ASSERT_EQUALS("", errout_str()); - check("void f() { if(1) {} }"); + check("void f() { if(1) {} }\n"); ASSERT_EQUALS("", errout_str()); check("void f(int i) {\n" @@ -3555,36 +3555,36 @@ class TestCondition : public TestFixture { " else if (!b && i == 1) {}\n" " if (b)\n" " {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:14]: (style) Condition '!b' is always true [knownConditionTrueFalse]\n", errout_str()); - check("bool f() { return nullptr; }"); + check("bool f() { return nullptr; }\n"); ASSERT_EQUALS("", errout_str()); check("enum E { A };\n" - "bool f() { return A; }"); + "bool f() { return A; }\n"); ASSERT_EQUALS("", errout_str()); check("bool f() {\n" " const int x = 0;\n" " return x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); - check("int f(void){return 1/abs(10);}"); + check("int f(void){return 1/abs(10);}\n"); ASSERT_EQUALS("", errout_str()); check("bool f() {\n" " int x = 0;\n" " return x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f() {\n" " const int a = 50;\n" " const int b = 52;\n" " return a+b;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:13]: (style) Return value 'a+b' is always true [knownConditionTrueFalse]\n", errout_str()); check("int f() {\n" @@ -3593,7 +3593,7 @@ class TestCondition : public TestFixture { " a++;\n" " b++;\n" " return a+b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool& g();\n" @@ -3601,7 +3601,7 @@ class TestCondition : public TestFixture { " bool & b = g();\n" " b = false;\n" " return b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" @@ -3610,13 +3610,13 @@ class TestCondition : public TestFixture { " b = false;\n" " return b;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("bool f(long maxtime) {\n" " if (std::time(0) > maxtime)\n" " return std::time(0) > maxtime;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(double param) {\n" @@ -3626,7 +3626,7 @@ class TestCondition : public TestFixture { " }\n" " if (param<0.)\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int i) {\n" @@ -3636,7 +3636,7 @@ class TestCondition : public TestFixture { " }\n" " if (cond && (42==i))\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // 8842 crash @@ -3646,15 +3646,15 @@ class TestCondition : public TestFixture { " void f() {\n" " if (b) return;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("void f(const char* x, const char* t) {\n" " if (!(strcmp(x, y) == 0)) { return; }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(const int a[]){ if (a == 0){} }"); + check("void f(const int a[]){ if (a == 0){} }\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" @@ -3665,7 +3665,7 @@ class TestCondition : public TestFixture { " bool c = s [test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\n", errout_str()); check("int f(void *handle) {\n" " if (handle == 0) return 0;\n" " if (handle) return 1;\n" " else return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9]: (style) Condition 'handle' is always true [knownConditionTrueFalse]\n", errout_str()); check("int f(void *handle) {\n" " if (handle != 0) return 0;\n" " if (handle) return 1;\n" " else return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=0', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("int f(void *handle) {\n" " if (handle != nullptr) return 0;\n" " if (handle) return 1;\n" " else return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16] -> [test.cpp:3:9]: (warning) Identical condition 'handle!=nullptr', second condition is always false [identicalConditionAfterEarlyExit]\n", errout_str()); check("void f(const char* p) {\n" // #13716 @@ -3710,7 +3710,7 @@ class TestCondition : public TestFixture { " if (p == NULL) {}\n" " if (p == nullptr) {}\n" " if (p == 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:11]: (style) The if condition is the same as the previous if condition [duplicateCondition]\n", errout_str()); @@ -3718,7 +3718,7 @@ class TestCondition : public TestFixture { " if (p) {}\n" " else if (!p) {}\n" " else if (p == NULL) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:14]: (style) Expression is always true because 'else if' condition is opposite to previous condition at line 2. [multiCondition]\n" "[test.cpp:4:16]: (style) Expression is always false because 'else if' condition matches previous condition at line 3. [multiCondition]\n", errout_str()); @@ -3728,7 +3728,7 @@ class TestCondition : public TestFixture { " return;\n" " if (x == nullptr || y == nullptr)\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void* g();\n" @@ -3739,7 +3739,7 @@ class TestCondition : public TestFixture { " break;\n" " }\n" " if (a) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void* g();\n" @@ -3748,26 +3748,26 @@ class TestCondition : public TestFixture { " a = g();\n" " }\n" " if (a) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:12] -> [test.cpp:6:9]: (style) Condition 'a' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int * x, bool b) {\n" " if (!x && b) {}\n" " else if (x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " const std::string x=\"xyz\";\n" " if(!x.empty()){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8]: (style) Condition '!x.empty()' is always true [knownConditionTrueFalse]\n", errout_str()); check("std::string g();\n" "void f() {\n" " const std::string msg = g();\n" " if(!msg.empty()){}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int *array, int size ) {\n" @@ -3776,7 +3776,7 @@ class TestCondition : public TestFixture { " continue;\n" " if(array){}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:12]: (style) Condition 'array' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int *array, int size ) {\n" @@ -3785,7 +3785,7 @@ class TestCondition : public TestFixture { " continue;\n" " else if(array){}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:17]: (style) Condition 'array' is always true [knownConditionTrueFalse]\n", errout_str()); // #9277 @@ -3795,7 +3795,7 @@ class TestCondition : public TestFixture { " return 0;\n" " else\n" " return 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9954 @@ -3817,7 +3817,7 @@ class TestCondition : public TestFixture { " bool x = false;\n" " g({0, 1}, x);\n" " if (x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9318 @@ -3828,7 +3828,7 @@ class TestCondition : public TestFixture { " return;\n" " auto b = dynamic_cast(x);\n" " if (b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int foo() {\n" @@ -3846,7 +3846,7 @@ class TestCondition : public TestFixture { check("bool g();\n" "void f(bool x) {\n" " if (x) while(x) x = g();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // isLikelyStream @@ -3856,7 +3856,7 @@ class TestCondition : public TestFixture { " iss >> x;\n" " if (!iss) break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9332 @@ -3868,14 +3868,14 @@ class TestCondition : public TestFixture { " void* c = a.g();\n" " if (!c) return;\n" " bool compare = c == b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9361 check("void f(char c) {\n" " if (c == '.') {}\n" " else if (isdigit(c) != 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9351 @@ -3883,7 +3883,7 @@ class TestCondition : public TestFixture { " const bool b = x < 42;\n" " if(b) return b?0:-1;\n" " return 42;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:3:18]: (style) Condition 'b' is always true [knownConditionTrueFalse]\n", errout_str()); // #9362 @@ -3893,7 +3893,7 @@ class TestCondition : public TestFixture { " if((v != 0x00)) {\n" " if( (v & 0x01) == 0x00) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9367 @@ -3902,25 +3902,25 @@ class TestCondition : public TestFixture { " return;\n" " if (x % 360L == 0)\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(int a, int b) {\n" " static const int x = 10;\n" " return x == 1 ? a : b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("const bool x = false;\n" "void f() {\n" " if (x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("const bool x = false;\n" "void f() {\n" " if (!x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9709 @@ -3931,7 +3931,7 @@ class TestCondition : public TestFixture { " if (r != nullptr)\n" " ok = a != 0;\n" " if (ok) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9816 @@ -4120,7 +4120,7 @@ class TestCondition : public TestFixture { check("void foo(unsigned int max) {\n" " unsigned int num = max - 1;\n" " if (num < 0) {}\n" // <- do not report knownConditionTrueFalse - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #10297 @@ -4459,7 +4459,7 @@ class TestCondition : public TestFixture { ASSERT_EQUALS("", errout_str()); // #8358 - check("void f(double d) { if ((d * 0) != 0) {} }"); + check("void f(double d) { if ((d * 0) != 0) {} }\n"); ASSERT_EQUALS("", errout_str()); // #6870 @@ -4819,7 +4819,7 @@ class TestCondition : public TestFixture { " return 9;\n" " \n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int g();\n" // #10561 @@ -4834,7 +4834,7 @@ class TestCondition : public TestFixture { " }\n" " catch (...) {}\n" " return b ? 1 : 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" @@ -4990,10 +4990,10 @@ class TestCondition : public TestFixture { "}\n"); ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:4:14]: (style) Condition 'x==y' is always false [knownConditionTrueFalse]\n", errout_str()); - check("void f(bool a, bool b) { if (a == b && a && !b){} }"); + check("void f(bool a, bool b) { if (a == b && a && !b){} }\n"); ASSERT_EQUALS("[test.cpp:1:41] -> [test.cpp:1:46]: (style) Condition '!b' is always false [knownConditionTrueFalse]\n", errout_str()); - check("bool f(bool a, bool b) { if(a && b && (!a)){} }"); + check("bool f(bool a, bool b) { if(a && b && (!a)){} }\n"); ASSERT_EQUALS("[test.cpp:1:29] -> [test.cpp:1:40]: (style) Condition '!a' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int x, int y) {\n" @@ -5205,7 +5205,7 @@ class TestCondition : public TestFixture { "}\n"); ASSERT_EQUALS("", errout_str()); - check("struct A { int x; int y; };" + check("struct A { int x; int y; };\n" "void use(int);\n" "void test(A a) {\n" " int i = a.x;\n" @@ -5214,10 +5214,10 @@ class TestCondition : public TestFixture { " if (i == j) {}\n" " if (i == a.x) {}\n" " if (j == a.x) {}\n" - "}"); - ASSERT_EQUALS("[test.cpp:6:11]: (style) Condition 'i==j' is always true [knownConditionTrueFalse]\n" - "[test.cpp:7:11]: (style) Condition 'i==a.x' is always true [knownConditionTrueFalse]\n" - "[test.cpp:8:11]: (style) Condition 'j==a.x' is always true [knownConditionTrueFalse]\n", + "}\n"); + ASSERT_EQUALS("[test.cpp:7:11]: (style) Condition 'i==j' is always true [knownConditionTrueFalse]\n" + "[test.cpp:8:11]: (style) Condition 'i==a.x' is always true [knownConditionTrueFalse]\n" + "[test.cpp:9:11]: (style) Condition 'j==a.x' is always true [knownConditionTrueFalse]\n", errout_str()); check("struct S { int i; };\n" // #12795 @@ -5258,7 +5258,7 @@ class TestCondition : public TestFixture { " x++;\n" " if (x == 1) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x==1' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" @@ -5266,7 +5266,7 @@ class TestCondition : public TestFixture { " x++;\n" " if (x != 1) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:4:15]: (style) Condition 'x!=1' is always true [knownConditionTrueFalse]\n", errout_str()); // #6890 @@ -5278,7 +5278,7 @@ class TestCondition : public TestFixture { " if (x == -1) {}\n" " else {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x==-1' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" @@ -5289,7 +5289,7 @@ class TestCondition : public TestFixture { " if (x != -1) {}\n" " else {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x!=-1' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" @@ -5300,7 +5300,7 @@ class TestCondition : public TestFixture { " if (x >= -1) {}\n" " else {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>=-1' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" @@ -5311,7 +5311,7 @@ class TestCondition : public TestFixture { " if (x > -1) {}\n" " else {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>-1' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" @@ -5322,7 +5322,7 @@ class TestCondition : public TestFixture { " if (x < -1) {}\n" " else {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<-1' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" @@ -5333,7 +5333,7 @@ class TestCondition : public TestFixture { " if (x <= -1) {}\n" " else {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x<=-1' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" @@ -5344,7 +5344,7 @@ class TestCondition : public TestFixture { " if (x > 7) {}\n" " else {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:6:15]: (style) Condition 'x>7' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(int i) {\n" @@ -5355,7 +5355,7 @@ class TestCondition : public TestFixture { " if (x > 9) {}\n" " else {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int i) {\n" @@ -5366,7 +5366,7 @@ class TestCondition : public TestFixture { " if (x > 10) {}\n" " else {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #11100 @@ -5391,7 +5391,7 @@ class TestCondition : public TestFixture { " if(pos > 0)\n" " --pos;\n" " return pos;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:5:16]: (style) Condition 'pos>0' is always true [knownConditionTrueFalse]\n", errout_str()); // #9721 @@ -5400,7 +5400,7 @@ class TestCondition : public TestFixture { " if ( (x>255) || (-128>x) )\n" " return;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:30]: (style) Condition '-128>x' is always false [knownConditionTrueFalse]\n", errout_str()); // #8778 @@ -5414,7 +5414,7 @@ class TestCondition : public TestFixture { check("void f() {\n" " for(int x = 0; x < 3; ++x)\n" " if(x == -5) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:14]: (style) Condition 'x==-5' is always false [knownConditionTrueFalse]\n", errout_str()); // #8407 @@ -5423,7 +5423,7 @@ class TestCondition : public TestFixture { " if(i == 0) return 1; \n" // << " else return 0;\n" " return -1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:14]: (style) Condition 'i==0' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f(unsigned int u1, unsigned int u2) {\n" @@ -5495,7 +5495,7 @@ class TestCondition : public TestFixture { " c2(g );\n" " if ( !g.empty() )\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int flag) {\n" @@ -5506,7 +5506,7 @@ class TestCondition : public TestFixture { " c2(g );\n" " if ( !g.empty() )\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" @@ -5717,7 +5717,7 @@ class TestCondition : public TestFixture { " {;}\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:20] -> [test.cpp:7:27]: (style) Condition 'i==1' is always true [knownConditionTrueFalse]\n", errout_str()); // #10863 @@ -5831,7 +5831,7 @@ class TestCondition : public TestFixture { void alwaysTruePremiumMisra() { const char code[] = "void f() {\n" " if (3 > 2) {}\n" - "}"; + "}\n"; check(code); ASSERT_EQUALS("", errout_str()); @@ -5847,7 +5847,7 @@ class TestCondition : public TestFixture { " int val = 0;\n" " if (val < 0) continue;\n" " if (val > 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -5855,7 +5855,7 @@ class TestCondition : public TestFixture { " if (val < 0) {\n" " if (val > 0) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -5863,7 +5863,7 @@ class TestCondition : public TestFixture { " if (val < 0) {\n" " if (val < 0) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -5871,7 +5871,7 @@ class TestCondition : public TestFixture { " int foo = 0;\n" " if (activate) {}\n" " else if (foo) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7]: (style) Condition 'activate' is always false [knownConditionTrueFalse]\n" "[test.cpp:5:12]: (style) Condition 'foo' is always false [knownConditionTrueFalse]\n", errout_str()); @@ -5879,7 +5879,7 @@ class TestCondition : public TestFixture { check("void f() {\n" " const int b[2] = { 1,0 };\n" " if(b[1] == 2) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11]: (style) Condition 'b[1]==2' is always false [knownConditionTrueFalse]\n", errout_str()); // #9878 @@ -5896,40 +5896,40 @@ class TestCondition : public TestFixture { check("void f(bool x) {\n" " if(x) {}\n" " if(x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:8] -> [test.cpp:3:8]: (style) The if condition is the same as the previous if condition [duplicateCondition]\n", errout_str()); check("void f(int x) {\n" " if(x == 1) {}\n" " if(x == 1) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:3:10]: (style) The if condition is the same as the previous if condition [duplicateCondition]\n", errout_str()); check("void f(int x) {\n" " if(x == 1) {}\n" " if(x == 2) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if(x == 1) {}\n" " if(x != 1) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool x) {\n" " if(x) {}\n" " g();\n" " if(x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if(x == 1) { x++; }\n" " if(x == 1) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #8996 @@ -5941,7 +5941,7 @@ class TestCondition : public TestFixture { " g(d);\n" " if (a) {}\n" " if (b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9311 @@ -5956,7 +5956,7 @@ class TestCondition : public TestFixture { " g(d);\n" " if (a) {}\n" " if (b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #8993 @@ -5964,7 +5964,7 @@ class TestCondition : public TestFixture { " auto y = x;\n" " if (x.empty()) y = \"1\";\n" " if (y.empty()) return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9106 @@ -5972,7 +5972,7 @@ class TestCondition : public TestFixture { "void f(A a, int c) {\n" " if (a.b) a.b = c;\n" " if (a.b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" @@ -6094,7 +6094,7 @@ class TestCondition : public TestFixture { " ;\n" " if (other.mPA.cols > 0 && other.mPA.rows > 0)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" // #11202 @@ -6143,27 +6143,27 @@ class TestCondition : public TestFixture { void checkInvalidTestForOverflow() { check("void f(char *p, unsigned int x) {\n" " assert((p + x) < p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)= p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20]: (warning) Invalid test for overflow '(p+x)>=p'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\n", errout_str()); check("void f(char *p, unsigned int x) {\n" " assert(p > (p + x));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (warning) Invalid test for overflow 'p>(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always false. [invalidTestForOverflow]\n", errout_str()); check("void f(char *p, unsigned int x) {\n" " assert(p <= (p + x));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (warning) Invalid test for overflow 'p<=(p+x)'; pointer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always true. [invalidTestForOverflow]\n", errout_str()); check("void f(signed int x) {\n" // unsigned overflow => don't warn " assert(x + 100U < x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); @@ -6171,57 +6171,57 @@ class TestCondition : public TestFixture { #define MSG(EXPR, RESULT) "[test.cpp:1:30]: (warning) Invalid test for overflow '" EXPR "'; signed integer overflow is undefined behavior. Some mainstream compilers remove such overflow tests when optimising the code and assume it's always " RESULT ". [invalidTestForOverflow]\n" - check("int f(int x) { return x + 10 > x; }"); + check("int f(int x) { return x + 10 > x; }\n"); ASSERT_EQUALS(MSG("x+10>x", "true"), errout_str()); - check("int f(int x) { return x + 10 >= x; }"); + check("int f(int x) { return x + 10 >= x; }\n"); ASSERT_EQUALS(MSG("x+10>=x", "true"), errout_str()); - check("int f(int x) { return x + 10 < x; }"); + check("int f(int x) { return x + 10 < x; }\n"); ASSERT_EQUALS(MSG("x+10 x; }"); + check("int f(int x) { return x - 10 > x; }\n"); ASSERT_EQUALS(MSG("x-10>x", "false"), errout_str()); - check("int f(int x) { return x - 10 >= x; }"); + check("int f(int x) { return x - 10 >= x; }\n"); ASSERT_EQUALS(MSG("x-10>=x", "false"), errout_str()); - check("int f(int x) { return x - 10 < x; }"); + check("int f(int x) { return x - 10 < x; }\n"); ASSERT_EQUALS(MSG("x-10 x; }"); + check("int f(int x, int y) { return x + y > x; }\n"); ASSERT_EQUALS(MSG("x+y>x", "y>0"), errout_str()); - check("int f(int x, int y) { return x + y >= x; }"); + check("int f(int x, int y) { return x + y >= x; }\n"); ASSERT_EQUALS(MSG("x+y>=x", "y>=0"), errout_str()); // x - y < x - check("int f(int x, int y) { return x - y < x; }"); + check("int f(int x, int y) { return x - y < x; }\n"); ASSERT_EQUALS(MSG("x-y0"), errout_str()); - check("int f(int x, int y) { return x - y <= x; }"); + check("int f(int x, int y) { return x - y <= x; }\n"); ASSERT_EQUALS(MSG("x-y<=x", "y>=0"), errout_str()); - check("int f(int x, int y) { return x - y > x; }"); + check("int f(int x, int y) { return x - y > x; }\n"); ASSERT_EQUALS(MSG("x-y>x", "y<0"), errout_str()); - check("int f(int x, int y) { return x - y >= x; }"); + check("int f(int x, int y) { return x - y >= x; }\n"); ASSERT_EQUALS(MSG("x-y>=x", "y<=0"), errout_str()); } @@ -6230,55 +6230,55 @@ class TestCondition : public TestFixture { " enum states {A,B,C};\n" " const unsigned g_flags = B|C;\n" " if(g_flags & A) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:16]: (style) Condition 'g_flags&A' is always false [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int a = 5;" " if(a) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:22]: (style) Condition 'a' is always true [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int a = 5;" " while(a + 1) { a--; }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int a = 5;" " while(a + 1) { return; }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:27]: (style) Condition 'a+1' is always true [knownConditionTrueFalse]\n", errout_str()); } void alwaysTrueFalseInLogicalOperators() { check("bool f();\n" - "void foo() { bool x = true; if(x||f()) {}}"); + "void foo() { bool x = true; if(x||f()) {}}\n"); ASSERT_EQUALS("[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\n", errout_str()); - check("void foo(bool b) { bool x = true; if(x||b) {}}"); + check("void foo(bool b) { bool x = true; if(x||b) {}}\n"); ASSERT_EQUALS("[test.cpp:1:38]: (style) Condition 'x' is always true [knownConditionTrueFalse]\n", errout_str()); - check("void foo(bool b) { if(true||b) {}}"); + check("void foo(bool b) { if(true||b) {}}\n"); ASSERT_EQUALS("", errout_str()); check("bool f();\n" - "void foo() { bool x = false; if(x||f()) {}}"); + "void foo() { bool x = false; if(x||f()) {}}\n"); ASSERT_EQUALS("[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\n", errout_str()); check("bool f();\n" - "void foo() { bool x = false; if(x&&f()) {}}"); + "void foo() { bool x = false; if(x&&f()) {}}\n"); ASSERT_EQUALS("[test.cpp:2:33]: (style) Condition 'x' is always false [knownConditionTrueFalse]\n", errout_str()); - check("void foo(bool b) { bool x = false; if(x&&b) {}}"); + check("void foo(bool b) { bool x = false; if(x&&b) {}}\n"); ASSERT_EQUALS("[test.cpp:1:39]: (style) Condition 'x' is always false [knownConditionTrueFalse]\n", errout_str()); - check("void foo(bool b) { if(false&&b) {}}"); + check("void foo(bool b) { if(false&&b) {}}\n"); ASSERT_EQUALS("", errout_str()); check("bool f();\n" - "void foo() { bool x = true; if(x&&f()) {}}"); + "void foo() { bool x = true; if(x&&f()) {}}\n"); ASSERT_EQUALS("[test.cpp:2:32]: (style) Condition 'x' is always true [knownConditionTrueFalse]\n", errout_str()); // #9578 @@ -6303,7 +6303,7 @@ class TestCondition : public TestFixture { " if (!b) {\n" " bool x = a || b;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:18]: (style) Condition '!b' is always false [knownConditionTrueFalse]\n" "[test.cpp:7:9] -> [test.cpp:8:23]: (style) Condition 'b' is always false [knownConditionTrueFalse]\n", errout_str()); @@ -6312,7 +6312,7 @@ class TestCondition : public TestFixture { void pointerAdditionResultNotNull() { check("void f(char *ptr) {\n" " if (ptr + 1 != 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning) Comparison is wrong. Result of 'ptr+1' can't be 0 unless there is pointer overflow, and pointer overflow is undefined behaviour. [pointerAdditionResultNotNull]\n", errout_str()); } @@ -6322,7 +6322,7 @@ class TestCondition : public TestFixture { check("void f(int& x, int y) {\n" " if (x == y)\n" " x = y;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\n" "[test.cpp:2:11]: note: Condition 'x==y'\n" "[test.cpp:3:11]: note: Assignment 'x=y' is redundant\n", errout_str()); @@ -6330,7 +6330,7 @@ class TestCondition : public TestFixture { check("void f(int& x, int y) {\n" " if (x != y)\n" " x = y;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: style: The statement 'if (x!=y) x=y' is logically equivalent to 'x=y'. [duplicateConditionalAssign]\n" "[test.cpp:3:11]: note: Assignment 'x=y'\n" "[test.cpp:2:11]: note: Condition 'x!=y' is redundant\n", errout_str()); @@ -6340,7 +6340,7 @@ class TestCondition : public TestFixture { " x = y;\n" " else\n" " x = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11]: style: Assignment 'x=y' is redundant with condition 'x==y'. [duplicateConditionalAssign]\n" "[test.cpp:2:11]: note: Condition 'x==y'\n" "[test.cpp:3:11]: note: Assignment 'x=y' is redundant\n", errout_str()); @@ -6350,13 +6350,13 @@ class TestCondition : public TestFixture { " x = y;\n" " else\n" " x = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int& x, int y) {\n" " if (x == y)\n" " x = y + 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void g();\n" @@ -6365,7 +6365,7 @@ class TestCondition : public TestFixture { " x = y;\n" " g();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(bool b) {\n" @@ -6411,12 +6411,12 @@ class TestCondition : public TestFixture { void checkAssignmentInCondition() { check("void f(std::string s) {\n" " if (s=\"123\"){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style) Suspicious assignment in condition. Condition 's=\"123\"' is always true. [assignmentInCondition]\n", errout_str()); check("void f(std::string *p) {\n" " if (p=foo()){}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(uint32_t u) {\n" // #2490 @@ -6432,65 +6432,65 @@ class TestCondition : public TestFixture { check("void f(unsigned char c) {\n" " if (c == 256) {}\n" - "}", settingsUnix64); + "}\n", settingsUnix64); ASSERT_EQUALS("[test.cpp:2:12]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\n", errout_str()); check("void f(unsigned char* b, int i) {\n" // #6372 " if (b[i] == 256) {}\n" - "}", settingsUnix64); + "}\n", settingsUnix64); ASSERT_EQUALS("[test.cpp:2:15]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false. [compareValueOutOfTypeRangeError]\n", errout_str()); check("void f(unsigned char c) {\n" " if (c == 255) {}\n" - "}", settingsUnix64); + "}\n", settingsUnix64); ASSERT_EQUALS("", errout_str()); check("void f(bool b) {\n" " if (b == true) {}\n" - "}", settingsUnix64); + "}\n", settingsUnix64); ASSERT_EQUALS("", errout_str()); // #10372 check("void f(signed char x) {\n" " if (x == 0xff) {}\n" - "}", settingsUnix64); + "}\n", settingsUnix64); ASSERT_EQUALS("[test.cpp:2:12]: (style) Comparing expression of type 'signed char' against value 255. Condition is always false. [compareValueOutOfTypeRangeError]\n", errout_str()); check("void f(short x) {\n" " if (x == 0xffff) {}\n" - "}", settingsUnix64); + "}\n", settingsUnix64); ASSERT_EQUALS("[test.cpp:2:12]: (style) Comparing expression of type 'signed short' against value 65535. Condition is always false. [compareValueOutOfTypeRangeError]\n", errout_str()); check("void f(int x) {\n" " if (x == 0xffffffff) {}\n" - "}", settingsUnix64); + "}\n", settingsUnix64); ASSERT_EQUALS("", errout_str()); check("void f(long x) {\n" " if (x == ~0L) {}\n" - "}", settingsUnix64); + "}\n", settingsUnix64); ASSERT_EQUALS("", errout_str()); check("void f(long long x) {\n" " if (x == ~0LL) {}\n" - "}", settingsUnix64); + "}\n", settingsUnix64); ASSERT_EQUALS("", errout_str()); check("int f(int x) {\n" " const int i = 0xFFFFFFFF;\n" " if (x == i) {}\n" - "}", settingsUnix64); + "}\n", settingsUnix64); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " char c;\n" " if ((c = foo()) != -1) {}\n" - "}", settingsUnix64); + "}\n", settingsUnix64); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " if (x < 3000000000) {}\n" - "}", settingsUnix64); + "}\n", settingsUnix64); ASSERT_EQUALS("[test.cpp:2:11]: (style) Comparing expression of type 'signed int' against value 3000000000. Condition is always true. [compareValueOutOfTypeRangeError]\n", errout_str()); check("void f(const signed char i) {\n" // #8545 @@ -6624,7 +6624,7 @@ class TestCondition : public TestFixture { " }\n" "\n" " S1 mS;\n" - "};" + "};\n" ); ASSERT_EQUALS("[test.cpp:13:11] -> [test.cpp:18:13]: (style) Condition 'mS.b' is always false [knownConditionTrueFalse]\n", errout_str()); } diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 5f2fd228dc4..4de49f54311 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -240,21 +240,21 @@ class TestConstructors : public TestFixture { "{\n" "public:\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class Fred\n" "{\n" "private:\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:1:1]: (style) The class 'Fred' does not declare a constructor although it has private member variables which likely require initialization. [noConstructor]\n", errout_str()); check("struct Fred\n" "{\n" "private:\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:1:1]: (style) The struct 'Fred' does not declare a constructor although it has private member variables which likely require initialization. [noConstructor]\n", errout_str()); } @@ -267,7 +267,7 @@ class TestConstructors : public TestFixture { " Fred(Fred const & other) : i(other.i) {}\n" " Fred(Fred && other) : i(other.i) {}\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class Fred\n" @@ -277,7 +277,7 @@ class TestConstructors : public TestFixture { " Fred(Fred const & other) {i=other.i}\n" " Fred(Fred && other) {i=other.i}\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class Fred\n" @@ -287,7 +287,7 @@ class TestConstructors : public TestFixture { " Fred(Fred const & other) {}\n" " Fred(Fred && other) {}\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:5:5]: (warning) Member variable 'Fred::i' is not initialized in the copy constructor. [uninitMemberVar]\n" "[test.cpp:6:5]: (warning) Member variable 'Fred::i' is not initialized in the move constructor. [uninitMemberVar]\n", errout_str()); @@ -298,7 +298,7 @@ class TestConstructors : public TestFixture { " Fred(Fred const & other) {}\n" " Fred(Fred && other) {}\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:4:5]: (warning) Member variable 'Fred::i' is not initialized in the copy constructor. [uninitMemberVar]\n" "[test.cpp:5:5]: (warning) Member variable 'Fred::i' is not initialized in the move constructor. [uninitMemberVar]\n", errout_str()); @@ -312,7 +312,7 @@ class TestConstructors : public TestFixture { " int i;\n" "};\n" "Fred::Fred() :i(0)\n" - "{ }"); + "{ }\n"); ASSERT_EQUALS("", errout_str()); check("struct Fred\n" @@ -321,7 +321,7 @@ class TestConstructors : public TestFixture { " int i;\n" "};\n" "Fred::Fred()\n" - "{ i = 0; }"); + "{ i = 0; }\n"); ASSERT_EQUALS("", errout_str()); check("struct Fred\n" @@ -330,7 +330,7 @@ class TestConstructors : public TestFixture { " int i;\n" "};\n" "Fred::Fred()\n" - "{ }"); + "{ }\n"); ASSERT_EQUALS("[test.cpp:6:7]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -365,7 +365,7 @@ class TestConstructors : public TestFixture { " }\n" "private:\n" " int mValue;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -375,7 +375,7 @@ class TestConstructors : public TestFixture { " A(const T & t) { x = t.x; }\n" "private:\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("template struct A {\n" @@ -383,7 +383,7 @@ class TestConstructors : public TestFixture { " A(const T & t) : x(t.x) { }\n" "private:\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("template struct A {\n" @@ -392,7 +392,7 @@ class TestConstructors : public TestFixture { "private:\n" " int x;\n" " int y;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning) Member variable 'A::y' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:3:5]: (warning) Member variable 'A::y' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -401,14 +401,14 @@ class TestConstructors : public TestFixture { check("class Fred;\n" "struct Fred {\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } void simple8() { check("struct Fred { int x; };\n" "class Barney { Fred fred; };\n" - "class Wilma { struct Betty { int x; } betty; };"); + "class Wilma { struct Betty { int x; } betty; };\n"); ASSERT_EQUALS("[test.cpp:2:1]: (style) The class 'Barney' does not declare a constructor although it has private member variables which likely require initialization. [noConstructor]\n" "[test.cpp:3:1]: (style) The class 'Wilma' does not declare a constructor although it has private member variables which likely require initialization. [noConstructor]\n", errout_str()); } @@ -419,7 +419,7 @@ class TestConstructors : public TestFixture { " Fred() : x(0) { }\n" "private:\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -429,7 +429,7 @@ class TestConstructors : public TestFixture { " Fred() = default;\n" "private:\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'Fred::x' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct S {\n" // #9391 @@ -457,7 +457,7 @@ class TestConstructors : public TestFixture { " int b{1}, c{2};\n" " int d, e{3};\n" " int f{4}, g;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'Fred::d' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:3:5]: (warning) Member variable 'Fred::g' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -469,7 +469,7 @@ class TestConstructors : public TestFixture { " Fred() { Init(); }\n" " void Init(int i = 0);\n" "};\n" - "void Fred::Init(int i) { x = i; }"); + "void Fred::Init(int i) { x = i; }\n"); ASSERT_EQUALS("", errout_str()); check("class Fred {\n" @@ -479,7 +479,7 @@ class TestConstructors : public TestFixture { " Fred() { Init(0); }\n" " void Init(int i, int j = 0);\n" "};\n" - "void Fred::Init(int i, int j) { x = i; y = j; }"); + "void Fred::Init(int i, int j) { x = i; y = j; }\n"); ASSERT_EQUALS("", errout_str()); } @@ -487,7 +487,7 @@ class TestConstructors : public TestFixture { check("class Fred {\n" " int x=1;\n" " int *y=0;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -500,7 +500,7 @@ class TestConstructors : public TestFixture { " {}\n" "private:\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class Fred : public Base {" @@ -511,7 +511,7 @@ class TestConstructors : public TestFixture { " {}\n" "private:\n" " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -590,7 +590,7 @@ class TestConstructors : public TestFixture { check("class Fred\n" "{\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:1:1]: (style) The class 'Fred' does not declare a constructor although it has private member variables which likely require initialization. [noConstructor]\n", errout_str()); } @@ -602,7 +602,7 @@ class TestConstructors : public TestFixture { "};\n" "\n" "void Fred::foobar()\n" - "{ }"); + "{ }\n"); ASSERT_EQUALS("", errout_str()); } @@ -611,7 +611,7 @@ class TestConstructors : public TestFixture { "{\n" "private:\n" " static int foobar;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -620,7 +620,7 @@ class TestConstructors : public TestFixture { "{\n" "public:\n" " int foobar;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -628,7 +628,7 @@ class TestConstructors : public TestFixture { check("namespace Foo\n" "{\n" " int i;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -642,14 +642,14 @@ class TestConstructors : public TestFixture { "private:\n" " cpucyclesT m_v;\n" " bool m_b;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } void noConstructor7() { // ticket #4391 check("short bar;\n" - "class foo;"); + "class foo;\n"); ASSERT_EQUALS("", errout_str()); } @@ -657,7 +657,7 @@ class TestConstructors : public TestFixture { // ticket #4404 check("class LineSegment;\n" "class PointArray { };\n" - "void* tech_ = NULL;"); + "void* tech_ = NULL;\n"); ASSERT_EQUALS("", errout_str()); } @@ -668,7 +668,7 @@ class TestConstructors : public TestFixture { " CGreeting() : CGreetingBase(), MessageSet(false) {}\n" "private:\n" " bool MessageSet;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -688,28 +688,28 @@ class TestConstructors : public TestFixture { " virtual ~A();\n" "private:\n" " wxTimer *WxTimer1;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } void noConstructor11() { // #3552 check("class Fred { int x; };\n" - "union U { int y; Fred fred; };"); + "union U { int y; Fred fred; };\n"); ASSERT_EQUALS("", errout_str()); } void noConstructor12() { // #8951 - check("class Fred { int x{0}; };"); + check("class Fred { int x{0}; };\n"); ASSERT_EQUALS("", errout_str()); - check("class Fred { int x=0; };"); + check("class Fred { int x=0; };\n"); ASSERT_EQUALS("", errout_str()); - check("class Fred { int x[1]={0}; };"); // #8850 + check("class Fred { int x[1]={0}; };\n"); // #8850 ASSERT_EQUALS("", errout_str()); - check("class Fred { int x[1]{0}; };"); + check("class Fred { int x[1]{0}; };\n"); ASSERT_EQUALS("", errout_str()); } @@ -803,15 +803,15 @@ class TestConstructors : public TestFixture { // ticket #3190 "SymbolDatabase: Parse of sub class constructor fails" void forwardDeclaration() { check("class foo;\n" - "int bar;"); + "int bar;\n"); ASSERT_EQUALS("", errout_str()); check("class foo;\n" - "class foo;"); + "class foo;\n"); ASSERT_EQUALS("", errout_str()); check("class foo{};\n" - "class foo;"); + "class foo;\n"); ASSERT_EQUALS("", errout_str()); } @@ -821,7 +821,7 @@ class TestConstructors : public TestFixture { " Fred()\n" " { this->i = 0; }\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -836,7 +836,7 @@ class TestConstructors : public TestFixture { " i = 1;\n" " }\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -855,7 +855,7 @@ class TestConstructors : public TestFixture { "\n" " const Fred & operator=(const Fred &fred)\n" " { i = fred.i; return *this; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct Fred {\n" @@ -866,7 +866,7 @@ class TestConstructors : public TestFixture { "\n" " const Fred & operator=(const Fred &fred)\n" " { i = fred.i; return *this; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct A\n" @@ -881,7 +881,7 @@ class TestConstructors : public TestFixture { "\n" " int i;\n" " int j;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -892,7 +892,7 @@ class TestConstructors : public TestFixture { " Fred() { i = 0; }\n" " void operator=(const Fred &fred) { }\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:10]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); } @@ -904,7 +904,7 @@ class TestConstructors : public TestFixture { "private:\n" " void Init() { i = 0; }\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -921,7 +921,7 @@ class TestConstructors : public TestFixture { " }\n" " return *this\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:12]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); check("class Fred\n" @@ -936,7 +936,7 @@ class TestConstructors : public TestFixture { " }\n" " return *this\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:12]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); check("class Fred\n" @@ -951,7 +951,7 @@ class TestConstructors : public TestFixture { " }\n" " return *this\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:12]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); check("class Fred\n" @@ -966,7 +966,7 @@ class TestConstructors : public TestFixture { " }\n" " return *this\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -981,7 +981,7 @@ class TestConstructors : public TestFixture { " Fred(rhs).swap(*this);\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -991,7 +991,7 @@ class TestConstructors : public TestFixture { " Fred & operator=(const Fred &rhs) {\n" " return *this;\n" " }\n" - "};",dinit(CheckOptions, $.inconclusive = true)); + "};\n",dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:3:12]: (warning, inconclusive) Member variable 'Fred::data' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); check("struct Fred {\n" @@ -999,7 +999,7 @@ class TestConstructors : public TestFixture { " Fred & operator=(const Fred &rhs) {\n" " return *this;\n" " }\n" - "};",dinit(CheckOptions, $.inconclusive = true)); + "};\n",dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:3:12]: (warning, inconclusive) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); check("struct Fred {\n" @@ -1007,7 +1007,7 @@ class TestConstructors : public TestFixture { " Fred & operator=(const Fred &rhs) {\n" " return *this;\n" " }\n" - "};",dinit(CheckOptions, $.inconclusive = true)); + "};\n",dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:3:12]: (warning, inconclusive) Member variable 'Fred::data' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); } @@ -1113,7 +1113,7 @@ class TestConstructors : public TestFixture { " int b;\n" " Fred() { b = 0; }\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); @@ -1133,7 +1133,7 @@ class TestConstructors : public TestFixture { " int b;\n" " Fred() { b = 0; }\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); @@ -1153,7 +1153,7 @@ class TestConstructors : public TestFixture { " int b;\n" " Fred() { b = 0; }\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); @@ -1175,7 +1175,7 @@ class TestConstructors : public TestFixture { " Fred() { b = 0; }\n" " };\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -1197,7 +1197,7 @@ class TestConstructors : public TestFixture { " Fred() { }\n" " };\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:7:13]: (warning) Member variable 'Fred::a' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:16:13]: (warning) Member variable 'Fred::b' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); @@ -1217,7 +1217,7 @@ class TestConstructors : public TestFixture { "c::c()\n" "{\n" " m_iMyInt1 = m_iMyInt2 = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1250,7 +1250,7 @@ class TestConstructors : public TestFixture { "void c::InitInt()\n" "{\n" " m_iMyInt = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1263,7 +1263,7 @@ class TestConstructors : public TestFixture { " Fred();\n" "};\n" "Fred::Fred() : s(NULL)\n" - "{ }"); + "{ }\n"); ASSERT_EQUALS("", errout_str()); check("struct Fred\n" @@ -1272,7 +1272,7 @@ class TestConstructors : public TestFixture { " Fred();\n" "};\n" "Fred::Fred()\n" - "{ s = NULL; }"); + "{ s = NULL; }\n"); ASSERT_EQUALS("", errout_str()); check("struct Fred\n" @@ -1281,7 +1281,7 @@ class TestConstructors : public TestFixture { " Fred();\n" "};\n" "Fred::Fred()\n" - "{ }"); + "{ }\n"); ASSERT_EQUALS("[test.cpp:6:7]: (warning) Member variable 'Fred::s' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -1293,7 +1293,7 @@ class TestConstructors : public TestFixture { "private:\n" " void update() const;\n" " mutable int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1304,7 +1304,7 @@ class TestConstructors : public TestFixture { "public:\n" " Fred() { }\n" " static void *p;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1317,7 +1317,7 @@ class TestConstructors : public TestFixture { "\n" "private:\n" " std::map * values_{};\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1335,7 +1335,7 @@ class TestConstructors : public TestFixture { " {\n" " U.a = 0;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class Fred\n" @@ -1349,7 +1349,7 @@ class TestConstructors : public TestFixture { " Fred()\n" " {\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:9:5]: (warning) Member variable 'Fred::U' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -1360,7 +1360,7 @@ class TestConstructors : public TestFixture { "public:\n" " A(int n) { }\n" " A() : A(42) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:5:5]: (warning) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); @@ -1369,7 +1369,7 @@ class TestConstructors : public TestFixture { "public:\n" " A(int n) { number = n; }\n" " A() : A(42) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class A {\n" @@ -1377,7 +1377,7 @@ class TestConstructors : public TestFixture { "public:\n" " A(int n) : A() { }\n" " A() {}\n" - "};", dinit(CheckOptions, $.inconclusive = true)); + "};\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:5:5]: (warning, inconclusive) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); @@ -1386,7 +1386,7 @@ class TestConstructors : public TestFixture { "public:\n" " A(int n) : A() { }\n" " A() { number = 42; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class A {\n" @@ -1394,7 +1394,7 @@ class TestConstructors : public TestFixture { "public:\n" " A(int n) { }\n" " A() : A{42} {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:5:5]: (warning) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); @@ -1403,7 +1403,7 @@ class TestConstructors : public TestFixture { "public:\n" " A(int n) { number = n; }\n" " A() : A{42} {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class A {\n" @@ -1411,7 +1411,7 @@ class TestConstructors : public TestFixture { "public:\n" " A(int n) : A{} { }\n" " A() {}\n" - "};", dinit(CheckOptions, $.inconclusive = true)); + "};\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:5:5]: (warning, inconclusive) Member variable 'A::number' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); @@ -1420,7 +1420,7 @@ class TestConstructors : public TestFixture { "public:\n" " A(int n) : A{} { }\n" " A() { number = 42; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // Ticket #6675 @@ -1430,7 +1430,7 @@ class TestConstructors : public TestFixture { " int foo_;\n" "};\n" "Foo::Foo() : Foo(0) {}\n" - "Foo::Foo(int foo) : foo_(foo) {}"); + "Foo::Foo(int foo) : foo_(foo) {}\n"); ASSERT_EQUALS("", errout_str()); // Noexcept ctors @@ -1442,7 +1442,7 @@ class TestConstructors : public TestFixture { " A() noexcept;\n" "};\n" "\n" - "A::A() noexcept: A(0) {}"); + "A::A() noexcept: A(0) {}\n"); ASSERT_EQUALS("", errout_str()); // Ticket #8581 @@ -1452,7 +1452,7 @@ class TestConstructors : public TestFixture { "public:\n" " A(int a) : _a(a) {}\n" " A(float a) : A(int(a)) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // Ticket #8258 @@ -1464,7 +1464,7 @@ class TestConstructors : public TestFixture { " int _a;\n" " int _b;\n" " F _f;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1488,7 +1488,7 @@ class TestConstructors : public TestFixture { " : a(true)\n" " , b(0)\n" "{\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1503,7 +1503,7 @@ class TestConstructors : public TestFixture { "public:\n" " Derived() {}\n" " void foo() override;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:9:3]: (warning) Member variable 'Base::x' is not initialized in the constructor. Maybe it should be initialized directly in the class Base? [uninitDerivedMemberVar]\n", errout_str()); check("struct A {\n" // #3462 @@ -1590,7 +1590,7 @@ class TestConstructors : public TestFixture { "class C : public S {\n" "public:\n" " C() { all = 0; tick = 0; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" @@ -1606,7 +1606,7 @@ class TestConstructors : public TestFixture { "class C : public S {\n" "public:\n" " C() { flag1 = flag2 = 0; tick = 0; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" @@ -1622,7 +1622,7 @@ class TestConstructors : public TestFixture { "class C : public S {\n" "public:\n" " C() {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:13:5]: (warning) Member variable 'S::all' is not initialized in the constructor. Maybe it should be initialized directly in the class S? [uninitDerivedMemberVar]\n" "[test.cpp:13:5]: (warning) Member variable 'S::flag1' is not initialized in the constructor. Maybe it should be initialized directly in the class S? [uninitDerivedMemberVar]\n" "[test.cpp:13:5]: (warning) Member variable 'S::flag2' is not initialized in the constructor. Maybe it should be initialized directly in the class S? [uninitDerivedMemberVar]\n", errout_str()); @@ -1638,7 +1638,7 @@ class TestConstructors : public TestFixture { " Fred();\n" "};\n" "Fred::Fred()\n" - "{ }", s); + "{ }\n", s); ASSERT_EQUALS("[test.cpp:7:7]: (warning) Member variable 'Fred::var' is not initialized in the constructor. [uninitMemberVarPrivate]\n", errout_str()); } @@ -1651,7 +1651,7 @@ class TestConstructors : public TestFixture { " Fred();\n" "};\n" "Fred::Fred()\n" - "{ }", s); + "{ }\n", s); ASSERT_EQUALS("", errout_str()); } } @@ -1673,7 +1673,7 @@ class TestConstructors : public TestFixture { "public:\n" " Fred() { };\n" " Fred(const Fred &) { };\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class Fred\n" @@ -1683,7 +1683,7 @@ class TestConstructors : public TestFixture { "public:\n" " Fred() { };\n" " Fred(const Fred &) { };\n" - "};", dinit(CheckOptions, $.inconclusive = true)); + "};\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:7:5]: (warning, inconclusive) Member variable 'Fred::var' is not assigned in the copy constructor. Should it be copied? [missingMemberCopy]\n", errout_str()); check("class Fred\n" @@ -1731,7 +1731,7 @@ class TestConstructors : public TestFixture { "A::A(){}\n" "A::B::B(int x){}\n" "A::B::C::C(int y){}\n" - "A::B::C::D::D(int z){}"); + "A::B::C::D::D(int z){}\n"); // Note that the example code is not compilable. The A constructor must // explicitly initialize A::b. A warning for A::b is not necessary. ASSERT_EQUALS("[test.cpp:20:4]: (warning) Member variable 'A::a' is not initialized in the constructor. [uninitMemberVar]\n" @@ -1761,7 +1761,7 @@ class TestConstructors : public TestFixture { "A::A(){}\n" "A::B::B(int x){}\n" "A::B::C::C(int y){}\n" - "A::B::C::D::D(const A::B::C::D & d){}"); + "A::B::C::D::D(const A::B::C::D & d){}\n"); // Note that the example code is not compilable. The A constructor must // explicitly initialize A::b. A warning for A::b is not necessary. ASSERT_EQUALS("[test.cpp:20:4]: (warning) Member variable 'A::a' is not initialized in the constructor. [uninitMemberVar]\n" @@ -1792,7 +1792,7 @@ class TestConstructors : public TestFixture { "A::A(){}\n" "A::B::B(int x){}\n" "A::B::C::C(int y){}\n" - "A::B::C::D::D(const A::B::C::D::E & e){}"); + "A::B::C::D::D(const A::B::C::D::E & e){}\n"); // Note that the example code is not compilable. The A constructor must // explicitly initialize A::b. A warning for A::b is not necessary. ASSERT_EQUALS("[test.cpp:21:4]: (warning) Member variable 'A::a' is not initialized in the constructor. [uninitMemberVar]\n" @@ -1814,7 +1814,7 @@ class TestConstructors : public TestFixture { " A(const A&){}\n" " A(A &&){}\n" " const A& operator=(const A&){return *this;}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class B\n" @@ -1829,7 +1829,7 @@ class TestConstructors : public TestFixture { " A(const A&){}\n" " A(A &&){}\n" " const A& operator=(const A&){return *this;}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class B\n" @@ -1846,7 +1846,7 @@ class TestConstructors : public TestFixture { " A(const A&){}\n" " A(A &&){}\n" " const A& operator=(const A&){return *this;}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class B\n" @@ -1862,7 +1862,7 @@ class TestConstructors : public TestFixture { " A(const A&){}\n" " A(A &&){}\n" " const A& operator=(const A&){return *this;}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class A : public std::vector\n" @@ -1878,7 +1878,7 @@ class TestConstructors : public TestFixture { " B(const B&){}\n" " B(B &&){}\n" " const B& operator=(const B&){return *this;}\n" - "};", dinit(CheckOptions, $.inconclusive = true)); + "};\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:11:5]: (warning, inconclusive) Member variable 'B::a' is not assigned in the copy constructor. Should it be copied? [missingMemberCopy]\n" "[test.cpp:12:5]: (warning, inconclusive) Member variable 'B::a' is not assigned in the move constructor. Should it be moved? [missingMemberCopy]\n" "[test.cpp:13:14]: (warning, inconclusive) Member variable 'B::a' is not assigned a value in 'B::operator='. [operatorEqVarError]\n", @@ -1898,7 +1898,7 @@ class TestConstructors : public TestFixture { " A(const A&){}\n" " A(A &&){}\n" " const A& operator=(const A&){return *this;}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:13:5]: (warning) Member variable 'A::m_SemVar' is not initialized in the move constructor. [uninitMemberVar]\n", errout_str()); check("class B\n" @@ -1916,7 +1916,7 @@ class TestConstructors : public TestFixture { " A(const A&){}\n" " A(A &&){}\n" " const A& operator=(const A&){return *this;}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class A\n" @@ -1926,7 +1926,7 @@ class TestConstructors : public TestFixture { " A(){}\n" " A(const A&){}\n" " const A& operator=(const A&){return *this;}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1944,7 +1944,7 @@ class TestConstructors : public TestFixture { " A(){}\n" " A(const A&){}\n" " const A& operator=(const A&){return *this;}\n" - "};", dinit(CheckOptions, $.inconclusive = true)); + "};\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("class B\n" @@ -1961,7 +1961,7 @@ class TestConstructors : public TestFixture { " A(){}\n" " A(const A&){}\n" " const A& operator=(const A&){return *this;}\n" - "};", dinit(CheckOptions, $.inconclusive = true)); + "};\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:12:5]: (warning) Member variable 'A::m_SemVar' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:13:5]: (warning) Member variable 'A::m_SemVar' is not initialized in the copy constructor. [uninitMemberVar]\n" "[test.cpp:14:14]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='. [operatorEqVarError]\n", errout_str()); @@ -1972,14 +1972,14 @@ class TestConstructors : public TestFixture { " B b;\n" " A() {}\n" " A(const A& rhs) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" " B b;\n" " A() {}\n" " A(const A& rhs) {}\n" - "};", dinit(CheckOptions, $.inconclusive = true)); + "};\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:4:5]: (warning, inconclusive) Member variable 'A::b' is not assigned in the copy constructor. Should it be copied? [missingMemberCopy]\n", errout_str()); } @@ -1995,7 +1995,7 @@ class TestConstructors : public TestFixture { "}\n" "void S::Set(const T& val) {\n" " t = val;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -2004,7 +2004,7 @@ class TestConstructors : public TestFixture { " Foo(int m) { this->setMember(m); }\n" " void setMember(int m) { member = m; }\n" " int member;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2016,7 +2016,7 @@ class TestConstructors : public TestFixture { "public:\n" " Fred() : var(0) {}\n" " ~Fred() {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2024,7 +2024,7 @@ class TestConstructors : public TestFixture { check("class something {\n" " int * ( something :: * process()) () { return 0; }\n" " something() { process(); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2035,7 +2035,7 @@ class TestConstructors : public TestFixture { " int& pa = a;\n" " pa = 4;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" @@ -2044,7 +2044,7 @@ class TestConstructors : public TestFixture { " int* pa = &a;\n" " *pa = 4;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" @@ -2054,7 +2054,7 @@ class TestConstructors : public TestFixture { " for (int i = 0; i < 2; i++)\n" " *pa++ = i;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" @@ -2063,7 +2063,7 @@ class TestConstructors : public TestFixture { " int* pa = a[1];\n" " *pa = 0;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'S::a' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct S {\n" @@ -2072,7 +2072,7 @@ class TestConstructors : public TestFixture { " int pa = a;\n" " pa = 4;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'S::a' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -2091,7 +2091,7 @@ class TestConstructors : public TestFixture { " A() {\n" " Wrapper::foo(x);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2109,7 +2109,7 @@ class TestConstructors : public TestFixture { " d = rhs.get();\n" " }\n" " double d;\n" - "};", s); + "};\n", s); ASSERT_EQUALS("", errout_str()); check("struct S {\n" // #8485 @@ -2136,7 +2136,7 @@ class TestConstructors : public TestFixture { "{ }\n" "\n" "void Fred::operator=(const Fred &f)\n" - "{ }", dinit(CheckOptions, $.inconclusive = true)); + "{ }\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:13:12]: (warning, inconclusive) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); const Settings s = settingsBuilder().certainty(Certainty::inconclusive).severity(Severity::style).severity(Severity::warning).library("std.cfg").build(); @@ -2161,7 +2161,7 @@ class TestConstructors : public TestFixture { "\n" "private:\n" " ECODES _code;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:10:5]: (warning) Member variable 'Fred::_code' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); @@ -2174,7 +2174,7 @@ class TestConstructors : public TestFixture { " B() {}\n" "private:\n" " float f;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:3]: (warning) Member variable 'B::f' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class C\n" @@ -2187,7 +2187,7 @@ class TestConstructors : public TestFixture { "\n" "C::C(FILE *fp) {\n" " C::fp = fp;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2198,7 +2198,7 @@ class TestConstructors : public TestFixture { " John() { (*this).i = 0; }\n" "private:\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2213,7 +2213,7 @@ class TestConstructors : public TestFixture { " Bar();\n" " };\n" " Bar bars[2];\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // Using struct that doesn't have constructor @@ -2226,7 +2226,7 @@ class TestConstructors : public TestFixture { " int x;\n" " };\n" " Bar bars[2];\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Foo::bars' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -2240,7 +2240,7 @@ class TestConstructors : public TestFixture { " int x;\n" " };\n" " struct Bar bar;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2252,7 +2252,7 @@ class TestConstructors : public TestFixture { " Foo &operator=(const Foo &)\n" " { return *this; }\n" " static int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2263,7 +2263,7 @@ class TestConstructors : public TestFixture { " explicit Foo(int i) : Bar(mi=i) { }\n" "private:\n" " int mi;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class Foo : public Bar\n" @@ -2272,7 +2272,7 @@ class TestConstructors : public TestFixture { " explicit Foo(int i) : Bar{mi=i} { }\n" "private:\n" " int mi;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2293,7 +2293,7 @@ class TestConstructors : public TestFixture { " Foo copy(rhs);\n" " copy.Swap(*this);\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2310,7 +2310,7 @@ class TestConstructors : public TestFixture { " {\n" " }\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:11]: (warning) Member variable 'Foo::a' is not assigned a value in 'Foo::operator='. [operatorEqVarError]\n", errout_str()); } @@ -2324,7 +2324,7 @@ class TestConstructors : public TestFixture { "Prefs::Prefs(wxSize size)\n" "{\n" " SetMinSize( wxSize( 48,48 ) );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:8]: (warning) Member variable 'Prefs::xasd' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -2336,7 +2336,7 @@ class TestConstructors : public TestFixture { " int var1;\n" " int var2;\n" "};\n" - "A::A() : var1(0) { }"); + "A::A() : var1(0) { }\n"); ASSERT_EQUALS("[test.cpp:8:4]: (warning) Member variable 'A::var2' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -2347,7 +2347,7 @@ class TestConstructors : public TestFixture { "private:\n" " int var;\n" "};\n" - "A::A(int a) { }"); + "A::A(int a) { }\n"); ASSERT_EQUALS("[test.cpp:7:4]: (warning) Member variable 'A::var' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -2363,7 +2363,7 @@ class TestConstructors : public TestFixture { " : x(x), y(y)\n" " {}\n" " int x, y;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Point::x' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:4:5]: (warning) Member variable 'Point::y' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -2375,7 +2375,7 @@ class TestConstructors : public TestFixture { "public:\n" " A()\n" " {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:5]: (warning) Member variable 'A::ints' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -2390,7 +2390,7 @@ class TestConstructors : public TestFixture { "};\n" "Foo::Foo()\n" "{\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:6]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // single namespace @@ -2406,7 +2406,7 @@ class TestConstructors : public TestFixture { " Foo::Foo()\n" " {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:10]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // constructor outside namespace @@ -2422,7 +2422,7 @@ class TestConstructors : public TestFixture { "}\n" "Foo::Foo()\n" "{\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // constructor outside namespace @@ -2438,7 +2438,7 @@ class TestConstructors : public TestFixture { "}\n" "Output::Foo::Foo()\n" "{\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:11:14]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // constructor outside namespace with using, #4792 @@ -2455,7 +2455,7 @@ class TestConstructors : public TestFixture { "using namespace Output;" "Foo::Foo()\n" "{\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:11:29]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // constructor in separate namespace @@ -2474,7 +2474,7 @@ class TestConstructors : public TestFixture { " Foo::Foo()\n" " {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:13:10]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // constructor in different separate namespace @@ -2493,7 +2493,7 @@ class TestConstructors : public TestFixture { " Foo::Foo()\n" " {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // constructor in different separate namespace (won't compile) @@ -2512,7 +2512,7 @@ class TestConstructors : public TestFixture { " Output::Foo::Foo()\n" " {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // constructor in nested separate namespace @@ -2534,7 +2534,7 @@ class TestConstructors : public TestFixture { " {\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:15:14]: (warning) Member variable 'Foo::mMember' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // constructor in nested different separate namespace @@ -2556,7 +2556,7 @@ class TestConstructors : public TestFixture { " {\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // constructor in nested different separate namespace @@ -2578,7 +2578,7 @@ class TestConstructors : public TestFixture { " {\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2592,7 +2592,7 @@ class TestConstructors : public TestFixture { "};\n" "Fred::~Fred()\n" "{\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2610,7 +2610,7 @@ class TestConstructors : public TestFixture { " {\n" " foo.set(0);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct Foo\n" @@ -2625,7 +2625,7 @@ class TestConstructors : public TestFixture { " Bar()\n" " {\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:10:5]: (warning) Member variable 'Bar::foo' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -2642,7 +2642,7 @@ class TestConstructors : public TestFixture { " {\n" " foo[0].a = 0;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct Foo\n" @@ -2656,7 +2656,7 @@ class TestConstructors : public TestFixture { " Bar()\n" " {\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:9:5]: (warning) Member variable 'Bar::foo' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -2672,7 +2672,7 @@ class TestConstructors : public TestFixture { " A() { }\n" "private:\n" " Altren value;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2696,7 +2696,7 @@ class TestConstructors : public TestFixture { " {\n" " free(m_str);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2708,7 +2708,7 @@ class TestConstructors : public TestFixture { " std::streamsize dataLength_;\n" " double bitsInData_;\n" " } obj;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:9]: (warning) Member variable 'LocalClass::bitsInData_' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct copy_protected;\n" @@ -2719,7 +2719,7 @@ class TestConstructors : public TestFixture { " std::streamsize dataLength_;\n" " double bitsInData_;\n" " } obj;\n" - "};"); + "};\n"); ASSERT_EQUALS( "[test.cpp:5:9]: (warning) Member variable 'LocalClass::bitsInData_' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); @@ -2732,7 +2732,7 @@ class TestConstructors : public TestFixture { " std::streamsize dataLength_;\n" " double bitsInData_;\n" " } obj;\n" - "};"); + "};\n"); ASSERT_EQUALS( "[test.cpp:5:9]: (warning) Member variable 'LocalClass::bitsInData_' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); @@ -2747,7 +2747,7 @@ class TestConstructors : public TestFixture { "};\n" "Fred::Fred() {\n" " a[x::y] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2764,7 +2764,7 @@ class TestConstructors : public TestFixture { "Fred & Fred::clone(const Fred & other) {\n" " x = 0;\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class Fred {\n" @@ -2778,7 +2778,7 @@ class TestConstructors : public TestFixture { "}\n" "Fred & Fred::clone(const Fred & other) {\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:14]: (warning) Member variable 'Fred::x' is not assigned a value in 'Fred::operator='. [operatorEqVarError]\n", errout_str()); } @@ -2796,7 +2796,7 @@ class TestConstructors : public TestFixture { "Fred::Fred(struct C c, D d) { }\n" "Fred::Fred(E e, struct F f) { }\n" "Fred::Fred(G g, H h) { }\n" - "Fred::Fred(struct I i, struct J j) { }"); + "Fred::Fred(struct I i, struct J j) { }\n"); ASSERT_EQUALS("[test.cpp:10:7]: (warning) Member variable 'Fred::x' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:11:7]: (warning) Member variable 'Fred::x' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:12:7]: (warning) Member variable 'Fred::x' is not initialized in the constructor. [uninitMemberVar]\n" @@ -2905,7 +2905,7 @@ class TestConstructors : public TestFixture { " A(int s) {\n" " v = new int [sz = s];\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2916,7 +2916,7 @@ class TestConstructors : public TestFixture { " A() {\n" " rtl::math::setNan(&d);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class A {\n" " double d;\n" @@ -2924,7 +2924,7 @@ class TestConstructors : public TestFixture { " A() {\n" " ::rtl::math::setNan(&d);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2939,7 +2939,7 @@ class TestConstructors : public TestFixture { " }\n" " void foo(int a) { i = a; }\n" " void foo(float a) { f = a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2971,7 +2971,7 @@ class TestConstructors : public TestFixture { " D() { foo(); }\n" " void foo() { }\n" " void foo() const { i = 0; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:18:5]: (warning) Member variable 'C::i' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:25:5]: (warning) Member variable 'D::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -2988,7 +2988,7 @@ class TestConstructors : public TestFixture { "}\n" "using namespace NS;\n" "MyClass::~MyClass() { }\n" - "MyClass::MyClass() : SomeVar(false) { }"); + "MyClass::MyClass() : SomeVar(false) { }\n"); ASSERT_EQUALS("", errout_str()); } @@ -3006,7 +3006,7 @@ class TestConstructors : public TestFixture { "}\n" "void MyClass::Restart() {\n" " m_retCode = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3019,7 +3019,7 @@ class TestConstructors : public TestFixture { " {\n" " if (1) {}\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:4]: (warning) Member variable 'Foo::member' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class Foo {\n" " friend class Bar;\n" @@ -3029,7 +3029,7 @@ class TestConstructors : public TestFixture { " {\n" " while (1) {}\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:4]: (warning) Member variable 'Foo::member' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class Foo {\n" " friend class Bar;\n" @@ -3039,7 +3039,7 @@ class TestConstructors : public TestFixture { " {\n" " for (;;) {}\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:4]: (warning) Member variable 'Foo::member' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -3051,7 +3051,7 @@ class TestConstructors : public TestFixture { " int x;\n" " };\n" "};\n" - "app::B::B(void){}"); + "app::B::B(void){}\n"); ASSERT_EQUALS("[test.cpp:8:9]: (warning) Member variable 'B::x' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -3103,7 +3103,7 @@ class TestConstructors : public TestFixture { "\n" "private:\n" " char name[255];\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'John::name' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class John\n" @@ -3113,7 +3113,7 @@ class TestConstructors : public TestFixture { "\n" "private:\n" " char name[255];\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class John\n" @@ -3123,7 +3123,7 @@ class TestConstructors : public TestFixture { "\n" "private:\n" " char name[255];\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class John\n" @@ -3132,7 +3132,7 @@ class TestConstructors : public TestFixture { " John() { }\n" "\n" " double operator[](const unsigned long i);\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class A;\n" @@ -3141,7 +3141,7 @@ class TestConstructors : public TestFixture { "public:\n" " John() { }\n" " A a[5];\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class A;\n" @@ -3150,7 +3150,7 @@ class TestConstructors : public TestFixture { "public:\n" " John() { }\n" " A (*a)[5];\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:5]: (warning) Member variable 'John::a' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -3162,7 +3162,7 @@ class TestConstructors : public TestFixture { "\n" "private:\n" " char name[255];\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // #5754 @@ -3173,7 +3173,7 @@ class TestConstructors : public TestFixture { "\n" "private:\n" " char name[255];\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3190,7 +3190,7 @@ class TestConstructors : public TestFixture { " memset(a,0,sizeof(a));\n" " memset(b,0,sizeof(b));\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3207,7 +3207,7 @@ class TestConstructors : public TestFixture { " if (snprintf(a,10,\"a\")) { }\n" " if (snprintf(b,10,\"b\")) { }\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3219,7 +3219,7 @@ class TestConstructors : public TestFixture { "public:\n" " Foo()\n" " { }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3231,7 +3231,7 @@ class TestConstructors : public TestFixture { " static const char STR[];\n" "};\n" "const char Foo::STR[] = \"abc\";\n" - "Foo::Foo() { }"); + "Foo::Foo() { }\n"); ASSERT_EQUALS("", errout_str()); } @@ -3241,7 +3241,7 @@ class TestConstructors : public TestFixture { " int array[10];\n" "public:\n" " Foo() { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:5]: (warning) Member variable 'Foo::array' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class Foo\n" @@ -3249,7 +3249,7 @@ class TestConstructors : public TestFixture { " int array[10];\n" "public:\n" " Foo() { memset(array, 0, sizeof(array)); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class Foo\n" @@ -3257,7 +3257,7 @@ class TestConstructors : public TestFixture { " int array[10];\n" "public:\n" " Foo() { ::memset(array, 0, sizeof(array)); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3266,7 +3266,7 @@ class TestConstructors : public TestFixture { " char a[10];\n" "public:\n" " Foo() { ::ZeroMemory(a); }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3277,7 +3277,7 @@ class TestConstructors : public TestFixture { " BaseGDL* eArr[3];\n" "public:\n" " IxExprListT() {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:5]: (warning) Member variable 'IxExprListT::eArr' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct sRAIUnitDefBL {\n" " sRAIUnitDefBL();\n" @@ -3286,7 +3286,7 @@ class TestConstructors : public TestFixture { "struct sRAIUnitDef {\n" " sRAIUnitDef() {}\n" " sRAIUnitDefBL *List[35];\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:3]: (warning) Member variable 'sRAIUnitDef::List' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -3333,7 +3333,7 @@ class TestConstructors : public TestFixture { "\n" "private:\n" " char a[2][2];\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3344,7 +3344,7 @@ class TestConstructors : public TestFixture { " char a[2][2][2];\n" "public:\n" " John() { a[0][0][0] = 0; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3355,7 +3355,7 @@ class TestConstructors : public TestFixture { " Foo()\n" " : bar({\"a\", \"b\"})\n" " {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3371,7 +3371,7 @@ class TestConstructors : public TestFixture { " Fred() : f{0, true} { }\n" " float get() const;\n" "};\n" - "float Fred::get() const { return g; }"); + "float Fred::get() const { return g; }\n"); ASSERT_EQUALS("[test.cpp:9:5]: (warning) Member variable 'Fred::g' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -3387,7 +3387,7 @@ class TestConstructors : public TestFixture { "public:\n" " A() {\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class A\n" @@ -3401,7 +3401,7 @@ class TestConstructors : public TestFixture { "public:\n" " A() {\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:10:5]: (warning) Member variable 'A::b' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class A\n" @@ -3416,7 +3416,7 @@ class TestConstructors : public TestFixture { "public:\n" " A() {\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3433,7 +3433,7 @@ class TestConstructors : public TestFixture { "public:\n" " Fred()\n" " { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:11:5]: (warning) Member variable 'Fred::p' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct POINT\n" @@ -3449,7 +3449,7 @@ class TestConstructors : public TestFixture { "public:\n" " Fred()\n" " { }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct POINT\n" @@ -3465,7 +3465,7 @@ class TestConstructors : public TestFixture { "public:\n" " Fred()\n" " { }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // non static data-member initialization @@ -3481,7 +3481,7 @@ class TestConstructors : public TestFixture { "public:\n" " Fred()\n" " { }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3493,13 +3493,13 @@ class TestConstructors : public TestFixture { "public:\n" " Fred()\n" " { a = 0; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class Fred {\n" "private:\n" " union { int a{}; int b; };\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3513,7 +3513,7 @@ class TestConstructors : public TestFixture { "public:\n" " Fred() : data_type(0)\n" " { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:8:5]: (warning) Member variable 'Fred::data' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -3526,7 +3526,7 @@ class TestConstructors : public TestFixture { "private:\n" " void Init();" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // Unknown non-member function (friend class) @@ -3537,7 +3537,7 @@ class TestConstructors : public TestFixture { "private:\n" " friend ABC;\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // Unknown non-member function (is Init a virtual function?) @@ -3547,7 +3547,7 @@ class TestConstructors : public TestFixture { " Fred() { Init(); }\n" "private:\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // Unknown non-member function @@ -3557,7 +3557,7 @@ class TestConstructors : public TestFixture { " Fred() { Init(); }\n" "private:\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // Unknown non-member function @@ -3568,7 +3568,7 @@ class TestConstructors : public TestFixture { " Fred() { Init(); }\n" "private:\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // Unknown member functions and unknown static functions @@ -3588,7 +3588,7 @@ class TestConstructors : public TestFixture { " static void static_f();\n" "private:\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:7:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // Unknown overloaded member functions @@ -3601,7 +3601,7 @@ class TestConstructors : public TestFixture { " void func();\n" "private:\n" " int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3613,7 +3613,7 @@ class TestConstructors : public TestFixture { " Fred() {}\n" "private:\n" " unsigned int i;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -3624,7 +3624,7 @@ class TestConstructors : public TestFixture { "struct Y {\n" " Y() {}\n" " X x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3640,7 +3640,7 @@ class TestConstructors : public TestFixture { " if(!(in >> foo))\n" " throw 0;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3652,7 +3652,7 @@ class TestConstructors : public TestFixture { " typedef int * pointer;\n" " Foo() : a(0) {}\n" " pointer a;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3663,7 +3663,7 @@ class TestConstructors : public TestFixture { "public:\n" " int * pointer;\n" " Foo() { memset(this, 0, sizeof(*this)); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -3672,7 +3672,7 @@ class TestConstructors : public TestFixture { "public:\n" " int * pointer;\n" " Foo() { ::memset(this, 0, sizeof(*this)); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -3681,13 +3681,13 @@ class TestConstructors : public TestFixture { " int * p;\n" " char c;\n" " Foo() { memset(p, 0, sizeof(int)); }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Foo::c' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct Foo {\n" " int i;\n" " char c;\n" " Foo() { memset(&i, 0, sizeof(int)); }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Foo::c' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct Foo { int f; };\n" "struct Bar { int b; };\n" @@ -3701,7 +3701,7 @@ class TestConstructors : public TestFixture { "int main() {\n" " FooBar foobar;\n" " return foobar.foo.f + foobar.bar.b;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:3]: (warning) Member variable 'FooBar::bar' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct Foo { int f; };\n" "struct Bar { int b; };\n" @@ -3715,7 +3715,7 @@ class TestConstructors : public TestFixture { "int main() {\n" " FooBar foobar;\n" " return foobar.foo.f + foobar.bar.b;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:3]: (warning) Member variable 'FooBar::bar' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); // #7755 @@ -3724,7 +3724,7 @@ class TestConstructors : public TestFixture { " memset(this->data, 0, 42);\n" " }\n" " char data[42];\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3734,7 +3734,7 @@ class TestConstructors : public TestFixture { check("class Foo {\n" " int foo;\n" " Foo() { }\n" - "};", s); + "};\n", s); ASSERT_EQUALS("", errout_str()); } @@ -3743,7 +3743,7 @@ class TestConstructors : public TestFixture { check("class Foo {\n" " int foo;\n" " Foo() { }\n" - "};", s); + "};\n", s); ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'Foo::foo' is not initialized in the constructor. [uninitMemberVarPrivate]\n", errout_str()); } } @@ -3756,7 +3756,7 @@ class TestConstructors : public TestFixture { " Foo() { }\n" "public:\n" " explicit Foo(int _i) { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:7:14]: (warning) Member variable 'Foo::foo' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -3777,7 +3777,7 @@ class TestConstructors : public TestFixture { "int* A::f(int* p)\n" "{\n" " return p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3791,7 +3791,7 @@ class TestConstructors : public TestFixture { " int *i;\n" "public:\n" " Fred() { }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3805,7 +3805,7 @@ class TestConstructors : public TestFixture { " Fred() { }\n" "private:\n" " int x;\n" - "};", s); + "};\n", s); ASSERT_EQUALS("", errout_str()); } @@ -3815,7 +3815,7 @@ class TestConstructors : public TestFixture { "public:\n" " Fred() { }\n" " int *operator [] (int index) { return 0; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -3829,7 +3829,7 @@ class TestConstructors : public TestFixture { " { f.d = 0; }\n" "\n" " double d;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class Fred\n" @@ -3841,7 +3841,7 @@ class TestConstructors : public TestFixture { " { }\n" "\n" " double d;\n" - "};"); + "};\n"); TODO_ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Fred::d' is not initialized in the constructor. [uninitMemberVar]\n", "", errout_str()); } @@ -3855,7 +3855,7 @@ class TestConstructors : public TestFixture { " { f.d = 0; return true; }\n" "\n" " double d;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class Fred\n" @@ -3867,7 +3867,7 @@ class TestConstructors : public TestFixture { " { return true; }\n" "\n" " double d;\n" - "};"); + "};\n"); TODO_ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Fred::d' is not initialized in the constructor. [uninitMemberVar]\n", "", errout_str()); } @@ -3881,7 +3881,7 @@ class TestConstructors : public TestFixture { " { d = 0; return true; }\n" "\n" " double d;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class Fred\n" @@ -3893,7 +3893,7 @@ class TestConstructors : public TestFixture { " { return true; }\n" "\n" " double d;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Fred::d' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -3907,7 +3907,7 @@ class TestConstructors : public TestFixture { " { f.d = 0; }\n" "\n" " double d;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class Fred\n" @@ -3919,7 +3919,7 @@ class TestConstructors : public TestFixture { " { }\n" "\n" " double d;\n" - "};"); + "};\n"); TODO_ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'Fred::d' is not initialized in the constructor. [uninitMemberVar]\n", "", errout_str()); } @@ -3933,7 +3933,7 @@ class TestConstructors : public TestFixture { "public:\n" " A() { Init( B ); };\n" " void Init( Structure& S ) { S.C = 0; };\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct Structure {\n" @@ -3945,7 +3945,7 @@ class TestConstructors : public TestFixture { "public:\n" " A() { Init( B ); };\n" " void Init(const Structure& S) { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:8:5]: (warning) Member variable 'A::B' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); } @@ -3970,7 +3970,7 @@ class TestConstructors : public TestFixture { "A::B::B()\n" "{\n" " i = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class B\n" @@ -3996,7 +3996,7 @@ class TestConstructors : public TestFixture { "\n" "A::B::B()\n" "{\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:18:4]: (warning) Member variable 'B::j' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:22:7]: (warning) Member variable 'B::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); @@ -4017,7 +4017,7 @@ class TestConstructors : public TestFixture { "public:\n" " Foo() { }\n" "};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("namespace n1\n" @@ -4039,7 +4039,7 @@ class TestConstructors : public TestFixture { "public:\n" " Foo() { }\n" "};\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:11:10]: (warning) Member variable 'Foo::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("namespace n1\n" @@ -4061,7 +4061,7 @@ class TestConstructors : public TestFixture { "public:\n" " Foo() { }\n" "};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -4082,7 +4082,7 @@ class TestConstructors : public TestFixture { "\n" " void init(int value)\n" " { i = value; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class A\n" @@ -4100,7 +4100,7 @@ class TestConstructors : public TestFixture { "\n" " void init(int value)\n" " { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:7:5]: (warning) Member variable 'A::i' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class bar {\n" // #9887 @@ -4121,7 +4121,7 @@ class TestConstructors : public TestFixture { " int a;\n" " A() { a=0; }\n" " A(A const &a) { operator=(a); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" @@ -4132,7 +4132,7 @@ class TestConstructors : public TestFixture { " a = rhs.a;\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" @@ -4142,7 +4142,7 @@ class TestConstructors : public TestFixture { " A & operator = (const A & rhs) {\n" " return *this;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'A::a' is not initialized in the copy constructor. [uninitMemberVar]\n" "[test.cpp:5:9]: (warning) Member variable 'A::a' is not assigned a value in 'A::operator='. [operatorEqVarError]\n", errout_str()); } @@ -4154,28 +4154,28 @@ class TestConstructors : public TestFixture { "struct B {\n" " A* a;\n" " B() { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:5]: (warning) Member variable 'B::a' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct A;\n" "struct B {\n" " A* a;\n" " B() { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'B::a' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct A;\n" "struct B {\n" " const A* a;\n" " B() { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'B::a' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("struct A;\n" "struct B {\n" " A* const a;\n" " B() { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'B::a' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); check("class Test {\n" // #8498 @@ -4226,7 +4226,7 @@ class TestConstructors : public TestFixture { " A* const a;\n" " B() { }\n" " B(B& b) { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Member variable 'B::a' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:5:5]: (warning) Member variable 'B::a' is not initialized in the copy constructor. [uninitMemberVar]\n", errout_str()); @@ -4234,21 +4234,21 @@ class TestConstructors : public TestFixture { "struct B {\n" " A* const a;\n" " B& operator=(const B& r) { }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // #3804 check("struct B {\n" " const int a;\n" " B() { }\n" " B(B& b) { }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning) Member variable 'B::a' is not initialized in the constructor. [uninitMemberVar]\n" "[test.cpp:4:5]: (warning) Member variable 'B::a' is not initialized in the copy constructor. [uninitMemberVar]\n", errout_str()); check("struct B {\n" " const int a;\n" " B& operator=(const B& r) { }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4258,7 +4258,7 @@ class TestConstructors : public TestFixture { "public:\n" " C() _STLP_NOTHROW {}\n" " C(const C&) _STLP_NOTHROW {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4267,7 +4267,7 @@ class TestConstructors : public TestFixture { " int mValue;\n" "public:\n" " operatorX() : mValue(0) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4277,7 +4277,7 @@ class TestConstructors : public TestFixture { " T* mElements;\n" "};\n" "template Container::Container() : mElements(nullptr) {}\n" - "Container intContainer;"); + "Container intContainer;\n"); ASSERT_EQUALS("", errout_str()); } @@ -4287,7 +4287,7 @@ class TestConstructors : public TestFixture { "public:\n" " SelectionPosition() {}\n" " const rvec &x() const;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4302,7 +4302,7 @@ class TestConstructors : public TestFixture { " x = 1;\n" " return true;\n" " }\n" - "};", dinit(CheckOptions, $.inconclusive = true)); + "};\n", dinit(CheckOptions, $.inconclusive = true)); TODO_ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Member variable 'C::x' is not initialized in the constructor.\n", "[test.cpp:3:5]: (warning) Member variable 'C::x' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); @@ -4316,7 +4316,7 @@ class TestConstructors : public TestFixture { " x = 1;\n" " return true;\n" " }\n" - "};", dinit(CheckOptions, $.inconclusive = true)); + "};\n", dinit(CheckOptions, $.inconclusive = true)); TODO_ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Member variable 'C::x' is not initialized in the constructor.\n", "[test.cpp:3:5]: (warning) Member variable 'C::x' is not initialized in the constructor. [uninitMemberVar]\n", errout_str()); @@ -4330,7 +4330,7 @@ class TestConstructors : public TestFixture { " x = 1;\n" " return true;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4343,7 +4343,7 @@ class TestConstructors : public TestFixture { " x = 1;\n" " return true;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4353,7 +4353,7 @@ class TestConstructors : public TestFixture { " i = i * SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4363,7 +4363,7 @@ class TestConstructors : public TestFixture { " i = i / SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4373,7 +4373,7 @@ class TestConstructors : public TestFixture { " i = i % SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4383,7 +4383,7 @@ class TestConstructors : public TestFixture { " i = i + SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4393,7 +4393,7 @@ class TestConstructors : public TestFixture { " i = i - SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4403,7 +4403,7 @@ class TestConstructors : public TestFixture { " i = i << SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4413,7 +4413,7 @@ class TestConstructors : public TestFixture { " i = i >> SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4423,7 +4423,7 @@ class TestConstructors : public TestFixture { " i = i ^ SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4438,7 +4438,7 @@ class TestConstructors : public TestFixture { " x = 1;\n" " return true;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4451,7 +4451,7 @@ class TestConstructors : public TestFixture { " x = 1;\n" " return true;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4461,7 +4461,7 @@ class TestConstructors : public TestFixture { " i *= SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4471,7 +4471,7 @@ class TestConstructors : public TestFixture { " i /= SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4481,7 +4481,7 @@ class TestConstructors : public TestFixture { " i %= SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4491,7 +4491,7 @@ class TestConstructors : public TestFixture { " i += SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4501,7 +4501,7 @@ class TestConstructors : public TestFixture { " i -= SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4511,7 +4511,7 @@ class TestConstructors : public TestFixture { " i <<= SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4521,7 +4521,7 @@ class TestConstructors : public TestFixture { " i >>= SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4531,7 +4531,7 @@ class TestConstructors : public TestFixture { " i ^= SetValue();\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4546,7 +4546,7 @@ class TestConstructors : public TestFixture { " x = 1;\n" " return true;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4559,7 +4559,7 @@ class TestConstructors : public TestFixture { " x = 1;\n" " return true;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4568,7 +4568,7 @@ class TestConstructors : public TestFixture { " bool b = (0 < SetValue());\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4577,7 +4577,7 @@ class TestConstructors : public TestFixture { " bool b = (0 <= SetValue());\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4586,7 +4586,7 @@ class TestConstructors : public TestFixture { " bool b = (0 > SetValue());\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct C {\n" @@ -4595,7 +4595,7 @@ class TestConstructors : public TestFixture { " bool b = (0 >= SetValue());\n" " }\n" " int SetValue() { return x = 1; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -4613,7 +4613,7 @@ class TestConstructors : public TestFixture { "class C {\n" " private:\n" " A* b;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("template class A{};\n" @@ -4625,7 +4625,7 @@ class TestConstructors : public TestFixture { " bool m_value;\n" "};\n" "template\n" - "A>::A() : m_value(false) {}"); + "A>::A() : m_value(false) {}\n"); ASSERT_EQUALS("", errout_str()); check("template struct S;\n" // #11177 @@ -4644,7 +4644,7 @@ class TestConstructors : public TestFixture { "public:\n" " A& operator=() { return *this; }\n" "};\n" - "A a;"); + "A a;\n"); ASSERT_EQUALS("", errout_str()); } diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index 17c5b8eff3c..ffd4d387cfc 100644 --- a/test/testcppcheck.cpp +++ b/test/testcppcheck.cpp @@ -175,7 +175,7 @@ class TestCppcheck : public TestFixture { "void f()\n" "{\n" " (void)(*((int*)0));\n" - "}"); + "}\n"); int called = 0; std::unordered_set addons; @@ -259,7 +259,7 @@ class TestCppcheck : public TestFixture { "void f()\n" "{\n" " (void)(*((int*)0));\n" - "}"); + "}\n"); int called = 0; std::unordered_set addons; @@ -342,7 +342,7 @@ class TestCppcheck : public TestFixture { "void f()\n" "{\n" " (void)(*((int*)0));\n" - "}"); + "}\n"); const char xmldata[] = R"()"; const Settings s = settingsBuilder().libraryxml(xmldata).build(); @@ -364,11 +364,11 @@ class TestCppcheck : public TestFixture { "inline void f()\n" "{\n" " (void)(*((int*)0));\n" - "}"); + "}\n"); ScopedFile test_file_a("a.c", - "#include \"inc.h\""); + "#include \"inc.h\"\n"); ScopedFile test_file_b("b.c", - "#include \"inc.h\""); + "#include \"inc.h\"\n"); // this is the "simple" format const auto s = dinit(Settings, $.templateFormat = templateFormat); // TODO: remove when we only longer rely on toString() in unique message handling @@ -400,7 +400,7 @@ class TestCppcheck : public TestFixture { "long a=m[9], b=m[9];\n" "(void)a;\n" "(void)b;\n" - "}"); + "}\n"); // this is the "simple" format const auto s = dinit(Settings, $.templateFormat = templateFormat); // TODO: remove when we only longer rely on toString() in unique message handling? @@ -490,7 +490,7 @@ class TestCppcheck : public TestFixture { ";\n"; simplecpp::OutputList outputList; - const simplecpp::TokenList tokens2(code, files, "", &outputList); + const simplecpp::TokenList tokens2(code, files, "", {}, &outputList); const std::string expected2 = " \n" " \n" " \n" diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index 014ac3a0a8f..c849d3a0c61 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -140,7 +140,7 @@ class TestErrorLogger : public TestFixture { ASSERT_EQUALS("info", loc.getinfo()); } { - const SimpleTokenList tokenlist("a", "dir/a.cpp"); + const SimpleTokenList tokenlist("a\n", "dir/a.cpp"); { const ErrorMessage::FileLocation loc(tokenlist.front(), &tokenlist.get()); ASSERT_EQUALS("dir/a.cpp", loc.getOrigFile(false)); @@ -173,7 +173,7 @@ class TestErrorLogger : public TestFixture { } } { - const SimpleTokenList tokenlist("a", "dir\\a.cpp"); + const SimpleTokenList tokenlist("a\n", "dir\\a.cpp"); { const ErrorMessage::FileLocation loc(tokenlist.front(), &tokenlist.get()); ASSERT_EQUALS("dir\\a.cpp", loc.getOrigFile(false)); @@ -213,12 +213,12 @@ class TestErrorLogger : public TestFixture { ASSERT_EQUALS("dir/a.cpp", ErrorMessage::FileLocation("dir/a.cpp", "info", 1, 1).getfile(false)); ASSERT_EQUALS("dir/a.cpp", ErrorMessage::FileLocation("dir\\a.cpp", "info", 1, 1).getfile(false)); { - const SimpleTokenList tokenlist("a", "dir/a.cpp"); + const SimpleTokenList tokenlist("a\n", "dir/a.cpp"); ASSERT_EQUALS("dir/a.cpp", ErrorMessage::FileLocation(tokenlist.front(), &tokenlist.get()).getfile(false)); ASSERT_EQUALS("dir/a.cpp", ErrorMessage::FileLocation(tokenlist.front(), "info", &tokenlist.get()).getfile(false)); } { - const SimpleTokenList tokenlist("a", "dir\\a.cpp"); + const SimpleTokenList tokenlist("a\n", "dir\\a.cpp"); ASSERT_EQUALS("dir/a.cpp", ErrorMessage::FileLocation(tokenlist.front(), &tokenlist.get()).getfile(false)); ASSERT_EQUALS("dir/a.cpp", ErrorMessage::FileLocation(tokenlist.front(), "info", &tokenlist.get()).getfile(false)); } diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index 1be46fbf282..7e3de4405b0 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -84,7 +84,7 @@ class TestExceptionSafety : public TestFixture { " ~x() {\n" " throw e;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:9]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\n" "[test.cpp:3:9]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str()); @@ -93,7 +93,7 @@ class TestExceptionSafety : public TestFixture { "};\n" "x::~x() {\n" " throw e;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\n" "[test.cpp:5:5]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str()); @@ -105,7 +105,7 @@ class TestExceptionSafety : public TestFixture { " } catch (...) {\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class x {\n" @@ -114,7 +114,7 @@ class TestExceptionSafety : public TestFixture { " throw e;\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:13]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str()); // #11031 should not warn when noexcept false @@ -123,7 +123,7 @@ class TestExceptionSafety : public TestFixture { " ~A() noexcept(false) {\n" " throw 30;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -134,7 +134,7 @@ class TestExceptionSafety : public TestFixture { " if (x)\n" " throw 123;\n" " p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\n", errout_str()); check("void f() {\n" @@ -143,7 +143,7 @@ class TestExceptionSafety : public TestFixture { " if (foo)\n" " throw 1;\n" " p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\n", errout_str()); } @@ -154,7 +154,7 @@ class TestExceptionSafety : public TestFixture { " if (foo)\n" " throw 1;\n" " p = new int;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -162,7 +162,7 @@ class TestExceptionSafety : public TestFixture { " delete p;\n" " reset(p);\n" " throw 1;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -171,14 +171,14 @@ class TestExceptionSafety : public TestFixture { " static int* p = 0;\n" " delete p;\n" " throw 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " static int* p = 0;\n" " delete p;\n" " throw 1;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory. [exceptDeallocThrow]\n", errout_str()); } @@ -192,7 +192,7 @@ class TestExceptionSafety : public TestFixture { " {\n" " throw err;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\n", errout_str()); } @@ -206,7 +206,7 @@ class TestExceptionSafety : public TestFixture { " {\n" " throw err;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\n", errout_str()); } @@ -218,7 +218,7 @@ class TestExceptionSafety : public TestFixture { " catch(std::runtime_error& err) {\n" " throw err;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:9]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\n", errout_str()); } @@ -233,7 +233,7 @@ class TestExceptionSafety : public TestFixture { " exception err2;\n" " throw err2;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -250,7 +250,7 @@ class TestExceptionSafety : public TestFixture { " throw inner;\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:13]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception. [exceptRethrowCopy]\n", errout_str()); check("void f() {\n" @@ -265,7 +265,7 @@ class TestExceptionSafety : public TestFixture { " throw outer;\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -277,7 +277,7 @@ class TestExceptionSafety : public TestFixture { " catch( ::std::exception err) {\n" " foo(err);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5]: (style) Exception should be caught by reference. [catchExceptionByValue]\n", errout_str()); check("void f() {\n" @@ -287,7 +287,7 @@ class TestExceptionSafety : public TestFixture { " catch(const exception err) {\n" " foo(err);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5]: (style) Exception should be caught by reference. [catchExceptionByValue]\n", errout_str()); check("void f() {\n" @@ -297,7 +297,7 @@ class TestExceptionSafety : public TestFixture { " catch( ::std::exception& err) {\n" " foo(err);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -307,7 +307,7 @@ class TestExceptionSafety : public TestFixture { " catch(exception* err) {\n" " foo(err);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -317,7 +317,7 @@ class TestExceptionSafety : public TestFixture { " catch(const exception& err) {\n" " foo(err);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -327,7 +327,7 @@ class TestExceptionSafety : public TestFixture { " catch(int err) {\n" " foo(err);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -337,7 +337,7 @@ class TestExceptionSafety : public TestFixture { " catch(exception* const err) {\n" " foo(err);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -347,14 +347,14 @@ class TestExceptionSafety : public TestFixture { "void func3() noexcept(true) { throw 1; }\n" "void func4() noexcept(false) { throw 1; }\n" "void func5() noexcept(true) { func1(); }\n" - "void func6() noexcept(false) { func1(); }"); + "void func6() noexcept(false) { func1(); }\n"); ASSERT_EQUALS("[test.cpp:2:25]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n" "[test.cpp:3:31]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n" "[test.cpp:5:31]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str()); // avoid false positives check("const char *func() noexcept { return 0; }\n" - "const char *func1() noexcept { try { throw 1; } catch(...) {} return 0; }"); + "const char *func1() noexcept { try { throw 1; } catch(...) {} return 0; }\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" // #14526 @@ -378,12 +378,12 @@ class TestExceptionSafety : public TestFixture { "void func2() throw() { throw 1; }\n" "void func3() throw(int) { throw 1; }\n" "void func4() throw() { func1(); }\n" - "void func5() throw(int) { func1(); }"); + "void func5() throw(int) { func1(); }\n"); ASSERT_EQUALS("[test.cpp:2:24]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n" "[test.cpp:4:24]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str()); // avoid false positives - check("const char *func() throw() { return 0; }"); + check("const char *func() throw() { return 0; }\n"); ASSERT_EQUALS("", errout_str()); @@ -451,12 +451,12 @@ class TestExceptionSafety : public TestFixture { void nothrowAttributeThrow() { check("void func1() throw(int) { throw 1; }\n" "void func2() __attribute((nothrow)); void func2() { throw 1; }\n" - "void func3() __attribute((nothrow)); void func3() { func1(); }"); + "void func3() __attribute((nothrow)); void func3() { func1(); }\n"); ASSERT_EQUALS("[test.cpp:2:53]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n" "[test.cpp:3:53]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str()); // avoid false positives - check("const char *func() __attribute((nothrow)); void func1() { return 0; }"); + check("const char *func() __attribute((nothrow)); void func1() { return 0; }\n"); ASSERT_EQUALS("", errout_str()); } @@ -465,30 +465,30 @@ class TestExceptionSafety : public TestFixture { " void copyMemberValues() throw () {\n" " copyMemberValues();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } void nothrowDeclspecThrow() { check("void func1() throw(int) { throw 1; }\n" "void __declspec(nothrow) func2() { throw 1; }\n" - "void __declspec(nothrow) func3() { func1(); }"); + "void __declspec(nothrow) func3() { func1(); }\n"); ASSERT_EQUALS("[test.cpp:2:36]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n" "[test.cpp:3:36]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str()); // avoid false positives - check("const char *func() __attribute((nothrow)); void func1() { return 0; }"); + check("const char *func() __attribute((nothrow)); void func1() { return 0; }\n"); ASSERT_EQUALS("", errout_str()); } void rethrowNoCurrentException1() { - check("void func1(const bool flag) { try{ if(!flag) throw; } catch (int&) { ; } }"); + check("void func1(const bool flag) { try{ if(!flag) throw; } catch (int&) { ; } }\n"); ASSERT_EQUALS("[test.cpp:1:46]: (error) Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow." " If there is no current exception this calls std::terminate(). More: https://isocpp.org/wiki/faq/exceptions#throw-without-an-object [rethrowNoCurrentException]\n", errout_str()); } void rethrowNoCurrentException2() { - check("void func1() { try{ ; } catch (...) { ; } throw; }"); + check("void func1() { try{ ; } catch (...) { ; } throw; }\n"); ASSERT_EQUALS("[test.cpp:1:43]: (error) Rethrowing current exception with 'throw;', it seems there is no current exception to rethrow." " If there is no current exception this calls std::terminate(). More: https://isocpp.org/wiki/faq/exceptions#throw-without-an-object [rethrowNoCurrentException]\n", errout_str()); } @@ -496,7 +496,7 @@ class TestExceptionSafety : public TestFixture { void rethrowNoCurrentException3() { check("void on_error() { try { throw; } catch (const int &) { ; } catch (...) { ; } }\n" // exception dispatcher idiom "void func2() { try{ ; } catch (const int&) { throw; } ; }\n" - "void func3() { throw 0; }"); + "void func3() { throw 0; }\n"); ASSERT_EQUALS("", errout_str()); } diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index f5067bc31dc..e1d421f6dbd 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -141,14 +141,14 @@ class TestFunctions : public TestFixture { check("void f()\n" "{\n" " bsd_signal(SIGABRT, SIG_IGN);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (style) Obsolescent function 'bsd_signal' called. It is recommended to use 'sigaction' instead. [bsd_signalCalled]\n", errout_str()); check("int f()\n" "{\n" " int bsd_signal(0);\n" " return bsd_signal;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" @@ -157,7 +157,7 @@ class TestFunctions : public TestFixture { " if(!hp = gethostbyname(\"127.0.0.1\")) {\n" " exit(1);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:14]: (style) Obsolescent function 'gethostbyname' called. It is recommended to use 'getaddrinfo' instead. [gethostbynameCalled]\n", errout_str()); check("void f()\n" @@ -167,13 +167,13 @@ class TestFunctions : public TestFixture { " if(!hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) {\n" " exit(1);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:14]: (style) Obsolescent function 'gethostbyaddr' called. It is recommended to use 'getnameinfo' instead. [gethostbyaddrCalled]\n", errout_str()); check("void f()\n" "{\n" " usleep( 1000 );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\n", errout_str()); } @@ -185,7 +185,7 @@ class TestFunctions : public TestFixture { "{\n" " n1::index();\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::size_t f()\n" @@ -193,19 +193,19 @@ class TestFunctions : public TestFixture { " std::size_t index(0);\n" " index++;\n" " return index;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f()\n" "{\n" " return this->index();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" "{\n" " int index( 0 );\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("const char f()\n" @@ -213,7 +213,7 @@ class TestFunctions : public TestFixture { " const char var[6] = \"index\";\n" " const char i = index(var, 0);\n" " return i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:20]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\n", errout_str()); } @@ -221,7 +221,7 @@ class TestFunctions : public TestFixture { void prohibitedFunctions_qt_index() { check("void TDataModel::forceRowRefresh(int row) {\n" " emit dataChanged(index(row, 0), index(row, columnCount() - 1));\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:22]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\n" "[test.cpp:2:37]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead. [indexCalled]\n", @@ -232,14 +232,14 @@ class TestFunctions : public TestFixture { check("void f()\n" "{\n" " int rindex( 0 );\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" "{\n" " const char var[7] = \"rindex\";\n" " print(rindex(var, 0));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:11]: (style) Obsolescent function 'rindex' called. It is recommended to use 'strrchr' instead. [rindexCalled]\n", errout_str()); } @@ -249,7 +249,7 @@ class TestFunctions : public TestFixture { "public:\n" " Fred() : index(0) { }\n" " int index;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -257,13 +257,13 @@ class TestFunctions : public TestFixture { check("void f()\n" "{\n" " char *x = gets(a);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\n", errout_str()); check("void f()\n" "{\n" " foo(x, gets(a));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:12]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\n", errout_str()); } @@ -271,32 +271,32 @@ class TestFunctions : public TestFixture { check("void f()\n" "{\n" " char *x = alloca(10);\n" - "}"); // #4382 - there are no VLAs in C++ + "}\n"); // #4382 - there are no VLAs in C++ ASSERT_EQUALS("[test.cpp:3:15]: (warning) Obsolete function 'alloca' called. [allocaCalled]\n", errout_str()); check("void f()\n" "{\n" " char *x = alloca(10);\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:3:15]: (warning) Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead. [allocaCalled]\n", errout_str()); const Settings s = settingsBuilder(settings).c(Standards::C89).cpp(Standards::CPP03).build(); check("void f()\n" "{\n" " char *x = alloca(10);\n" - "}", s); // #4382 - there are no VLAs in C++ + "}\n", s); // #4382 - there are no VLAs in C++ ASSERT_EQUALS("", errout_str()); check("void f()\n" "{\n" " char *x = alloca(10);\n" - "}", s, false); // #7558 - no alternative to alloca in C89 + "}\n", s, false); // #7558 - no alternative to alloca in C89 ASSERT_EQUALS("", errout_str()); check("void f()\n" "{\n" " char *x = alloca(10);\n" - "}", s, false); + "}\n", s, false); ASSERT_EQUALS("", errout_str()); } @@ -310,7 +310,7 @@ class TestFunctions : public TestFixture { "{\n" " int b ; b = ftime ( 1 ) ;\n" " return 0 ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -320,7 +320,7 @@ class TestFunctions : public TestFixture { "{\n" " char *x = std::gets(str);\n" " char *y = gets(str);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\n" "[test.cpp:4:15]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\n", errout_str()); } @@ -331,7 +331,7 @@ class TestFunctions : public TestFixture { "{\n" " char *x = std::gets(str);\n" " usleep( 1000 );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:20]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\n" "[test.cpp:4:5]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead. [usleepCalled]\n", errout_str()); } @@ -343,14 +343,14 @@ class TestFunctions : public TestFixture { " char s [ 10 ] ;\n" " gets ( s ) ;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead. [getsCalled]\n", errout_str()); check("int getcontext(ucontext_t *ucp);\n" "void f (ucontext_t *ucp)\n" "{\n" " getcontext ( ucp ) ;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (portability) Obsolescent function 'getcontext' called. Applications are recommended to be rewritten to use POSIX threads. [getcontextCalled]\n", errout_str()); } @@ -361,7 +361,7 @@ class TestFunctions : public TestFixture { " char s [ 10 ] ;\n" " gets ( s ) ;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -370,7 +370,7 @@ class TestFunctions : public TestFixture { "{\n" " char *cpwd;" " crypt(pwd, cpwd);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:20]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\n" "[test.cpp:3:20]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\n", errout_str()); @@ -379,7 +379,7 @@ class TestFunctions : public TestFixture { " char *pwd = getpass(\"Password:\");" " char *cpwd;" " crypt(pwd, cpwd);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:57]: (warning) Return value of function crypt() is not used. [ignoredReturnValue]\n" "[test.cpp:3:57]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'. [cryptCalled]\n", errout_str()); @@ -387,7 +387,7 @@ class TestFunctions : public TestFixture { "{\n" " int crypt = 0;" " return crypt;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -396,14 +396,14 @@ class TestFunctions : public TestFixture { "{\n" " time_t t = 0;" " auto lt = std::localtime(&t);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:37]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\n", errout_str()); // Passed as function argument check("void f()\n" "{\n" " printf(\"Magic guess: %d\", getpwent());\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:31]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\n", errout_str()); // Pass return value @@ -411,14 +411,14 @@ class TestFunctions : public TestFixture { "{\n" " time_t t = 0;" " struct tm *foo = localtime(&t);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:39]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'. [localtimeCalled]\n", errout_str()); // Access via global namespace check("void f()\n" "{\n" " ::getpwent();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:7]: (warning) Return value of function ::getpwent() is not used. [ignoredReturnValue]\n" "[test.cpp:3:7]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'. [getpwentCalled]\n", errout_str()); @@ -426,68 +426,68 @@ class TestFunctions : public TestFixture { check("int getpwent()\n" "{\n" " return 123;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Be quiet on other namespaces check("void f()\n" "{\n" " foobar::getpwent();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Be quiet on class member functions check("void f()\n" "{\n" " foobar.getpwent();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void invalidFunctionUsage1() { - check("void f() { memset(a,b,sizeof(a)!=12); }"); + check("void f() { memset(a,b,sizeof(a)!=12); }\n"); ASSERT_EQUALS("[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\n", errout_str()); - check("void f() { memset(a,b,sizeof(a)!=0); }"); + check("void f() { memset(a,b,sizeof(a)!=0); }\n"); ASSERT_EQUALS("[test.cpp:1:32]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\n", errout_str()); - check("void f() { memset(a,b,!c); }"); + check("void f() { memset(a,b,!c); }\n"); ASSERT_EQUALS("[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\n", errout_str()); // Ticket #6990 - check("void f(bool c) { memset(a,b,c); }"); + check("void f(bool c) { memset(a,b,c); }\n"); ASSERT_EQUALS("[test.cpp:1:29]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\n", errout_str()); - check("void f() { memset(a,b,true); }"); + check("void f() { memset(a,b,true); }\n"); ASSERT_EQUALS("[test.cpp:1:23]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\n", errout_str()); // Ticket #6588 (c mode) check("void record(char* buf, int n) {\n" " memset(buf, 0, n < 255);\n" /* KO */ " memset(buf, 0, n < 255 ? n : 255);\n" /* OK */ - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\n", errout_str()); // Ticket #6588 (c++ mode) check("void record(char* buf, int n) {\n" " memset(buf, 0, n < 255);\n" /* KO */ " memset(buf, 0, n < 255 ? n : 255);\n" /* OK */ - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20]: (error) Invalid memset() argument nr 3. A non-boolean value is required. [invalidFunctionArgBool]\n", errout_str()); check("int boolArgZeroIsInvalidButOneIsValid(int a, int param) {\n" " return div(a, param > 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:23]: (error) Invalid div() argument nr 2. The value is 0 or 1 (boolean) but the valid values are ':-1,1:'. [invalidFunctionArg]\n", errout_str()); check("void boolArgZeroIsValidButOneIsInvalid(int param) {\n" " strtol(a, b, param > 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:22]: (error) Invalid strtol() argument nr 3. The value is 0 or 1 (boolean) but the valid values are '0,2:36'. [invalidFunctionArg]\n", errout_str()); - check("void f() { strtol(a,b,1); }"); + check("void f() { strtol(a,b,1); }\n"); ASSERT_EQUALS("[test.cpp:1:23]: (error) Invalid strtol() argument nr 3. The value is 1 but the valid values are '0,2:36'. [invalidFunctionArg]\n", errout_str()); - check("void f() { strtol(a,b,10); }"); + check("void f() { strtol(a,b,10); }\n"); ASSERT_EQUALS("", errout_str()); check("void f(std::vector& v) {\n" // #10754 @@ -530,16 +530,16 @@ class TestFunctions : public TestFixture { } void invalidFunctionUsageStrings() { - check("size_t f() { char x = 'x'; return strlen(&x); }"); + check("size_t f() { char x = 'x'; return strlen(&x); }\n"); ASSERT_EQUALS("[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); - check("size_t f() { return strlen(&x); }"); + check("size_t f() { return strlen(&x); }\n"); ASSERT_EQUALS("", errout_str()); - check("size_t f(char x) { return strlen(&x); }"); + check("size_t f(char x) { return strlen(&x); }\n"); ASSERT_EQUALS("[test.cpp:1:34]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); - check("size_t f() { char x = '\\0'; return strlen(&x); }"); + check("size_t f() { char x = '\\0'; return strlen(&x); }\n"); ASSERT_EQUALS("", errout_str()); check("size_t f() {\n" @@ -549,41 +549,41 @@ class TestFunctions : public TestFixture { " else\n" " x = 'a';\n" " return strlen(&x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:17]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); - check("int f() { char x = '\\0'; return strcmp(\"Hello world\", &x); }"); + check("int f() { char x = '\\0'; return strcmp(\"Hello world\", &x); }\n"); ASSERT_EQUALS("", errout_str()); - check("int f() { char x = 'x'; return strcmp(\"Hello world\", &x); }"); + check("int f() { char x = 'x'; return strcmp(\"Hello world\", &x); }\n"); ASSERT_EQUALS("[test.cpp:1:54]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); - check("size_t f(char x) { char * y = &x; return strlen(y); }"); + check("size_t f(char x) { char * y = &x; return strlen(y); }\n"); TODO_ASSERT_EQUALS("[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", "", errout_str()); - check("size_t f(char x) { char * y = &x; char *z = y; return strlen(z); }"); + check("size_t f(char x) { char * y = &x; char *z = y; return strlen(z); }\n"); TODO_ASSERT_EQUALS("[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", "", errout_str()); - check("size_t f() { char x = 'x'; char * y = &x; char *z = y; return strlen(z); }"); + check("size_t f() { char x = 'x'; char * y = &x; char *z = y; return strlen(z); }\n"); TODO_ASSERT_EQUALS("[test.cpp:1:42]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", "", errout_str()); - check("size_t f() { char x = '\\0'; char * y = &x; char *z = y; return strlen(z); }"); + check("size_t f() { char x = '\\0'; char * y = &x; char *z = y; return strlen(z); }\n"); ASSERT_EQUALS("", errout_str()); - check("size_t f() { char x[] = \"Hello world\"; return strlen(x); }"); + check("size_t f() { char x[] = \"Hello world\"; return strlen(x); }\n"); ASSERT_EQUALS("", errout_str()); - check("size_t f(char x[]) { return strlen(x); }"); + check("size_t f(char x[]) { return strlen(x); }\n"); ASSERT_EQUALS("", errout_str()); - check("int f(char x, char y) { return strcmp(&x, &y); }"); + check("int f(char x, char y) { return strcmp(&x, &y); }\n"); ASSERT_EQUALS("[test.cpp:1:39]: (error) Invalid strcmp() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n" "[test.cpp:1:43]: (error) Invalid strcmp() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); - check("size_t f() { char x[] = \"Hello world\"; return strlen(&x[0]); }"); + check("size_t f() { char x[] = \"Hello world\"; return strlen(&x[0]); }\n"); ASSERT_EQUALS("", errout_str()); - check("size_t f() { char* x = \"Hello world\"; return strlen(&x[0]); }"); + check("size_t f() { char* x = \"Hello world\"; return strlen(&x[0]); }\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" @@ -596,11 +596,11 @@ class TestFunctions : public TestFixture { " size_t l1 = strlen(&s1.x);\n" " size_t l2 = strlen(&s2.x);\n" " return l1 + l2;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n" "[test.cpp:9:22]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); - check("const char x = 'x'; size_t f() { return strlen(&x); }"); + check("const char x = 'x'; size_t f() { return strlen(&x); }\n"); ASSERT_EQUALS("[test.cpp:1:48]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("struct someStruct {\n" @@ -615,7 +615,7 @@ class TestFunctions : public TestFixture { "int f(struct someStruct * const tp, const int k)\n" "{\n" " return strcmp(&tp->x.buf[k], \"needle\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct someStruct {\n" @@ -624,29 +624,29 @@ class TestFunctions : public TestFixture { "int f(struct someStruct * const tp, const int k)\n" "{\n" " return strcmp(&tp->buf[k], \"needle\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); - check("const char x = 'x'; size_t f() { char y = x; return strlen(&y); }"); + check("const char x = 'x'; size_t f() { char y = x; return strlen(&y); }\n"); ASSERT_EQUALS("[test.cpp:1:60]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); - check("const char x = '\\0'; size_t f() { return strlen(&x); }"); + check("const char x = '\\0'; size_t f() { return strlen(&x); }\n"); ASSERT_EQUALS("", errout_str()); - check("const char x = '\\0'; size_t f() { char y = x; return strlen(&y); }"); + check("const char x = '\\0'; size_t f() { char y = x; return strlen(&y); }\n"); ASSERT_EQUALS("", errout_str()); check("size_t f() {\n" " char * a = \"Hello world\";\n" " char ** b = &a;\n" " return strlen(&b[0][0]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("size_t f() {\n" " char ca[] = \"asdf\";\n" " return strlen((char*) &ca);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #5225 @@ -657,67 +657,67 @@ class TestFunctions : public TestFixture { " strcat(str, &d);\n" " puts(str);\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:15]: (error) Invalid strcat() argument nr 2. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("FILE* f(void) {\n" " const char fileName[1] = { \'x\' };\n" " return fopen(fileName, \"r\"); \n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("FILE* f(void) {\n" " const char fileName[2] = { \'x\', \'y\' };\n" " return fopen(fileName, \"r\"); \n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("FILE* f(void) {\n" " const char fileName[3] = { \'x\', \'y\' ,\'\\0\' };\n" " return fopen(fileName, \"r\"); \n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("FILE* f(void) {\n" " const char fileName[3] = { \'x\', \'\\0\' ,\'y\' };\n" " return fopen(fileName, \"r\"); \n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("FILE* f(void) {\n" " const char fileName[3] = { \'x\', \'y\' };\n" // implicit '\0' added at the end " return fopen(fileName, \"r\"); \n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("FILE* f(void) {\n" " const char fileName[] = { \'\\0\' };\n" " return fopen(fileName, \"r\"); \n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("FILE* f(void) {\n" " const char fileName[] = { \'0\' + 42 };\n" // no size is explicitly defined, no implicit '\0' is added " return fopen(fileName, \"r\"); \n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("FILE* f(void) {\n" " const char fileName[] = { \'0\' + 42, \'x\' };\n" // no size is explicitly defined, no implicit '\0' is added " return fopen(fileName, \"r\"); \n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:16]: (error) Invalid fopen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); check("FILE* f(void) {\n" " const char fileName[2] = { \'0\' + 42 };\n" // implicitly '\0' added at the end because size is set to 2 " return fopen(fileName, \"r\"); \n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("FILE* f(void) {\n" " const char fileName[] = { };\n" " return fopen(fileName, \"r\"); \n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void scanMetaTypes()\n" // don't crash @@ -728,7 +728,7 @@ class TestFunctions : public TestFixture { " if (strstr(name, \"GammaRay::\") != name)\n" " metaTypes.push_back(mtId);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f() {\n" @@ -770,10 +770,10 @@ class TestFunctions : public TestFixture { "}\n"); ASSERT_EQUALS("", errout_str()); - check("size_t f() { wchar_t x = L'x'; return wcslen(&x); }"); + check("size_t f() { wchar_t x = L'x'; return wcslen(&x); }\n"); ASSERT_EQUALS("[test.cpp:1:46]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); - check("void f() { char a[10] = \"1234567890\"; puts(a); }", dinit(CheckOptions, $.cpp = false)); // #1770 + check("void f() { char a[10] = \"1234567890\"; puts(a); }\n", dinit(CheckOptions, $.cpp = false)); // #1770 ASSERT_EQUALS("[test.c:1:44]: (error) Invalid puts() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]\n", errout_str()); } @@ -799,7 +799,7 @@ class TestFunctions : public TestFixture { " std::cout << sqrt(-1) << std::endl;\n" " std::cout << sqrtf(-1) << std::endl;\n" " std::cout << sqrtl(-1) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:25]: (error) Invalid sqrt() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\n" "[test.cpp:4:26]: (error) Invalid sqrtf() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\n" "[test.cpp:5:26]: (error) Invalid sqrtl() argument nr 1. The value is -1 but the valid values are '0.0:'. [invalidFunctionArg]\n", errout_str()); @@ -810,7 +810,7 @@ class TestFunctions : public TestFixture { " std::cout << sqrt(-0.) << std::endl;\n" " std::cout << sqrtf(-0.) << std::endl;\n" " std::cout << sqrtl(-0.) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" @@ -818,7 +818,7 @@ class TestFunctions : public TestFixture { " std::cout << sqrt(1) << std::endl;\n" " std::cout << sqrtf(1) << std::endl;\n" " std::cout << sqrtl(1) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -838,7 +838,7 @@ class TestFunctions : public TestFixture { " std::cout << log1p(-3) << std::endl;\n" " std::cout << log1pf(-3) << std::endl;\n" " std::cout << log1pl(-3) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" "[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -2 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" "[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -2 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" @@ -875,7 +875,7 @@ class TestFunctions : public TestFixture { " std::cout << log1p(-2) << std::endl;\n" " std::cout << log1pf(-2) << std::endl;\n" " std::cout << log1pl(-2) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:24]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" "[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" "[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" @@ -912,7 +912,7 @@ class TestFunctions : public TestFixture { " std::cout << log1p(-2.0) << std::endl;\n" " std::cout << log1pf(-2.0) << std::endl;\n" " std::cout << log1pl(-2.0) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" "[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" "[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" @@ -949,7 +949,7 @@ class TestFunctions : public TestFixture { " std::cout << log1p(-1.1) << std::endl;\n" " std::cout << log1pf(-1.1) << std::endl;\n" " std::cout << log1pl(-1.1) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:25]: (error) Invalid log() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" "[test.cpp:4:26]: (error) Invalid logf() argument nr 1. The value is -0.1 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" "[test.cpp:5:26]: (error) Invalid logl() argument nr 1. The value is -0.1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" @@ -986,7 +986,7 @@ class TestFunctions : public TestFixture { " std::cout << log1p(-1.) << std::endl;\n" " std::cout << log1pf(-1.0) << std::endl;\n" " std::cout << log1pl(-1) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:23]: (error) Invalid log() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" "[test.cpp:4:25]: (error) Invalid logf() argument nr 1. The value is 0 but the valid values are '1.4013e-45:'. [invalidFunctionArg]\n" "[test.cpp:5:25]: (error) Invalid logl() argument nr 1. The value is 0 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n" @@ -1059,21 +1059,21 @@ class TestFunctions : public TestFixture { " std::cout << log1p(2.0) << std::endl;\n" " std::cout << log1pf(2.0) << std::endl;\n" " std::cout << log1pf(2.0f) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" " std::string *log(0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #3473 - no warning if "log" is a variable - check("Fred::Fred() : log(0) { }"); + check("Fred::Fred() : log(0) { }\n"); ASSERT_EQUALS("", errout_str()); // #5748 - check("void f() { foo.log(0); }"); + check("void f() { foo.log(0); }\n"); ASSERT_EQUALS("", errout_str()); } @@ -1111,7 +1111,7 @@ class TestFunctions : public TestFixture { " + acosl(0.1E-1) \n" " + acosl(+0.1E-1) \n" " + acosl(-0.1E-1);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" @@ -1119,7 +1119,7 @@ class TestFunctions : public TestFixture { " std::cout << acos(1.1) << std::endl;\n" " std::cout << acosf(1.1) << std::endl;\n" " std::cout << acosl(1.1) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:25]: (error) Invalid acos() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" "[test.cpp:4:26]: (error) Invalid acosf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" "[test.cpp:5:26]: (error) Invalid acosl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n", errout_str()); @@ -1129,7 +1129,7 @@ class TestFunctions : public TestFixture { " std::cout << acos(-1.1) << std::endl;\n" " std::cout << acosf(-1.1) << std::endl;\n" " std::cout << acosl(-1.1) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:26]: (error) Invalid acos() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" "[test.cpp:4:27]: (error) Invalid acosf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" "[test.cpp:5:27]: (error) Invalid acosl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n", errout_str()); @@ -1172,7 +1172,7 @@ class TestFunctions : public TestFixture { " + asinl(0.1E-1) \n" " + asinl(+0.1E-1) \n" " + asinl(-0.1E-1);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" @@ -1180,7 +1180,7 @@ class TestFunctions : public TestFixture { " std::cout << asin(1.1) << std::endl;\n" " std::cout << asinf(1.1) << std::endl;\n" " std::cout << asinl(1.1) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:25]: (error) Invalid asin() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" "[test.cpp:4:26]: (error) Invalid asinf() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" "[test.cpp:5:26]: (error) Invalid asinl() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n", errout_str()); @@ -1190,7 +1190,7 @@ class TestFunctions : public TestFixture { " std::cout << asin(-1.1) << std::endl;\n" " std::cout << asinf(-1.1) << std::endl;\n" " std::cout << asinl(-1.1) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:26]: (error) Invalid asin() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" "[test.cpp:4:27]: (error) Invalid asinf() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" "[test.cpp:5:27]: (error) Invalid asinl() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n", errout_str()); @@ -1203,7 +1203,7 @@ class TestFunctions : public TestFixture { " std::cout << pow(0,-10) << std::endl;\n" " std::cout << powf(0,-10) << std::endl;\n" " std::cout << powl(0,-10) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:19]: (warning) Passing values 0 and -10 to pow() leads to implementation-defined result. [wrongmathcall]\n" "[test.cpp:4:19]: (warning) Passing values 0 and -10 to powf() leads to implementation-defined result. [wrongmathcall]\n" "[test.cpp:5:19]: (warning) Passing values 0 and -10 to powl() leads to implementation-defined result. [wrongmathcall]\n", errout_str()); @@ -1213,7 +1213,7 @@ class TestFunctions : public TestFixture { " std::cout << pow(0,10) << std::endl;\n" " std::cout << powf(0,10) << std::endl;\n" " std::cout << powl(0,10) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1254,7 +1254,7 @@ class TestFunctions : public TestFixture { " std::cout << atan2l(0.1E-1,3) ;\n" " std::cout << atan2l(+0.1E-1,1) ;\n" " std::cout << atan2l(-0.1E-1,8) ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" @@ -1262,7 +1262,7 @@ class TestFunctions : public TestFixture { " std::cout << atan2(0,0) << std::endl;\n" " std::cout << atan2f(0,0) << std::endl;\n" " std::cout << atan2l(0,0) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:19]: (warning) Passing values 0 and 0 to atan2() leads to implementation-defined result. [wrongmathcall]\n" "[test.cpp:4:19]: (warning) Passing values 0 and 0 to atan2f() leads to implementation-defined result. [wrongmathcall]\n" "[test.cpp:5:19]: (warning) Passing values 0 and 0 to atan2l() leads to implementation-defined result. [wrongmathcall]\n", errout_str()); @@ -1275,7 +1275,7 @@ class TestFunctions : public TestFixture { " std::cout << fmod(1.0,0) << std::endl;\n" " std::cout << fmodf(1.0,0) << std::endl;\n" " std::cout << fmodl(1.0,0) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:28]: (error) Invalid fmod() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\n" "[test.cpp:4:29]: (error) Invalid fmodf() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\n" "[test.cpp:5:29]: (error) Invalid fmodl() argument nr 2. The value is 0 but the valid values are '!0.0'. [invalidFunctionArg]\n" @@ -1288,7 +1288,7 @@ class TestFunctions : public TestFixture { " std::cout << fmod(1.0,1) << std::endl;\n" " std::cout << fmodf(1.0,1) << std::endl;\n" " std::cout << fmodl(1.0,1) << std::endl;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1297,7 +1297,7 @@ class TestFunctions : public TestFixture { " print(exp(x) - 1);\n" " print(log(1 + x));\n" " print(1 - erf(x));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\n" "[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\n" "[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\n", errout_str()); @@ -1306,7 +1306,7 @@ class TestFunctions : public TestFixture { " print(exp(x) - 1.0);\n" " print(log(1.0 + x));\n" " print(1.0 - erf(x));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\n" "[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\n" "[test.cpp:4:12]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\n", errout_str()); @@ -1315,7 +1315,7 @@ class TestFunctions : public TestFixture { " print(exp(3 + x*f(a)) - 1);\n" " print(log(x*4 + 1));\n" " print(1 - erf(34*x + f(x) - c));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Expression 'exp(x) - 1' can be replaced by 'expm1(x)' to avoid loss of precision. [unpreciseMathCall]\n" "[test.cpp:3:11]: (style) Expression 'log(1 + x)' can be replaced by 'log1p(x)' to avoid loss of precision. [unpreciseMathCall]\n" "[test.cpp:4:11]: (style) Expression '1 - erf(x)' can be replaced by 'erfc(x)' to avoid loss of precision. [unpreciseMathCall]\n", errout_str()); @@ -1323,7 +1323,7 @@ class TestFunctions : public TestFixture { check("void foo() {\n" " print(2*exp(x) - 1);\n" " print(1 - erf(x)/2.0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1340,67 +1340,67 @@ class TestFunctions : public TestFixture { check("void foo() {\n" " mystrcmp(a, b);\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("[test.cpp:2:3]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\n", errout_str()); check("void foo() {\n" " foo::mystrcmp(a, b);\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("[test.cpp:2:8]: (warning) Return value of function foo::mystrcmp() is not used. [ignoredReturnValue]\n", errout_str()); check("void f() {\n" " foo x;\n" " x.mystrcmp(a, b);\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("[test.cpp:3:5]: (warning) Return value of function x.mystrcmp() is not used. [ignoredReturnValue]\n", errout_str()); check("bool mystrcmp(char* a, char* b);\n" // cppcheck sees a custom strcmp definition, but it returns a value. Assume it is the one specified in the library. "void foo() {\n" " mystrcmp(a, b);\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("[test.cpp:3:5]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\n", errout_str()); check("void mystrcmp(char* a, char* b);\n" // cppcheck sees a custom strcmp definition which returns void! "void foo() {\n" " mystrcmp(a, b);\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " class mystrcmp { mystrcmp() {} };\n" // strcmp is a constructor definition here - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " return mystrcmp(a, b);\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " return foo::mystrcmp(a, b);\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " if(mystrcmp(a, b));\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " bool b = mystrcmp(a, b);\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("", errout_str()); // #6194 check("void foo() {\n" " MyStrCmp mystrcmp(x, y);\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("", errout_str()); // #6197 check("void foo() {\n" " abc::def.mystrcmp(a,b);\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("", errout_str()); // #6233 @@ -1411,30 +1411,30 @@ class TestFunctions : public TestFixture { " };\n" " lambda(13.3);\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // TODO: use settings2? // #6669 check("void foo(size_t size) {\n" " void * res{malloc(size)};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // TODO: use settings2? // #7447 check("void foo() {\n" " int x{mystrcmp(a,b)};\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("", errout_str()); // #7905 check("void foo() {\n" " int x({mystrcmp(a,b)});\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" // don't crash " DEBUG(123)(mystrcmp(a,b))(fd);\n" - "}", settings2); + "}\n", settings2); check("struct teststruct {\n" " int testfunc1() __attribute__ ((warn_unused_result)) { return 1; }\n" " [[nodiscard]] int testfunc2() { return 1; }\n" @@ -1445,7 +1445,7 @@ class TestFunctions : public TestFixture { " TestStruct1.testfunc1();\n" " TestStruct1.testfunc2();\n" " return 0;\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("[test.cpp:4:18]: (warning) Return value of function testfunc1() is not used. [ignoredReturnValue]\n" "[test.cpp:4:31]: (warning) Return value of function testfunc2() is not used. [ignoredReturnValue]\n" "[test.cpp:8:17]: (warning) Return value of function TestStruct1.testfunc1() is not used. [ignoredReturnValue]\n" @@ -1455,7 +1455,7 @@ class TestFunctions : public TestFixture { check("template uint8_t b(std::tuple d) {\n" " std::tuple c{std::move(d)};\n" " return std::get<0>(c);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // TODO: use settings2? check("struct A { int x; };\n" @@ -1463,13 +1463,13 @@ class TestFunctions : public TestFixture { "A f(int x, Ts... xs) {\n" " return {std::move(x), static_cast(xs)...};\n" "}\n" - "A g() { return f(1); }"); + "A g() { return f(1); }\n"); ASSERT_EQUALS("", errout_str()); // TODO: use settings2? // #8412 - unused operator result check("void foo() {\n" " !mystrcmp(a, b);\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("[test.cpp:2:4]: (warning) Return value of function mystrcmp() is not used. [ignoredReturnValue]\n", errout_str()); check("void f(std::vector v) {\n" @@ -1501,24 +1501,24 @@ class TestFunctions : public TestFixture { check("void foo() {\n" " mystrcmp(a, b);\n" - "}", settings2); + "}\n", settings2); ASSERT_EQUALS("[test.cpp:2:3]: (style) Error code from the return value of function mystrcmp() is not used. [ignoredReturnErrorCode]\n", errout_str()); } void memsetZeroBytes() { check("void f() {\n" " memset(p, 10, 0x0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\n", errout_str()); check("void f() {\n" " memset(p, sizeof(p), 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\n", errout_str()); check("void f() {\n" " memset(p, sizeof(p), i);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #6269 false positives in case of overloaded standard library functions @@ -1527,13 +1527,13 @@ class TestFunctions : public TestFixture { " void f( void ) {\n" " memset( 0 );\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // #7285 check("void f() {\n" " memset(&tm, sizeof(tm), 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning) memset() called to fill 0 bytes. [memsetZeroBytes]\n", errout_str()); } @@ -1544,7 +1544,7 @@ class TestFunctions : public TestFixture { " memset(is, 1.0f, 40);\n" " int* is2 = new int[10];\n" " memset(is2, 0.1f, 40);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:17]: (portability) The 2nd memset() argument '1.0f' is a float, its representation is implementation defined. [memsetFloat]\n" "[test.cpp:5:18]: (portability) The 2nd memset() argument '0.1f' is a float, its representation is implementation defined. [memsetFloat]\n", errout_str()); @@ -1552,19 +1552,19 @@ class TestFunctions : public TestFixture { " int* is = new int[10];\n" " float g = computeG();\n" " memset(is, g, 40);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:16]: (portability) The 2nd memset() argument 'g' is a float, its representation is implementation defined. [memsetFloat]\n", errout_str()); check("void f() {\n" " int* is = new int[10];\n" " memset(is, 0.0f, 40);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" // FP " float x = 2.3f;\n" " memset(a, (x?64:0), 40);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -1572,7 +1572,7 @@ class TestFunctions : public TestFixture { " memset(ss, 256, 4);\n" " short ss2[2];\n" " memset(ss2, -129, 4);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:16]: (warning) The 2nd memset() argument '256' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\n" "[test.cpp:5:18]: (warning) The 2nd memset() argument '-129' doesn't fit into an 'unsigned char'. [memsetValueOutOfRange]\n", errout_str()); @@ -1587,23 +1587,23 @@ class TestFunctions : public TestFixture { " memset(cs2, 255, 30);\n" " char cs3[30];\n" " memset(cs3, 0, 30);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int is[10];\n" " const int i = g();\n" " memset(is, 1.0f + i, 40);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:21]: (portability) The 2nd memset() argument '1.0f+i' is a float, its representation is implementation defined. [memsetFloat]\n", errout_str()); } void checkMissingReturn1() { - check("int f() {}"); + check("int f() {}\n"); ASSERT_EQUALS("[test.cpp:1:10]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); { - const char code[] = "int main(void) {}"; + const char code[] = "int main(void) {}\n"; { const Settings s = settingsBuilder().c(Standards::C89).build(); @@ -1621,16 +1621,16 @@ class TestFunctions : public TestFixture { } } - check("F(A,B) { x=1; }"); + check("F(A,B) { x=1; }\n"); ASSERT_EQUALS("", errout_str()); - check("auto foo4() -> void {}"); + check("auto foo4() -> void {}\n"); ASSERT_EQUALS("", errout_str()); - check("void STDCALL foo() {}"); + check("void STDCALL foo() {}\n"); ASSERT_EQUALS("", errout_str()); - check("void operator=(int y) { x=y; }"); + check("void operator=(int y) { x=y; }\n"); ASSERT_EQUALS("", errout_str()); check("int f() {\n" @@ -1646,14 +1646,14 @@ class TestFunctions : public TestFixture { check("int foo(int x) {\n" " return 1;\n" " (void)x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int foo(int x) {\n" " if (x) goto out;\n" " return 1;\n" "out:\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); // switch @@ -1662,7 +1662,7 @@ class TestFunctions : public TestFixture { " case 1: break;\n" // <- error " case 2: return 1;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:17]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); check("int f() {\n" @@ -1670,7 +1670,7 @@ class TestFunctions : public TestFixture { " case 1: return 2; break;\n" " default: return 1;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool test(unsigned char v1, int v2) {\n" @@ -1684,7 +1684,7 @@ class TestFunctions : public TestFixture { " default:\n" " return true;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // if/else @@ -1692,7 +1692,7 @@ class TestFunctions : public TestFixture { " if (x) {\n" " return 1;\n" " }\n" // <- error (missing else) - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); check("int f(int x) {\n" @@ -1701,19 +1701,19 @@ class TestFunctions : public TestFixture { " } else {\n" " return 1;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); check("int f() {\n" " if (!0) {\n" " return 1;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f() {\n" " if (!0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); // loop @@ -1721,7 +1721,7 @@ class TestFunctions : public TestFixture { " while (1) {\n" " dostuff();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // return {..} @@ -1730,20 +1730,20 @@ class TestFunctions : public TestFixture { " return {};\n" " else\n" " return {1, 2};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // noreturn function - check("int f(int x) { exit(0); }"); + check("int f(int x) { exit(0); }\n"); ASSERT_EQUALS("", errout_str()); - check("int f(int x) { assert(0); }"); + check("int f(int x) { assert(0); }\n"); ASSERT_EQUALS("", errout_str()); - check("int f(int x) { if (x) return 1; else return bar({1}, {}); }"); + check("int f(int x) { if (x) return 1; else return bar({1}, {}); }\n"); ASSERT_EQUALS("", errout_str()); - check("auto f() -> void {}"); // #10342 + check("auto f() -> void {}\n"); // #10342 ASSERT_EQUALS("", errout_str()); check("struct S1 {\n" // #7433 @@ -1763,36 +1763,36 @@ class TestFunctions : public TestFixture { errout_str()); // #11171 - check("std::enable_if_t f() {}"); + check("std::enable_if_t f() {}\n"); ASSERT_EQUALS("", errout_str()); - check("std::enable_if_t f() {}"); + check("std::enable_if_t f() {}\n"); ASSERT_EQUALS( "[test.cpp:1:51]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); - check("template std::enable_if_t{}, int> f(T) {}"); + check("template std::enable_if_t{}, int> f(T) {}\n"); ASSERT_EQUALS( "[test.cpp:1:71]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); - check("template std::enable_if_t{}> f(T) {}"); + check("template std::enable_if_t{}> f(T) {}\n"); ASSERT_EQUALS("", errout_str()); - check("typename std::enable_if::type f() {}"); + check("typename std::enable_if::type f() {}\n"); ASSERT_EQUALS("", errout_str()); - check("typename std::enable_if::type f() {}"); + check("typename std::enable_if::type f() {}\n"); ASSERT_EQUALS( "[test.cpp:1:64]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); - check("template typename std::enable_if{}, int>::type f(T) {}"); + check("template typename std::enable_if{}, int>::type f(T) {}\n"); ASSERT_EQUALS( "[test.cpp:1:84]: (error) Found an exit path from function with non-void return type that has missing return statement [missingReturn]\n", errout_str()); - check("template typename std::enable_if{}>::type f(T) {}"); + check("template typename std::enable_if{}>::type f(T) {}\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" @@ -1943,35 +1943,35 @@ class TestFunctions : public TestFixture { // NRVO check void returnLocalStdMove1() { - check("struct A{}; A f() { A var; return std::move(var); }"); + check("struct A{}; A f() { A var; return std::move(var); }\n"); ASSERT_EQUALS("[test.cpp:1:45]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization." " More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\n", errout_str()); } // RVO, C++03 ctor style void returnLocalStdMove2() { - check("struct A{}; A f() { return std::move( A() ); }"); + check("struct A{}; A f() { return std::move( A() ); }\n"); ASSERT_EQUALS("[test.cpp:1:40]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization." " More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\n", errout_str()); } // RVO, new ctor style void returnLocalStdMove3() { - check("struct A{}; A f() { return std::move(A{}); }"); + check("struct A{}; A f() { return std::move(A{}); }\n"); ASSERT_EQUALS("[test.cpp:1:39]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization." " More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\n", errout_str()); } // Function argument void returnLocalStdMove4() { - check("struct A{}; A f(A a) { return std::move(A{}); }"); + check("struct A{}; A f(A a) { return std::move(A{}); }\n"); ASSERT_EQUALS("[test.cpp:1:42]: (performance) Using std::move for returning object by-value from function will affect copy elision optimization." " More: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-return-move-local [returnStdMoveLocal]\n", errout_str()); } void returnLocalStdMove5() { check("struct A{} a; A f1() { return std::move(a); }\n" - "A f2() { volatile A var; return std::move(var); }"); + "A f2() { volatile A var; return std::move(var); }\n"); ASSERT_EQUALS("", errout_str()); check("struct S { std::string msg{ \"abc\" }; };\n" @@ -1998,14 +1998,14 @@ class TestFunctions : public TestFixture { " int *a;\n" " a = malloc( -10 );\n" " free(a);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:17]: (error) Invalid malloc() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\n", errout_str()); check("void f() {\n" " int *a;\n" " a = alloca( -10 );\n" " free(a);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8]: (warning) Obsolete function 'alloca' called. [allocaCalled]\n" "[test.cpp:3:17]: (error) Invalid alloca() argument nr 1. The value is -10 but the valid values are '0:'. [invalidFunctionArg]\n", errout_str()); } @@ -2016,12 +2016,12 @@ class TestFunctions : public TestFixture { check("void f() {\n" " lib_func();" - "}", s); + "}\n", s); ASSERT_EQUALS("[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\n", errout_str()); check("void f(void* v) {\n" " lib_func(v);" - "}", s); + "}\n", s); ASSERT_EQUALS("[test.cpp:2:5]: (information) --check-library: There is no matching configuration for function lib_func() [checkLibraryFunction]\n", errout_str()); // #10105 @@ -2037,7 +2037,7 @@ class TestFunctions : public TestFixture { "\n" " void testFunctionReturnType() {\n" " }\n" - "};", s); + "};\n", s); ASSERT_EQUALS("", errout_str()); // #11183 @@ -2047,7 +2047,7 @@ class TestFunctions : public TestFixture { "\n" "void f() {\n" " cb(std::string(\"\"));\n" - "}", s); + "}\n", s); TODO_ASSERT_EQUALS("", "[test.cpp:6:5]: (information) --check-library: There is no matching configuration for function cb() [checkLibraryFunction]\n", errout_str()); // #7375 diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 7d91a013940..c798950b8e3 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -321,7 +321,7 @@ class TestGarbage : public TestFixture { void final_class_x() { - const char code[] = "class __declspec(dllexport) x final { };"; + const char code[] = "class __declspec(dllexport) x final { };\n"; SimpleTokenizer tokenizer(settings, *this); ASSERT(tokenizer.tokenize(code)); ASSERT_EQUALS("", errout_str()); @@ -329,18 +329,18 @@ class TestGarbage : public TestFixture { void wrong_syntax1() { { - const char code[] ="TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))"; + const char code[] ="TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))\n"; ASSERT_THROW_INTERNAL(checkCode(code), UNKNOWN_MACRO); ASSERT_EQUALS("", errout_str()); } { - const char code[] ="struct A { template struct { }; };"; + const char code[] ="struct A { template struct { }; };\n"; ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX); } { - const char code[] ="enum ABC { A,B, typedef enum { C } };"; + const char code[] ="enum ABC { A,B, typedef enum { C } };\n"; ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX); } } @@ -351,7 +351,7 @@ class TestGarbage : public TestFixture { " Y y;\n" "}\n" "\n" - "void G( template class (j) ) {}"; + "void G( template class (j) ) {}\n"; // don't segfault.. ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX); @@ -366,7 +366,7 @@ class TestGarbage : public TestFixture { " for( #endif typedef typedef cb[N] )\n" " ca[N]; = cb[i]\n" " )\n" - "}"; + "}\n"; SimpleTokenizer tokenizer(settings, *this); try { @@ -380,25 +380,25 @@ class TestGarbage : public TestFixture { } void wrong_syntax4() { // #3618 - const char code[] = "typedef void (x) (int); return x&"; + const char code[] = "typedef void (x) (int); return x&\n"; ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX); } void wrong_syntax_if_macro() { // #2518 #4171 - ASSERT_THROW_INTERNAL(checkCode("void f() { if MACRO(); }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() { if MACRO(); }\n"), SYNTAX); // #4668 - note there is no semicolon after MACRO() - ASSERT_THROW_INTERNAL(checkCode("void f() { if (x) MACRO() {} }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() { if (x) MACRO() {} }\n"), SYNTAX); // #4810 - note there is no semicolon after MACRO() - ASSERT_THROW_INTERNAL(checkCode("void f() { if (x) MACRO() else ; }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() { if (x) MACRO() else ; }\n"), SYNTAX); } void wrong_syntax_class_x_y() { // #3585 - const char code[] = "class x y { };"; + const char code[] = "class x y { };\n"; { SimpleTokenizer tokenizer(settings, *this, false); @@ -413,65 +413,65 @@ class TestGarbage : public TestFixture { } void wrong_syntax_anonymous_struct() { - ASSERT_THROW_INTERNAL(checkCode("struct { int x; } = {0};"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("struct { int x; } * = {0};"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("struct { int x; } = {0};\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("struct { int x; } * = {0};\n"), SYNTAX); } void syntax_case_default() { - ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case: z(); break;}}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case: z(); break;}}\n"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case;: z(); break;}}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case;: z(); break;}}\n"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case {}: z(); break;}}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case {}: z(); break;}}\n"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case 0?{1}:{2} : z(); break;}}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case 0?{1}:{2} : z(); break;}}\n"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case 0?1;:{2} : z(); break;}}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case 0?1;:{2} : z(); break;}}\n"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case 0?(1?{3:4}):2 : z(); break;}}"), AST); + ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case 0?(1?{3:4}):2 : z(); break;}}\n"), AST); //ticket #4234 - ASSERT_THROW_INTERNAL(checkCode("( ) { switch break ; { switch ( x ) { case } y break ; : } }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("( ) { switch break ; { switch ( x ) { case } y break ; : } }\n"), SYNTAX); //ticket #4267 - ASSERT_THROW_INTERNAL(checkCode("f ( ) { switch break; { switch ( x ) { case } case break; -6: ( ) ; } }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("f ( ) { switch break; { switch ( x ) { case } case break; -6: ( ) ; } }\n"), SYNTAX); // Missing semicolon - ASSERT_THROW_INTERNAL(checkCode("void foo () { switch(0) case 0 : default : }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void foo () { switch(0) case 0 : default : }\n"), SYNTAX); } void garbageCode1() { - (void)checkCode("struct x foo_t; foo_t typedef y;"); + (void)checkCode("struct x foo_t; foo_t typedef y;\n"); } void garbageCode2() { //#4300 (segmentation fault) - TODO_ASSERT_THROW(checkCode("enum { D = 1 struct { } ; } s.b = D;"), InternalError); + TODO_ASSERT_THROW(checkCode("enum { D = 1 struct { } ; } s.b = D;\n"), InternalError); } void garbageCode3() { //#4849 (segmentation fault in Tokenizer::simplifyStructDecl (invalid code)) - TODO_ASSERT_THROW(checkCode("enum { D = 2 s ; struct y { x } ; } { s.a = C ; s.b = D ; }"), InternalError); + TODO_ASSERT_THROW(checkCode("enum { D = 2 s ; struct y { x } ; } { s.a = C ; s.b = D ; }\n"), InternalError); } void garbageCode4() { // #4887 - ASSERT_THROW_INTERNAL(checkCode("void f ( ) { = a ; if ( 1 ) if = ( 0 ) ; }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f ( ) { = a ; if ( 1 ) if = ( 0 ) ; }\n"), SYNTAX); } void garbageCode5() { // #5168 (segmentation fault) - ASSERT_THROW_INTERNAL(checkCode("( asm : ; void : );"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("( asm : ; void : );\n"), SYNTAX); } void garbageCode6() { // #5214 - ASSERT_THROW_INTERNAL(checkCode("int b = ( 0 ? ? ) 1 : 0 ;"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("int a = int b = ( 0 ? ? ) 1 : 0 ;"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("int b = ( 0 ? ? ) 1 : 0 ;\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("int a = int b = ( 0 ? ? ) 1 : 0 ;\n"), SYNTAX); } void garbageCode7() { - ASSERT_THROW_INTERNAL(checkCode("1 (int j) { return return (c) * sizeof } y[1];"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("foo(Args&&...) fn void = { } auto template { { e = T::error }; };\n" "ScopedEnum1 se1; { enum class E : T { e = 0 = e ScopedEnum2 struct UnscopedEnum3 { T{ e = 4 }; };\n" "arr[(int) E::e]; }; UnscopedEnum3 e2 = f()\n" @@ -479,48 +479,48 @@ class TestGarbage : public TestFixture { "namespace UnscopedEnum { template struct UnscopedEnum1 { E{ e = T::error }; }; UnscopedEnum1 { enum E : { e = 0 }; };\n" "UnscopedEnum2 ue3; template struct UnscopedEnum3 { enum { }; }; int arr[E::e]; };\n" "UnscopedEnum3 namespace template int f() { enum E { e }; T::error }; return (int) E(); } int test1 int g() { enum E { e = E };\n" - "E::e; } int test2 = g(); }"), InternalError); + "E::e; } int test2 = g(); }\n"), InternalError); } void garbageCode9() { - TODO_ASSERT_THROW(checkCode("enum { e = { } } ( ) { { enum { } } } { e } "), InternalError); + TODO_ASSERT_THROW(checkCode("enum { e = { } } ( ) { { enum { } } } { e } \n"), InternalError); } void garbageCode10() { // #6127 - ASSERT_THROW_INTERNAL(checkCode("for( rl=reslist; rl!=NULL; rl=rl->next )"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("for( rl=reslist; rl!=NULL; rl=rl->next )\n"), SYNTAX); } void garbageCode12() { // do not crash - (void)checkCode("{ g; S (void) { struct } { } int &g; }"); + (void)checkCode("{ g; S (void) { struct } { } int &g; }\n"); ignore_errout(); // we do not care about the output } void garbageCode13() { // Ticket #2607 - crash - (void)checkCode("struct C {} {} x"); + (void)checkCode("struct C {} {} x\n"); } void garbageCode15() { // Ticket #5203 - ASSERT_THROW_INTERNAL(checkCode("int f ( int* r ) { { int s[2] ; f ( s ) ; if ( ) } }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("int f ( int* r ) { { int s[2] ; f ( s ) ; if ( ) } }\n"), SYNTAX); } void garbageCode16() { // #6080 (segmentation fault) - (void)checkCode("{ } A() { delete }"); // #6080 + (void)checkCode("{ } A() { delete }\n"); // #6080 ignore_errout(); // we do not care about the output } void garbageCode17() { ASSERT_THROW_INTERNAL(checkCode("void h(int l) {\n" " while\n" // Don't crash (#3870) - "}"), SYNTAX); + "}\n"), SYNTAX); } void garbageCode18() { - ASSERT_THROW_INTERNAL(checkCode("switch(){case}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("switch(){case}\n"), SYNTAX); } void garbageCode20() { // #3953 (valgrind errors on garbage code) - ASSERT_EQUALS("void f ( 0 * ) ;", checkCode("void f ( 0 * ) ;")); + ASSERT_EQUALS("void f ( 0 * ) ;", checkCode("void f ( 0 * ) ;\n")); } void garbageCode21() { @@ -531,7 +531,7 @@ class TestGarbage : public TestFixture { " x;\n" " int a, a2, a2*x; if () ;\n" " )\n" - "}"), SYNTAX); + "}\n"), SYNTAX); } void garbageCode22() { @@ -539,7 +539,7 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL(checkCode("int f()\n" "{\n" " return if\n" - "}"), SYNTAX); + "}\n"), SYNTAX); } void garbageCode23() { @@ -547,7 +547,7 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL_EQUALS(checkCode("{\n" " if (1) = x\n" " else abort s[2]\n" - "}"), + "}\n"), SYNTAX, "syntax error"); } @@ -570,7 +570,7 @@ class TestGarbage : public TestFixture { " switch ( x ) {\n" " case struct Tree : break;\n" " }\n" - "}"), SYNTAX); + "}\n"), SYNTAX); ignore_errout(); // we do not care about the output } @@ -582,13 +582,13 @@ class TestGarbage : public TestFixture { " case 0:\n" " return;\n" " }\n" - "}"), SYNTAX); + "}\n"), SYNTAX); } void garbageCode27() { ASSERT_THROW_INTERNAL(checkCode("int f() {\n" " return if\n" - "}"), SYNTAX); + "}\n"), SYNTAX); } void garbageCode28() { // #5702 (segmentation fault) @@ -596,7 +596,7 @@ class TestGarbage : public TestFixture { (void)checkCode("struct R1 {\n" " int a;\n" " R1 () : a { }\n" - "};"); + "};\n"); ignore_errout(); // we do not care about the output } @@ -604,16 +604,16 @@ class TestGarbage : public TestFixture { // simply survive - a syntax error would be even better (#5867) (void)checkCode("void f(int x) {\n" " x = 42\n" - "}"); + "}\n"); ignore_errout(); // we do not care about the output } void garbageCode31() { - ASSERT_THROW_INTERNAL(checkCode("typedef struct{}x[([],)]typedef e y;(y,x 0){}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("typedef struct{}x[([],)]typedef e y;(y,x 0){}\n"), SYNTAX); } void garbageCode33() { // #6613 (segmentation fault) - (void)checkCode("main(()B{});"); + (void)checkCode("main(()B{});\n"); } // Bug #6626 crash: Token::astOperand2() const ( do while ) @@ -621,13 +621,13 @@ class TestGarbage : public TestFixture { const char code[] = "void foo(void) {\n" " do\n" " while (0);\n" - "}"; + "}\n"; ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX); } void garbageCode35() { // ticket #2604 segmentation fault - ASSERT_THROW_INTERNAL(checkCode("sizeof <= A"), AST); + ASSERT_THROW_INTERNAL(checkCode("sizeof <= A\n"), AST); } void garbageCode36() { // #6334 @@ -641,311 +641,311 @@ class TestGarbage : public TestFixture { void garbageCode37() { // #5166 segmentation fault (invalid code) in lib/checkother.cpp:329 ( void * f { } void b ( ) { * f } ) - (void)checkCode("void * f { } void b ( ) { * f }"); + (void)checkCode("void * f { } void b ( ) { * f }\n"); ignore_errout(); // we do not care about the output } void garbageCode38() { // Ticket #6666 (segmentation fault) - (void)checkCode("{ f2 { } } void f3 () { delete[] } { }"); + (void)checkCode("{ f2 { } } void f3 () { delete[] } { }\n"); ignore_errout(); // we do not care about the output } void garbageCode40() { // #6620 (segmentation fault) - (void)checkCode("{ ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { }"); + (void)checkCode("{ ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { }\n"); // test doesn't seem to work on any platform: ASSERT_THROW(checkCode("{ ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { }", "test.c"), InternalError); } void garbageCode41() { // #6685 (segmentation fault) - (void)checkCode(" { } { return } *malloc(__SIZE_TYPE__ size); *memcpy(void n); static * const () { memcpy (*slot, 3); } { (); } { }"); + (void)checkCode(" { } { return } *malloc(__SIZE_TYPE__ size); *memcpy(void n); static * const () { memcpy (*slot, 3); } { (); } { }\n"); } void garbageCode42() { // #5760 (segmentation fault) - (void)checkCode("{ } * const ( ) { }"); + (void)checkCode("{ } * const ( ) { }\n"); } void garbageCode43() { // #6703 (segmentation fault) - (void)checkCode("int { }; struct A a = { }"); + (void)checkCode("int { }; struct A a = { }\n"); } void garbageCode44() { // #6704 - ASSERT_THROW_INTERNAL(checkCode("{ { }; }; { class A : }; public typedef b;"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ { }; }; { class A : }; public typedef b;\n"), SYNTAX); } void garbageCode45() { // #6608 - ASSERT_THROW_INTERNAL(checkCode("struct true template < > { = } > struct Types \"s\" ; static_assert < int > ;"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("struct true template < > { = } > struct Types \"s\" ; static_assert < int > ;\n"), SYNTAX); } void garbageCode46() { // #6705 (segmentation fault) - (void)checkCode(" { bar(char *x); void foo (int ...) { struct } va_list ap; va_start(ap, size); va_arg(ap, (d)); }"); + (void)checkCode(" { bar(char *x); void foo (int ...) { struct } va_list ap; va_start(ap, size); va_arg(ap, (d)); }\n"); ignore_errout(); // we do not care about the output } void garbageCode47() { // #6706 (segmentation fault) - (void)checkCode(" { { }; }; * new private: B: B;"); + (void)checkCode(" { { }; }; * new private: B: B;\n"); } void garbageCode48() { // #6712 (segmentation fault) - ASSERT_THROW_INTERNAL(checkCode(" { d\" ) d ...\" } int main ( ) { ( ) catch ( A a ) { { } catch ( ) \"\" } }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode(" { d\" ) d ...\" } int main ( ) { ( ) catch ( A a ) { { } catch ( ) \"\" } }\n"), SYNTAX); } void garbageCode49() { // #6715 - ASSERT_THROW_INTERNAL(checkCode(" ( ( ) ) { } ( { ( __builtin_va_arg_pack ( ) ) ; } ) { ( int { ( ) ( ( ) ) } ( ) { } ( ) ) += ( ) }"), AST); + ASSERT_THROW_INTERNAL(checkCode(" ( ( ) ) { } ( { ( __builtin_va_arg_pack ( ) ) ; } ) { ( int { ( ) ( ( ) ) } ( ) { } ( ) ) += ( ) }\n"), AST); } void garbageCode51() { // #6719 - ASSERT_THROW_INTERNAL(checkCode(" (const \"C\" ...); struct base { int f2; base (int arg1, int arg2); }; global_base(0x55, 0xff); { ((global_base.f1 0x55) (global_base.f2 0xff)) { } } base::base(int arg1, int arg2) { f2 = }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode(" (const \"C\" ...); struct base { int f2; base (int arg1, int arg2); }; global_base(0x55, 0xff); { ((global_base.f1 0x55) (global_base.f2 0xff)) { } } base::base(int arg1, int arg2) { f2 = }\n"), SYNTAX); } void garbageCode53() { // #6721 - ASSERT_THROW_INTERNAL(checkCode("{ { } }; void foo (struct int i) { x->b[i] = = }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ { } }; void foo (struct int i) { x->b[i] = = }\n"), SYNTAX); } void garbageCode54() { // #6722 - ASSERT_THROW_INTERNAL(checkCode("{ typedef long ((pf) p) (); }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ typedef long ((pf) p) (); }\n"), SYNTAX); } void garbageCode55() { // #6724 - ASSERT_THROW_INTERNAL(checkCode("() __attribute__((constructor)); { } { }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("() __attribute__((constructor)); { } { }\n"), SYNTAX); } void garbageCode56() { // #6713 - ASSERT_THROW_INTERNAL(checkCode("void foo() { int a = 0; int b = ???; }"), AST); + ASSERT_THROW_INTERNAL(checkCode("void foo() { int a = 0; int b = ???; }\n"), AST); } void garbageCode57() { // #6731 - ASSERT_THROW_INTERNAL(checkCode("{ } if () try { } catch (...) B::~B { }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ } if () try { } catch (...) B::~B { }\n"), SYNTAX); } void garbageCode58() { // #6732, #6762 - ASSERT_THROW_INTERNAL(checkCode("{ }> {= ~A()^{} }P { }"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("{= ~A()^{} }P { } { }> is"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ }> {= ~A()^{} }P { }\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{= ~A()^{} }P { } { }> is\n"), SYNTAX); } void garbageCode59() { // #6735 - ASSERT_THROW_INTERNAL(checkCode("{ { } }; char font8x8[256][8]"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ { } }; char font8x8[256][8]\n"), SYNTAX); } void garbageCode60() { // #6736 - ASSERT_THROW_INTERNAL(checkCode("{ } { } typedef int int_array[]; int_array &right ="), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ } { } typedef int int_array[]; int_array &right =\n"), SYNTAX); } void garbageCode61() { // #6737 - ASSERT_THROW_INTERNAL(checkCode("{ (const U&) }; { }; { }; struct U : virtual public"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ (const U&) }; { }; { }; struct U : virtual public\n"), SYNTAX); } void garbageCode63() { // #6739 - ASSERT_THROW_INTERNAL(checkCode("{ } { } typedef int u_array[]; typedef u_array &u_array_ref; (u_array_ref arg) { } u_array_ref u_array_ref_gbl_obj0"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ } { } typedef int u_array[]; typedef u_array &u_array_ref; (u_array_ref arg) { } u_array_ref u_array_ref_gbl_obj0\n"), SYNTAX); } void garbageCode64() { // #6740 - ASSERT_THROW_INTERNAL(checkCode("{ } foo(void (*bar)(void))"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ } foo(void (*bar)(void))\n"), SYNTAX); } void garbageCode65() { // #6741 (segmentation fault) // TODO write some syntax error - (void)checkCode("{ } { } typedef int u_array[]; typedef u_array &u_array_ref; (u_array_ref arg) { } u_array_ref"); + (void)checkCode("{ } { } typedef int u_array[]; typedef u_array &u_array_ref; (u_array_ref arg) { } u_array_ref\n"); } void garbageCode66() { // #6742 - ASSERT_THROW_INTERNAL(checkCode("{ { } }; { { } }; { }; class bar : public virtual"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ { } }; { { } }; { }; class bar : public virtual\n"), SYNTAX); } void garbageCode68() { // #6745 (segmentation fault) - (void)checkCode("(int a[3]); typedef void (*fp) (void); fp"); + (void)checkCode("(int a[3]); typedef void (*fp) (void); fp\n"); } void garbageCode69() { // #6746 - ASSERT_THROW_INTERNAL(checkCode("{ (make_mess, aux); } typedef void F(void); aux(void (*x)()) { } (void (*y)()) { } F*"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ (make_mess, aux); } typedef void F(void); aux(void (*x)()) { } (void (*y)()) { } F*\n"), SYNTAX); } void garbageCode70() { // #6747 - ASSERT_THROW_INTERNAL(checkCode("{ } __attribute__((constructor)) void"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ } __attribute__((constructor)) void\n"), SYNTAX); } void garbageCode71() { // #6748 - ASSERT_THROW_INTERNAL(checkCode("( ) { } typedef void noattr_t ( ) ; noattr_t __attribute__ ( )"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("( ) { } typedef void noattr_t ( ) ; noattr_t __attribute__ ( )\n"), SYNTAX); } void garbageCode72() { // #6749 - ASSERT_THROW_INTERNAL(checkCode("{ } { } typedef void voidfn(void); = } } unsigned *d = (b b--) --*d"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void foo (int **p) { { { };>= } } unsigned *d = (b b--) --*d\n"), SYNTAX); } void garbageCode78() { // #6756 - ASSERT_THROW_INTERNAL(checkCode("( ) { [ ] } ( ) { } const_array_of_int ( ) { } typedef int A [ ] [ ] ; A a = { { } { } }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("( ) { [ ] } ( ) { } const_array_of_int ( ) { } typedef int A [ ] [ ] ; A a = { { } { } }\n"), SYNTAX); ignore_errout(); // we do not care about the output } void garbageCode79() { // #6757 - ASSERT_THROW_INTERNAL(checkCode("{ } { } typedef void ( func_type ) ( ) ; func_type & ( )"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ } { } typedef void ( func_type ) ( ) ; func_type & ( )\n"), SYNTAX); } void garbageCode80() { // #6759 - ASSERT_THROW_INTERNAL(checkCode("( ) { ; ( ) ; ( * ) [ ] ; [ ] = ( ( ) ( ) h ) ! ( ( ) ) } { ; } { } head heads [ ] = ; = & heads [ 2 ]"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("( ) { ; ( ) ; ( * ) [ ] ; [ ] = ( ( ) ( ) h ) ! ( ( ) ) } { ; } { } head heads [ ] = ; = & heads [ 2 ]\n"), SYNTAX); } void garbageCode81() { // #6760 - ASSERT_THROW_INTERNAL(checkCode("{ } [ ] { ( ) } { } typedef void ( *fptr1 ) ( ) const"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ } [ ] { ( ) } { } typedef void ( *fptr1 ) ( ) const\n"), SYNTAX); } void garbageCode82() { // #6761 - ASSERT_THROW_INTERNAL(checkCode("p(\"Hello \" 14) _yn(const size_t) typedef bool pfunk (*pfunk)(const size_t)"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("p(\"Hello \" 14) _yn(const size_t) typedef bool pfunk (*pfunk)(const size_t)\n"), SYNTAX); } void garbageCode83() { // #6771 - ASSERT_THROW_INTERNAL(checkCode("namespace A { class } class A { friend C ; } { } ;"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("namespace A { class } class A { friend C ; } { } ;\n"), SYNTAX); } void garbageCode84() { // #6780 - ASSERT_THROW_INTERNAL(checkCode("int main ( [ ] ) { " " [ ] ; int i = 0 ; do { } ; } ( [ ] ) { }"), SYNTAX); // do not crash + ASSERT_THROW_INTERNAL(checkCode("int main ( [ ] ) { " " [ ] ; int i = 0 ; do { } ; } ( [ ] ) { }\n"), SYNTAX); // do not crash } void garbageCode85() { // #6784 (segmentation fault) - (void)checkCode("{ } { } typedef void ( *VoidFunc() ) ( ) ; VoidFunc"); // do not crash + (void)checkCode("{ } { } typedef void ( *VoidFunc() ) ( ) ; VoidFunc\n"); // do not crash } void garbageCode86() { // #6785 - ASSERT_THROW_INTERNAL(checkCode("{ } typedef char ( *( X ) ( void) , char ) ;"), SYNTAX); // do not crash + ASSERT_THROW_INTERNAL(checkCode("{ } typedef char ( *( X ) ( void) , char ) ;\n"), SYNTAX); // do not crash } void garbageCode87() { // #6788 - ASSERT_THROW_INTERNAL(checkCode("((X (128))) (int a) { v[ = {} (x 42) a] += }"), SYNTAX); // do not crash + ASSERT_THROW_INTERNAL(checkCode("((X (128))) (int a) { v[ = {} (x 42) a] += }\n"), SYNTAX); // do not crash } void garbageCode88() { // #6786 - ASSERT_THROW_INTERNAL(checkCode("( ) { ( 0 ) { ( ) } } g ( ) { i( ( false ?) ( ) : 1 ) ; } ;"), SYNTAX); // do not crash + ASSERT_THROW_INTERNAL(checkCode("( ) { ( 0 ) { ( ) } } g ( ) { i( ( false ?) ( ) : 1 ) ; } ;\n"), SYNTAX); // do not crash } void garbageCode90() { // #6790 - ASSERT_THROW_INTERNAL(checkCode("{ } { } typedef int u_array [[ ] ; typedef u_array & u_array_ref] ( ) { } u_array_ref_gbl_obj0"), SYNTAX); // do not crash + ASSERT_THROW_INTERNAL(checkCode("{ } { } typedef int u_array [[ ] ; typedef u_array & u_array_ref] ( ) { } u_array_ref_gbl_obj0\n"), SYNTAX); // do not crash } void garbageCode91() { // #6791 - ASSERT_THROW_INTERNAL(checkCode("typedef __attribute__((vector_size (16))) { return[ (v2df){ } ;] }"), SYNTAX); // throw syntax error + ASSERT_THROW_INTERNAL(checkCode("typedef __attribute__((vector_size (16))) { return[ (v2df){ } ;] }\n"), SYNTAX); // throw syntax error } void garbageCode92() { // #6792 - ASSERT_THROW_INTERNAL(checkCode("template < typename _Tp ( ( ) ; _Tp ) , decltype > { } { ( ) ( ) }"), SYNTAX); // do not crash + ASSERT_THROW_INTERNAL(checkCode("template < typename _Tp ( ( ) ; _Tp ) , decltype > { } { ( ) ( ) }\n"), SYNTAX); // do not crash } void garbageCode94() { // #6803 //checkCode("typedef long __m256i __attribute__ ( ( ( ) ) )[ ; ( ) { } typedef __m256i __attribute__ ( ( ( ) ) ) < ] ( ) { ; }"); - ASSERT_THROW_INTERNAL(checkCode("typedef long __m256i __attribute__ ( ( ( ) ) )[ ; ( ) { } typedef __m256i __attribute__ ( ( ( ) ) ) < ] ( ) { ; }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("typedef long __m256i __attribute__ ( ( ( ) ) )[ ; ( ) { } typedef __m256i __attribute__ ( ( ( ) ) ) < ] ( ) { ; }\n"), SYNTAX); } void garbageCode95() { // #6804 - ASSERT_THROW_INTERNAL(checkCode("{ } x x ; { } h h [ ] ( ) ( ) { struct x ( x ) ; int __attribute__ ( ) f ( ) { h - > first = & x ; struct x * n = h - > first ; ( ) n > } }"), SYNTAX); // do not crash + ASSERT_THROW_INTERNAL(checkCode("{ } x x ; { } h h [ ] ( ) ( ) { struct x ( x ) ; int __attribute__ ( ) f ( ) { h - > first = & x ; struct x * n = h - > first ; ( ) n > } }\n"), SYNTAX); // do not crash } void garbageCode96() { // #6807 - ASSERT_THROW_INTERNAL(checkCode("typedef J J[ ; typedef ( ) ( ) { ; } typedef J J ;] ( ) ( J cx ) { n } ;"), SYNTAX); // throw syntax error + ASSERT_THROW_INTERNAL(checkCode("typedef J J[ ; typedef ( ) ( ) { ; } typedef J J ;] ( ) ( J cx ) { n } ;\n"), SYNTAX); // throw syntax error } void garbageCode97() { // #6808 - ASSERT_THROW_INTERNAL(checkCode("namespace A {> } class A{ { }} class A : T< ;"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("namespace A {> } class A{ { }} class A : T< ;\n"), SYNTAX); } void garbageCode98() { // #6838 ASSERT_THROW_INTERNAL(checkCode("for (cocon To::ta@Taaaaaforconst oken aaaaaaaaaaaa5Dl()\n" "const unsigned in;\n" - "fon *tok = f);.s(Token i = d-)L;"), SYNTAX); + "fon *tok = f);.s(Token i = d-)L;\n"), SYNTAX); } void garbageCode99() { // #6726 ASSERT_THROW_INTERNAL_EQUALS(checkCode("{ xs :: i(:) ! ! x/5 ! !\n" "i, :: a :: b integer, } foo2(x) :: j(:)\n" "b type(*), d(:), a x :: end d(..), foo end\n" - "foo4 b d(..), a a x type(*), b foo2 b"), SYNTAX, "syntax error"); + "foo4 b d(..), a a x type(*), b foo2 b\n"), SYNTAX, "syntax error"); } void garbageCode100() { // #6840 - ASSERT_THROW_INTERNAL(checkCode("( ) { ( i< ) } int foo ( ) { int i ; ( for ( i => 1 ) ; ) }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("( ) { ( i< ) } int foo ( ) { int i ; ( for ( i => 1 ) ; ) }\n"), SYNTAX); } void garbageCode101() { // #6835 // Reported case - ASSERT_THROW_INTERNAL(checkCode("template < class , =( , int) X = 1 > struct A { } ( ) { = } [ { } ] ( ) { A < void > 0 }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("template < class , =( , int) X = 1 > struct A { } ( ) { = } [ { } ] ( ) { A < void > 0 }\n"), SYNTAX); // Reduced case - ASSERT_THROW_INTERNAL(checkCode("template < class =( , ) X = 1> struct A {}; A a;"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("template < class =( , ) X = 1> struct A {}; A a;\n"), SYNTAX); } void garbageCode102() { // #6846 (segmentation fault) - ASSERT_THROW_INTERNAL(checkCode("struct Object { ( ) ; Object & operator= ( Object ) { ( ) { } if ( this != & b ) } }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("struct Object { ( ) ; Object & operator= ( Object ) { ( ) { } if ( this != & b ) } }\n"), SYNTAX); } void garbageCode103() { // #6824 - ASSERT_THROW_INTERNAL(checkCode("a f(r) int * r; { { int s[2]; [f(s); if () ] } }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("a f(r) int * r; { { int s[2]; [f(s); if () ] } }\n"), SYNTAX); } void garbageCode104() { // #6847 - ASSERT_THROW_INTERNAL(checkCode("template < Types > struct S {> ( S < ) S >} { ( ) { } } ( ) { return S < void > ( ) } { ( )> >} { ( ) { } } ( ) { ( ) }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("template < Types > struct S {> ( S < ) S >} { ( ) { } } ( ) { return S < void > ( ) } { ( )> >} { ( ) { } } ( ) { ( ) }\n"), SYNTAX); } void garbageCode105() { // #6859 - ASSERT_THROW_INTERNAL(checkCode("void foo (int i) { int a , for (a 1; a( < 4; a++) if (a) (b b++) (b);) n++; }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void foo (int i) { int a , for (a 1; a( < 4; a++) if (a) (b b++) (b);) n++; }\n"), SYNTAX); } void garbageCode106() { // #6880 - ASSERT_THROW_INTERNAL(checkCode("[ ] typedef typedef b_array b_array_ref [ ; ] ( ) b_array_ref b_array_ref_gbl_obj0 { ; { b_array_ref b_array_ref_gbl_obj0 } }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("[ ] typedef typedef b_array b_array_ref [ ; ] ( ) b_array_ref b_array_ref_gbl_obj0 { ; { b_array_ref b_array_ref_gbl_obj0 } }\n"), SYNTAX); } void garbageCode107() { // #6881 - TODO_ASSERT_THROW(checkCode("enum { val = 1{ }; { const} }; { } Bar { const int A = val const } ;"), InternalError); + TODO_ASSERT_THROW(checkCode("enum { val = 1{ }; { const} }; { } Bar { const int A = val const } ;\n"), InternalError); } void garbageCode108() { // #6895 "segmentation fault (invalid code) in CheckCondition::isOppositeCond" - ASSERT_THROW_INTERNAL(checkCode("A( ) { } bool f( ) { ( ) F; ( ) { ( == ) if ( !=< || ( !A( ) && r[2] ) ) ( !A( ) ) ( ) } }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("A( ) { } bool f( ) { ( ) F; ( ) { ( == ) if ( !=< || ( !A( ) && r[2] ) ) ( !A( ) ) ( ) } }\n"), SYNTAX); } void garbageCode109() { // #6900 "segmentation fault (invalid code) in CheckStl::runSimplifiedChecks" - (void)checkCode("( *const<> (( ) ) { } ( *const ( ) ( ) ) { } ( * const<> ( size_t )) ) { } ( * const ( ) ( ) ) { }"); + (void)checkCode("( *const<> (( ) ) { } ( *const ( ) ( ) ) { } ( * const<> ( size_t )) ) { } ( * const ( ) ( ) ) { }\n"); } void garbageCode110() { // #6902 "segmentation fault (invalid code) in CheckStl::string_c_str" - ASSERT_THROW_INTERNAL(checkCode("( *const<> ( size_t ) ; foo ) { } * ( *const ( size_t ) ( ) ;> foo )< { }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("( *const<> ( size_t ) ; foo ) { } * ( *const ( size_t ) ( ) ;> foo )< { }\n"), SYNTAX); } void garbageCode111() { // #6907 - TODO_ASSERT_THROW(checkCode("enum { FOO = 1( ,) } {{ FOO }} ;"), InternalError); + TODO_ASSERT_THROW(checkCode("enum { FOO = 1( ,) } {{ FOO }} ;\n"), InternalError); } void garbageCode112() { // #6909 - TODO_ASSERT_THROW(checkCode("enum { FOO = ( , ) } {{ }}>> enum { FOO< = ( ) } { { } } ;"), InternalError); + TODO_ASSERT_THROW(checkCode("enum { FOO = ( , ) } {{ }}>> enum { FOO< = ( ) } { { } } ;\n"), InternalError); } void garbageCode114() { // #2118 ASSERT_NO_THROW(checkCode("Q_GLOBAL_STATIC_WITH_INITIALIZER(Qt4NodeStaticData, qt4NodeStaticData, {\n" " for (unsigned i = 0 ; i < count; i++) {\n" " }\n" - "});")); + "});\n")); } void garbageCode115() { // #5506 - ASSERT_THROW_INTERNAL(checkCode("A template < int { int = -1 ; } template < int N > struct B { int [ A < N > :: zero ] ; } ; B < 0 > b ;"), UNKNOWN_MACRO); + ASSERT_THROW_INTERNAL(checkCode("A template < int { int = -1 ; } template < int N > struct B { int [ A < N > :: zero ] ; } ; B < 0 > b ;\n"), UNKNOWN_MACRO); } void garbageCode116() { // #5356 - ASSERT_THROW_INTERNAL(checkCode("struct template struct B { }; B < 0 > b;"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("struct template struct B { }; B < 0 > b;\n"), SYNTAX); } void garbageCode117() { // #6121 TODO_ASSERT_THROW(checkCode("enum E { f = {} };\n" - "int a = f;"), InternalError); + "int a = f;\n"), InternalError); } void garbageCode118() { // #5600 - missing include causes invalid enum @@ -955,32 +955,32 @@ class TestGarbage : public TestFixture { "};\n" "struct bytecode {};\n" "jv jq_next() { opcode = ((opcode) +NUM_OPCODES);\n" - "}"), SYNTAX); + "}\n"), SYNTAX); } void garbageCode119() { // #5598 (segmentation fault) - (void)checkCode("{ { void foo() { struct }; template struct S { Used x; void bar() } auto f = [this] { }; } };"); + (void)checkCode("{ { void foo() { struct }; template struct S { Used x; void bar() } auto f = [this] { }; } };\n"); ignore_errout(); // we do not care about the output } void garbageCode120() { // #4927 (segmentation fault) (void)checkCode("int main() {\n" " return 0\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void garbageCode121() { // #2585 ASSERT_THROW_INTERNAL(checkCode("abcdef?" "?<" "123456?" "?>" - "+?" "?="), SYNTAX); + "+?" "?=\n"), SYNTAX); } void garbageCode122() { // #6303 (segmentation fault) (void)checkCode("void foo() {\n" "char *a = malloc(10);\n" "a[0]\n" - "}"); + "}\n"); ignore_errout(); // we do not care about the output } @@ -989,18 +989,18 @@ class TestGarbage : public TestFixture { " class C {\n" " C tpl_mem(T *) { return }\n" " };\n" - "}"); + "}\n"); ignore_errout(); // we do not care about the output } void garbageCode125() { - ASSERT_THROW_INTERNAL(checkCode("{ T struct B : T valueA_AA ; } T : [ T > ( ) { B } template < T > struct A < > : ] { ( ) { return valueA_AC struct { : } } b A < int > AC ( ) a_aa.M ; ( ) ( ) }"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("template < Types > struct S :{ ( S < ) S >} { ( ) { } } ( ) { return S < void > ( ) }"), + ASSERT_THROW_INTERNAL(checkCode("{ T struct B : T valueA_AA ; } T : [ T > ( ) { B } template < T > struct A < > : ] { ( ) { return valueA_AC struct { : } } b A < int > AC ( ) a_aa.M ; ( ) ( ) }\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("template < Types > struct S :{ ( S < ) S >} { ( ) { } } ( ) { return S < void > ( ) }\n"), SYNTAX); } void garbageCode126() { - ASSERT_THROW_INTERNAL(checkCode("{ } float __ieee754_sinhf ( float x ) { float t , , do { gf_u ( jx ) { } ( 0 ) return ; ( ) { } t } ( 0x42b17180 ) { } }"), + ASSERT_THROW_INTERNAL(checkCode("{ } float __ieee754_sinhf ( float x ) { float t , , do { gf_u ( jx ) { } ( 0 ) return ; ( ) { } t } ( 0x42b17180 ) { } }\n"), SYNTAX); } @@ -1013,38 +1013,38 @@ class TestGarbage : public TestFixture { " ~A() { printf(\"A d'tor\\n\"); }\n" "};\n" " const A& foo(const A& arg) { return arg; }\n" - " foo(A(12)).Var"); + " foo(A(12)).Var\n"); ignore_errout(); // we do not care about the output } void garbageCode128() { - TODO_ASSERT_THROW(checkCode("enum { FOO = ( , ) } {{ }} enum {{ FOO << = } ( ) } {{ }} ;"), + TODO_ASSERT_THROW(checkCode("enum { FOO = ( , ) } {{ }} enum {{ FOO << = } ( ) } {{ }} ;\n"), InternalError); } void garbageCode129() { - ASSERT_THROW_INTERNAL(checkCode("operator - ( { } typedef typename x ; ( ) ) { ( { { ( ( ) ) } ( { } ) } ) }"), + ASSERT_THROW_INTERNAL(checkCode("operator - ( { } typedef typename x ; ( ) ) { ( { { ( ( ) ) } ( { } ) } ) }\n"), SYNTAX); } void garbageCode130() { - TODO_ASSERT_THROW(checkCode("enum { FOO = ( , ){ } { { } } { { FOO} = } ( ) } { { } } enumL\" ( enumL\" { { FOO } ( ) } { { } } ;"), + TODO_ASSERT_THROW(checkCode("enum { FOO = ( , ){ } { { } } { { FOO} = } ( ) } { { } } enumL\" ( enumL\" { { FOO } ( ) } { { } } ;\n"), InternalError); } void garbageCode131() { - ASSERT_THROW_INTERNAL(checkCode("( void ) { ( ) } ( ) / { ( ) }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("( void ) { ( ) } ( ) / { ( ) }\n"), SYNTAX); // actually the invalid code should trigger an syntax error... } void garbageCode132() { // #7022 - ASSERT_THROW_INTERNAL(checkCode("() () { } { () () ({}) i() } void i(void(*ptr) ()) { ptr(!) () }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("() () { } { () () ({}) i() } void i(void(*ptr) ()) { ptr(!) () }\n"), SYNTAX); } void garbageCode133() { - ASSERT_THROW_INTERNAL(checkCode("void f() {{}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() {{}\n"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("void f()) {}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f()) {}\n"), SYNTAX); ASSERT_THROW_INTERNAL(checkCode("void f()\n" "{\n" @@ -1095,32 +1095,32 @@ class TestGarbage : public TestFixture { void garbageCode134() { // Ticket #5605, #5759, #5762, #5774, #5823, #6059 - ASSERT_THROW_INTERNAL(checkCode("foo() template struct tuple Args> tuple { } main() { foo(); }"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("( ) template < T1 = typename = unused> struct Args { } main ( ) { foo < int > ( ) ; }"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("() template < T = typename = x > struct a {} { f () }"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("template < T = typename = > struct a { f }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("foo() template struct tuple Args> tuple { } main() { foo(); }\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("( ) template < T1 = typename = unused> struct Args { } main ( ) { foo < int > ( ) ; }\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("() template < T = typename = x > struct a {} { f () }\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("template < T = typename = > struct a { f }\n"), SYNTAX); (void)checkCode("struct S { int i, j; }; " "template struct X {}; " "X<&S::i, int> x = X<&S::i, int>(); " - "X<&S::j, int> y = X<&S::j, int>();"); + "X<&S::j, int> y = X<&S::j, int>();\n"); ignore_errout(); // we are not interested in the output (void)checkCode("template struct A {}; " "template <> struct A {}; " - "void foo(const void* f = 0) {}"); + "void foo(const void* f = 0) {}\n"); (void)checkCode("template struct A { " " static const int s = 0; " "}; " - "A a;"); + "A a;\n"); (void)checkCode("template class A {}; " "template > class B {}; " "template > class C { " " C() : _a(0), _b(0) {} " " int _a, _b; " - "};"); + "};\n"); (void)checkCode("template struct A { " " static int i; " "}; " - "void f() { A::i = 0; }"); + "void f() { A::i = 0; }\n"); ignore_errout(); // we are not interested in the output } @@ -1129,17 +1129,17 @@ class TestGarbage : public TestFixture { " return a >> extern\n" "}\n" "long a = 1 ;\n" - "long b = 2 ;"); + "long b = 2 ;\n"); ignore_errout(); // we are not interested in the output } void garbageCode136() { // #7033 - ASSERT_THROW_INTERNAL(checkCode("{ } () { void f() { node_t * n; for (; -n) {} } } { }"), + ASSERT_THROW_INTERNAL(checkCode("{ } () { void f() { node_t * n; for (; -n) {} } } { }\n"), SYNTAX); } void garbageCode137() { // #7034 - ASSERT_THROW_INTERNAL(checkCode("\" \" typedef signed char f; \" \"; void a() { f * s = () &[]; (; ) (; ) }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("\" \" typedef signed char f; \" \"; void a() { f * s = () &[]; (; ) (; ) }\n"), SYNTAX); } void garbageCode138() { // #6660 (segmentation fault) @@ -1151,7 +1151,7 @@ class TestGarbage : public TestFixture { " {};\n" " } halo;\n" "}\n" - "CS_PLUGIN_NAMESPACE_END(csparser)"); + "CS_PLUGIN_NAMESPACE_END(csparser)\n"); ignore_errout(); // we are not interested in the output } @@ -1160,19 +1160,19 @@ class TestGarbage : public TestFixture { " de_ctrl = (nDirection == RIGHT_TO_LEFT) ?\n" " ( (0 & ~(((1 << (1 - (0 ? DE_CONTROL_DIRECTION))) - 1) << (0 ? DE_CONTROL_DIRECTION))) )\n" " : 42;\n" - "}"), SYNTAX); + "}\n"), SYNTAX); } void garbageCode140() { // #7035 - ASSERT_THROW_INTERNAL(checkCode("int foo(int align) { int off(= 0 % align; return off) ? \\ align - off : 0; \\ }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("int foo(int align) { int off(= 0 % align; return off) ? \\ align - off : 0; \\ }\n"), SYNTAX); } void garbageCode141() { // #7043 - TODO_ASSERT_THROW(checkCode("enum { X = << { X } } enum { X = X } = X ;"), InternalError); + TODO_ASSERT_THROW(checkCode("enum { X = << { X } } enum { X = X } = X ;\n"), InternalError); } void garbageCode142() { // #7050 - ASSERT_THROW_INTERNAL(checkCode("{ } ( ) { void mapGraphs ( ) { node_t * n ; for (!oid n ) { } } } { }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ } ( ) { void mapGraphs ( ) { node_t * n ; for (!oid n ) { } } } { }\n"), SYNTAX); } void garbageCode143() { // #6922 @@ -1186,18 +1186,18 @@ class TestGarbage : public TestFixture { " VGAwCR(0x64,0x?? );\n" " }\n" " }\n" - "}"), AST); + "}\n"), AST); } void garbageCode144() { // #6865 - ASSERT_THROW_INTERNAL(checkCode("template < typename > struct A { } ; template < typename > struct A < INVALID > : A < int[ > { }] ;"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("template < typename > struct A { } ; template < typename > struct A < INVALID > : A < int[ > { }] ;\n"), SYNTAX); } void garbageCode146() { // #7081 ASSERT_THROW_INTERNAL(checkCode("void foo() {\n" " ? std::cout << pow((, 1) << std::endl;\n" " double ( ); }"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("void f() { x = , * [ | + 0xff | > 0xff]; }"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("void f() { x = , | 0xff , 0.1 < ; }"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("void f() { x = [ 1 || ] ; }"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("void f1() { x = name6 1 || ? name3 [ ( 1 || +) ] ; }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() { x= name2 & name3 name2 = | 0.1 , | 0.1 , | 0.1 name4 <= >( ); }\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() { x = , * [ | + 0xff | > 0xff]; }\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() { x = , | 0xff , 0.1 < ; }\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() { x = [ 1 || ] ; }\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f1() { x = name6 1 || ? name3 [ ( 1 || +) ] ; }\n"), SYNTAX); } void garbageValueFlow() { @@ -1306,46 +1306,46 @@ class TestGarbage : public TestFixture { } { // 6122 survive garbage code - const char code[] = "; { int i ; for ( i = 0 ; = 123 ; ) - ; }"; + const char code[] = "; { int i ; for ( i = 0 ; = 123 ; ) - ; }\n"; ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX); } { - const char code[] = "void f1() { for (int n = 0 n < 10 n++); }"; + const char code[] = "void f1() { for (int n = 0 n < 10 n++); }\n"; ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX); } } void garbageSymbolDatabase() { - (void)checkCode("void f( { u = 1 ; } ) { }"); + (void)checkCode("void f( { u = 1 ; } ) { }\n"); - ASSERT_THROW_INTERNAL(checkCode("{ }; void namespace A::f; { g() { int } }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ }; void namespace A::f; { g() { int } }\n"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("class Foo {}; class Bar : public Foo"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("class Foo {}; class Bar : public Foo\n"), SYNTAX); // #5663 (segmentation fault) (void)checkCode("YY_DECL { switch (yy_act) {\n" " case 65: YY_BREAK\n" " case YY_STATE_EOF(block):\n" " yyterminate();\n" - "} }"); + "} }\n"); ignore_errout(); // we are not interested in the output } void garbageAST() { ASSERT_THROW_INTERNAL(checkCode("N 1024 float a[N], b[N + 3], c[N]; void N; (void) i;\n" "int #define for (i = avx_test i < c[i]; i++)\n" - "b[i + 3] = a[i] * {}"), SYNTAX); // Don't hang (#5787) + "b[i + 3] = a[i] * {}\n"), SYNTAX); // Don't hang (#5787) - (void)checkCode("START_SECTION([EXTRA](bool isValid(const String &filename)))"); // Don't crash (#5991) + (void)checkCode("START_SECTION([EXTRA](bool isValid(const String &filename)))\n"); // Don't crash (#5991) // #8352 ASSERT_THROW_INTERNAL(checkCode("else return % name5 name2 - =name1 return enum | { - name3 1 enum != >= 1 >= ++ { { || " - "{ return return { | { - name3 1 enum != >= 1 >= ++ { name6 | ; ++}}}}}}}"), UNKNOWN_MACRO); + "{ return return { | { - name3 1 enum != >= 1 >= ++ { name6 | ; ++}}}}}}}\n"), UNKNOWN_MACRO); ASSERT_THROW_INTERNAL(checkCode("else return % name5 name2 - =name1 return enum | { - name3 1 enum != >= 1 >= ++ { { || " - "{ return return { | { - name3 1 enum != >= 1 >= ++ { { || ; ++}}}}}}}}"), UNKNOWN_MACRO); + "{ return return { | { - name3 1 enum != >= 1 >= ++ { { || ; ++}}}}}}}}\n"), UNKNOWN_MACRO); - ASSERT_THROW_INTERNAL(checkCode("f(*p, requires(x));"), AST); // #14740 + ASSERT_THROW_INTERNAL(checkCode("f(*p, requires(x));\n"), AST); // #14740 } void templateSimplifierCrashes() { @@ -1369,7 +1369,7 @@ class TestGarbage : public TestFixture { " void f() {\n" " s.operator A >();\n" " }\n" - "}"); + "}\n"); ASSERT_NO_THROW(checkCode( // #6034 "template class T, typename... Args>\n" @@ -1383,7 +1383,7 @@ class TestGarbage : public TestFixture { "\n" "int main() {\n" " foo >::value;\n" - "}")); + "}\n")); (void)checkCode( // #6117 (segmentation fault) "template struct something_like_tuple\n" @@ -1401,7 +1401,7 @@ class TestGarbage : public TestFixture { "\n" "typedef something_like_tuple something_like_tuple_t;\n" "SA ((is_last::value == false));\n" - "SA ((is_last::value == false));"); + "SA ((is_last::value == false));\n"); ignore_errout(); // we are not interested in the output (void)checkCode( // #6225 (use-after-free) @@ -1412,7 +1412,7 @@ class TestGarbage : public TestFixture { " template \n" " struct A {};\n" " using AliasA = A;\n" - "}"); + "}\n"); // #3449 ASSERT_EQUALS("template < typename T > struct A ;\n" @@ -1420,72 +1420,72 @@ class TestGarbage : public TestFixture { "{ } ;", checkCode("template struct A;\n" "struct B { template struct C };\n" - "{};")); + "{};\n")); } void garbageCode161() { //7200 - ASSERT_THROW_INTERNAL(checkCode("{ }{ if () try { } catch (...)} B : : ~B { }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{ }{ if () try { } catch (...)} B : : ~B { }\n"), SYNTAX); } void garbageCode162() { //7208 - ASSERT_THROW_INTERNAL(checkCode("return << >> x return << >> x ", false), UNKNOWN_MACRO); + ASSERT_THROW_INTERNAL(checkCode("return << >> x return << >> x \n", false), UNKNOWN_MACRO); } void garbageCode163() { //7228 - ASSERT_THROW_INTERNAL(checkCode("typedef s f[](){typedef d h(;f)}", false), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("typedef s f[](){typedef d h(;f)}\n", false), SYNTAX); } void garbageCode164() { //7234 - ASSERT_THROW_INTERNAL(checkCode("class d{k p;}(){d::d():B<()}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("class d{k p;}(){d::d():B<()}\n"), SYNTAX); } void garbageCode165() { //7235 - ASSERT_THROW_INTERNAL(checkCode("for(;..)", false),SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("for(;..)\n", false),SYNTAX); } void garbageCode167() { //7237 - ASSERT_THROW_INTERNAL(checkCode("class D00i000{:D00i000::}i"),SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("class D00i000{:D00i000::}i\n"),SYNTAX); } void garbageCode168() { // #7246 (segmentation fault) - (void)checkCode("long foo(void) { return *bar; }", false); + (void)checkCode("long foo(void) { return *bar; }\n", false); ignore_errout(); // we do not care about the output } void garbageCode169() { // 6713 ASSERT_THROW_INTERNAL(checkCode("( ) { ( ) ; { return } switch ( ) i\n" - "set case break ; default: ( ) }", false), SYNTAX); + "set case break ; default: ( ) }\n", false), SYNTAX); } void garbageCode170() { // 7255 - ASSERT_THROW_INTERNAL(checkCode("d i(){{f*s=typeid(()0,)}}", false), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("d i(){{f*s=typeid(()0,)}}\n", false), SYNTAX); } void garbageCode171() { // 7270 - ASSERT_THROW_INTERNAL(checkCode("(){case()?():}:", false), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("(){case()?():}:\n", false), SYNTAX); } void garbageCode172() { // #7357 - ASSERT_THROW_INTERNAL(checkCode("p>,"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("p>,\n"), SYNTAX); } void garbageCode173() { // #6781 heap corruption ; TemplateSimplifier::simplifyTemplateInstantiations - ASSERT_THROW_INTERNAL(checkCode(" template < Types > struct S : >( S < ...Types... > S <) > { ( ) { } } ( ) { return S < void > ( ) }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode(" template < Types > struct S : >( S < ...Types... > S <) > { ( ) { } } ( ) { return S < void > ( ) }\n"), SYNTAX); } void garbageCode174() { // #7356 - ASSERT_THROW_INTERNAL(checkCode("{r e() { w*constD = (())D = cast< }}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{r e() { w*constD = (())D = cast< }}\n"), SYNTAX); } void garbageCode175() { // #7027 @@ -1494,32 +1494,32 @@ class TestGarbage : public TestFixture { " for ( i = t3 , i < t1 ; i++ )\n" " for ( j = 0 ; j < = j++ )\n" " return t1 ,\n" - "}"), SYNTAX); + "}\n"), SYNTAX); } void garbageCode176() { // #7257 (segmentation fault) - (void)checkCode("class t { { struct } enum class f : unsigned { q } b ; operator= ( T ) { switch ( b ) { case f::q: } } { assert ( b ) ; } } { ; & ( t ) ( f::t ) ; } ;"); + (void)checkCode("class t { { struct } enum class f : unsigned { q } b ; operator= ( T ) { switch ( b ) { case f::q: } } { assert ( b ) ; } } { ; & ( t ) ( f::t ) ; } ;\n"); ignore_errout(); // we are not interested in the output } void garbageCode181() { - ASSERT_THROW_INTERNAL(checkCode("int test() { int +; }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("int test() { int +; }\n"), SYNTAX); } // #4195 - segfault for "enum { int f ( ) { return = } r = f ( ) ; }" void garbageCode182() { - ASSERT_THROW_INTERNAL(checkCode("enum { int f ( ) { return = } r = f ( ) ; }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("enum { int f ( ) { return = } r = f ( ) ; }\n"), SYNTAX); } // #7505 - segfault void garbageCode183() { - ASSERT_THROW_INTERNAL(checkCode("= { int } enum return { r = f() f(); }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("= { int } enum return { r = f() f(); }\n"), SYNTAX); } void garbageCode184() { // #7699 ASSERT_THROW_INTERNAL(checkCode("unsigned int AquaSalSystem::GetDisplayScreenCount() {\n" " NSArray* pScreens = [NSScreen screens];\n" " return pScreens ? [pScreens count] : 1;\n" - "}"), SYNTAX); + "}\n"), SYNTAX); } void garbageCode185() { // #6011 crash in libreoffice failure to create proper AST @@ -1531,29 +1531,29 @@ class TestGarbage : public TestFixture { " pOut->CreateObject( nIndex, GDI_BRUSH, new WinMtfFillStyle( ReadColor(), ( nStyle == BS_HOLLOW ) ? TRUE : FALSE ) );\n" " return bStatus;\n" " };\n" - "}"); + "}\n"); ignore_errout(); // we are not interested in the output } // #8151 - segfault due to incorrect template syntax void garbageCode186() { - ASSERT_THROW_INTERNAL(checkCode("A<>C"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("A<>C\n"), SYNTAX); } void garbageCode187() { // # 8152 - segfault in handling const char inp[] = "0|\0|0>;\n"; ASSERT_THROW_INTERNAL(checkCode(inp), SYNTAX); - (void)checkCode("template struct S : A< B || C > {};"); // No syntax error: #8390 - (void)checkCode("static_assert(A || B, ab);"); + (void)checkCode("template struct S : A< B || C > {};\n"); // No syntax error: #8390 + (void)checkCode("static_assert(A || B, ab);\n"); } void garbageCode188() { // #8255 - ASSERT_THROW_INTERNAL(checkCode("{z r(){(){for(;<(x);){if(0==0)}}}}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{z r(){(){for(;<(x);){if(0==0)}}}}\n"), SYNTAX); } void garbageCode189() { // #8317 (segmentation fault) - (void)checkCode("t&n(){()()[](){()}}$"); + (void)checkCode("t&n(){()()[](){()}}$\n"); } void garbageCode190() { // #8307 @@ -1561,31 +1561,31 @@ class TestGarbage : public TestFixture { " int i;\n" " i *= 0;\n" " !i <;\n" - "}"), + "}\n"), AST); } void garbageCode191() { // #8333 - ASSERT_THROW_INTERNAL(checkCode("struct A { int f(const); };"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("struct A { int f(int, const, char); };"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("struct A { int f(struct); };"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("struct A { int f(const); };\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("struct A { int f(int, const, char); };\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("struct A { int f(struct); };\n"), SYNTAX); // The following code is valid and should not trigger any error - ASSERT_NO_THROW(checkCode("struct A { int f ( char ) ; } ;")); + ASSERT_NO_THROW(checkCode("struct A { int f ( char ) ; } ;\n")); } void garbageCode192() { // #8386 (segmentation fault) - ASSERT_THROW_INTERNAL(checkCode("{(()[((0||0xf||))]0[])}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{(()[((0||0xf||))]0[])}\n"), SYNTAX); } // #8740 void garbageCode193() { - ASSERT_THROW_INTERNAL(checkCode("d f(){!=[]&&0()!=0}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("d f(){!=[]&&0()!=0}\n"), SYNTAX); } // #8384 void garbageCode194() { - ASSERT_THROW_INTERNAL(checkCode("{((()))(return 1||);}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{((()))(return 1||);}\n"), SYNTAX); } // #8709 - no garbage but to avoid stability regression (segmentation fault) @@ -1595,19 +1595,19 @@ class TestGarbage : public TestFixture { " switch (d) { case b:; }\n" " double e(b);\n" " if(e <= 0) {}\n" - "}"); + "}\n"); ignore_errout(); // we do not care about the output } // #8265 void garbageCode196() { - ASSERT_THROW_INTERNAL(checkCode("0|,0<= void { ( ()) } 1 name3 return >= >= ( ) >= name5 (\n" " name5 name6 :nam00 [ ()])}))})})})};\n" - "}"), SYNTAX); + "}\n"), SYNTAX); } // #8752 (segmentation fault) void garbageCode199() { - ASSERT_THROW_INTERNAL(checkCode("d f(){e n00e0[]n00e0&" "0+f=0}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("d f(){e n00e0[]n00e0&" "0+f=0}\n"), SYNTAX); } // #8757 void garbageCode200() { - ASSERT_THROW_INTERNAL(checkCode("(){e break,{(case)!{e:[]}}}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("(){e break,{(case)!{e:[]}}}\n"), SYNTAX); } // #8873 void garbageCode201() { - ASSERT_THROW_INTERNAL(checkCode("void f() { std::string s=\"abc\"; return s + }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() { std::string s=\"abc\"; return s + }\n"), SYNTAX); } // #8907 void garbageCode202() { - ASSERT_THROW_INTERNAL(checkCode("void f() { UNKNOWN_MACRO(return); }"), UNKNOWN_MACRO); - ASSERT_THROW_INTERNAL(checkCode("void f() { UNKNOWN_MACRO(throw); }"), UNKNOWN_MACRO); + ASSERT_THROW_INTERNAL(checkCode("void f() { UNKNOWN_MACRO(return); }\n"), UNKNOWN_MACRO); + ASSERT_THROW_INTERNAL(checkCode("void f() { UNKNOWN_MACRO(throw); }\n"), UNKNOWN_MACRO); ignore_errout(); } void garbageCode203() { // #8972 (segmentation fault) - ASSERT_THROW_INTERNAL(checkCode("{ > () {} }"), SYNTAX); - (void)checkCode("template <> a > ::b();"); + ASSERT_THROW_INTERNAL(checkCode("{ > () {} }\n"), SYNTAX); + (void)checkCode("template <> a > ::b();\n"); } void garbageCode204() { - ASSERT_THROW_INTERNAL(checkCode("template ()> c; template a as() {} as>();"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("template ()> c; template a as() {} as>();\n"), SYNTAX); } void garbageCode205() { @@ -1667,55 +1667,55 @@ class TestGarbage : public TestFixture { "CodeSnippetsEvent :: CodeSnippetsEvent ( const CodeSnippetsEvent & Event )\n" ": wxCommandEvent ( Event )\n" ", m_SnippetID ( 0 ) {\n" - "}"), + "}\n"), INTERNAL); } void garbageCode206() { - ASSERT_EQUALS("[test.cpp:1] syntax error: operator", getSyntaxError("void foo() { for (auto operator new : int); }")); - ASSERT_EQUALS("[test.cpp:1] syntax error", getSyntaxError("void foo() { for (a operator== :) }")); + ASSERT_EQUALS("[test.cpp:1] syntax error: operator", getSyntaxError("void foo() { for (auto operator new : int); }\n")); + ASSERT_EQUALS("[test.cpp:1] syntax error", getSyntaxError("void foo() { for (a operator== :) }\n")); } void garbageCode207() { // #8750 - ASSERT_THROW_INTERNAL(checkCode("d f(){(.n00e0(return%n00e0''('')));}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("d f(){(.n00e0(return%n00e0''('')));}\n"), SYNTAX); } void garbageCode208() { // #8753 - ASSERT_THROW_INTERNAL(checkCode("d f(){(for(((((0{t b;((((((((()))))))))}))))))}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("d f(){(for(((((0{t b;((((((((()))))))))}))))))}\n"), SYNTAX); } void garbageCode209() { // #8756 - ASSERT_THROW_INTERNAL(checkCode("{(- -##0xf/-1 0)[]}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{(- -##0xf/-1 0)[]}\n"), SYNTAX); } void garbageCode210() { // #8762 - ASSERT_THROW_INTERNAL(checkCode("{typedef typedef c n00e0[]c000(;n00e0&c000)}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{typedef typedef c n00e0[]c000(;n00e0&c000)}\n"), SYNTAX); } void garbageCode211() { // #8764 - ASSERT_THROW_INTERNAL(checkCode("{typedef f typedef[]({typedef e e,>;typedef(((typedef;typedef(((typedef struct A {};\n" "template struct A {}; \n" - "A a;"); + "A a;\n"); } void garbageCode217() { // #10011 @@ -1723,11 +1723,11 @@ class TestGarbage : public TestFixture { " auto p;\n" " if (g(p)) {}\n" " assert();\n" - "}"), AST); + "}\n"), AST); } void garbageCode218() { // #8763 - ASSERT_THROW_INTERNAL(checkCode("d f(){t n0000 const[]n0000+0!=n0000,(0)}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("d f(){t n0000 const[]n0000+0!=n0000,(0)}\n"), SYNTAX); } void garbageCode219() { // #10101 (void)checkCode("typedef void (*func) (addr) ;\n" @@ -1747,111 +1747,111 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL(checkCode("template\n"), SYNTAX); // don't crash } void garbageCode223() { // #11639 - ASSERT_THROW_INTERNAL(checkCode("struct{}*"), SYNTAX); // don't crash + ASSERT_THROW_INTERNAL(checkCode("struct{}*\n"), SYNTAX); // don't crash } void garbageCode224() { - ASSERT_THROW_INTERNAL(checkCode("void f(){ auto* b = dynamic_cast int { return 0; }() };")); + ASSERT_NO_THROW(checkCode("void f() { enum { A = [=]() mutable { return 0; }() }; }\n")); + ASSERT_NO_THROW(checkCode("enum { A = [=](void) mutable -> int { return 0; }() };\n")); } void garbageCode229() { // #14126 - ASSERT_THROW_INTERNAL(checkCode("void f() {} [[maybe_unused]]"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("void f() {} [[unused]]"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() {} [[maybe_unused]]\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() {} [[unused]]\n"), SYNTAX); } void garbageCode230() { // #14432 - ASSERT_THROW_INTERNAL(checkCode("e U U,i"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("e U U,i\n"), SYNTAX); } void garbageCode231() { - ASSERT_THROW_INTERNAL(checkCode("char char* [] = {\"a\" \"b\"}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("char char* [] = {\"a\" \"b\"}\n"), SYNTAX); } void syntaxErrorFirstToken() { - ASSERT_THROW_INTERNAL(checkCode("&operator(){[]};"), SYNTAX); // #7818 - ASSERT_THROW_INTERNAL(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), SYNTAX); // #6858 - ASSERT_THROW_INTERNAL(checkCode(">{ x while (y) z int = }"), SYNTAX); // #4175 - ASSERT_THROW_INTERNAL(checkCode("&p(!{}e x){({(0?:?){({})}()})}"), SYNTAX); // #7118 - ASSERT_THROW_INTERNAL(checkCode(" { struct { typename D4:typename Base }; };"), SYNTAX); // #3533 + ASSERT_THROW_INTERNAL(checkCode("&operator(){[]};\n"), SYNTAX); // #7818 + ASSERT_THROW_INTERNAL(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }\n"), SYNTAX); // #6858 + ASSERT_THROW_INTERNAL(checkCode(">{ x while (y) z int = }\n"), SYNTAX); // #4175 + ASSERT_THROW_INTERNAL(checkCode("&p(!{}e x){({(0?:?){({})}()})}\n"), SYNTAX); // #7118 + ASSERT_THROW_INTERNAL(checkCode(" { struct { typename D4:typename Base }; };\n"), SYNTAX); // #3533 ASSERT_THROW_INTERNAL(checkCode(" > template < . > struct Y < T > { = } ;\n"), SYNTAX); // #6108 } void syntaxErrorLastToken() { - ASSERT_THROW_INTERNAL(checkCode("int *"), SYNTAX); // #7821 - ASSERT_THROW_INTERNAL(checkCode("x[y]"), SYNTAX); // #2986 - ASSERT_THROW_INTERNAL(checkCode("( ) &"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("|| #if #define <="), SYNTAX); // #2601 - ASSERT_THROW_INTERNAL(checkCode("f::y:y : \n"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("++4++ + + E++++++++++ + ch " "tp.oed5[.]"), SYNTAX); // #7074 - ASSERT_THROW_INTERNAL(checkCode("d a(){f s=0()8[]s?():0}*()?:0", false), SYNTAX); // #7236 - ASSERT_THROW_INTERNAL(checkCode("!2 : #h2 ?:", false), SYNTAX); // #7769 - ASSERT_THROW_INTERNAL(checkCode("--"), SYNTAX); - ASSERT_THROW_INTERNAL(checkCode("volatile true , test < test < #ifdef __ppc__ true ,"), SYNTAX); // #4169 + ASSERT_THROW_INTERNAL(checkCode("++4++ + + E++++++++++ + ch " "tp.oed5[.]\n"), SYNTAX); // #7074 + ASSERT_THROW_INTERNAL(checkCode("d a(){f s=0()8[]s?():0}*()?:0\n", false), SYNTAX); // #7236 + ASSERT_THROW_INTERNAL(checkCode("!2 : #h2 ?:\n", false), SYNTAX); // #7769 + ASSERT_THROW_INTERNAL(checkCode("--\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("volatile true , test < test < #ifdef __ppc__ true ,\n"), SYNTAX); // #4169 ASSERT_THROW_INTERNAL(checkCode("a,b--\n"), SYNTAX); // #2847 - ASSERT_THROW_INTERNAL(checkCode("x a[0] ="), SYNTAX); // #2682 + ASSERT_THROW_INTERNAL(checkCode("x a[0] =\n"), SYNTAX); // #2682 ASSERT_THROW_INTERNAL(checkCode("auto_ptr\n"), SYNTAX); // #2967 ASSERT_THROW_INTERNAL(checkCode("char a[1]\n"), SYNTAX); // #2865 - ASSERT_THROW_INTERNAL(checkCode("<><<"), SYNTAX); // #2612 - ASSERT_THROW_INTERNAL(checkCode("z"), SYNTAX); // #2831 - ASSERT_THROW_INTERNAL(checkCode("><,f<<\n"), SYNTAX); // #2612 + ASSERT_THROW_INTERNAL(checkCode("z\n"), SYNTAX); // #2831 + ASSERT_THROW_INTERNAL(checkCode("><,f typedef name5 | ( , ;){ } (); }"), SYNTAX); // #9067 - ASSERT_THROW_INTERNAL(checkCode("void f() { x= {}( ) ( 'x')[ ] (); }"), SYNTAX); // #9068 - ASSERT_THROW_INTERNAL(checkCode("void f() { x= y{ } name5 y[ ] + y ^ name5 ^ name5 for ( ( y y y && y y y && name5 ++ int )); }"), SYNTAX); // #9069 + ASSERT_THROW_INTERNAL(checkCode("void f() { x= 'x' > typedef name5 | ( , ;){ } (); }\n"), SYNTAX); // #9067 + ASSERT_THROW_INTERNAL(checkCode("void f() { x= {}( ) ( 'x')[ ] (); }\n"), SYNTAX); // #9068 + ASSERT_THROW_INTERNAL(checkCode("void f() { x= y{ } name5 y[ ] + y ^ name5 ^ name5 for ( ( y y y && y y y && name5 ++ int )); }\n"), SYNTAX); // #9069 } void cliCode() { @@ -1862,12 +1862,12 @@ class TestGarbage : public TestFixture { "bool GetDeviceInformation(String ^ port, LibCECConfiguration ^configuration, uint32_t timeoutMs) {\n" "bool bReturn(false);\n" "}\n" - "};")); + "};\n")); ignore_errout(); // we are not interested in the output } void enumTrailingComma() { - ASSERT_THROW_INTERNAL(checkCode("enum ssl_shutdown_t {ssl_shutdown_none = 0,ssl_shutdown_close_notify = , } ;"), SYNTAX); // #8079 + ASSERT_THROW_INTERNAL(checkCode("enum ssl_shutdown_t {ssl_shutdown_none = 0,ssl_shutdown_close_notify = , } ;\n"), SYNTAX); // #8079 } void nonGarbageCode1() { @@ -1880,25 +1880,25 @@ class TestGarbage : public TestFixture { "template< class T >\n" "template< class Predicate > int\n" "List::DeleteIf( const Predicate &pred )\n" - "{}")); + "{}\n")); ignore_errout(); // we are not interested in the output // #8749 ASSERT_NO_THROW(checkCode( "struct A {\n" " void operator+=(A&) && = delete;\n" - "};")); + "};\n")); // #8788 ASSERT_NO_THROW(checkCode( "struct foo;\n" "void f() {\n" " auto fn = []() -> foo* { return new foo(); };\n" - "}")); + "}\n")); ignore_errout(); // we do not care about the output // #13892 - ASSERT_NO_THROW(checkCode("void foovm(int x[const *]);")); + ASSERT_NO_THROW(checkCode("void foovm(int x[const *]);\n")); // #14676 ASSERT_NO_THROW(checkCode("int main() {\n" diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 72a13ee6c42..8e523e3d06e 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -93,7 +93,7 @@ class TestIncompleteStatement : public TestFixture { "{\n" " const char def[] =\n" " \"abc\";\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -102,7 +102,7 @@ class TestIncompleteStatement : public TestFixture { check("void foo()\n" "{\n" " \"abc\";\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning) Redundant code: Found a statement that begins with string constant. [constStatement]\n", errout_str()); } @@ -111,7 +111,7 @@ class TestIncompleteStatement : public TestFixture { check("void foo()\n" "{\n" " const char *str[] = { \"abc\" };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -125,7 +125,7 @@ class TestIncompleteStatement : public TestFixture { "\"more \"\n" "\"world\"\n" "};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -134,7 +134,7 @@ class TestIncompleteStatement : public TestFixture { check("void foo()\n" "{\n" " 50;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning) Redundant code: Found a statement that begins with numeric constant. [constStatement]\n", errout_str()); } @@ -145,7 +145,7 @@ class TestIncompleteStatement : public TestFixture { " 1 == (two + three);\n" " 2 != (two + three);\n" " (one + two) != (two + three);\n" - "}"); + "}\n"); } void test7() { // #9335 @@ -160,7 +160,7 @@ class TestIncompleteStatement : public TestFixture { " for (C c(S); ; ) {\n" " (void)c;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -174,7 +174,7 @@ class TestIncompleteStatement : public TestFixture { " {\n" " { 346.1,114.1 }, { 347.1,111.1 }\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -186,7 +186,7 @@ class TestIncompleteStatement : public TestFixture { "}\n"); ASSERT_EQUALS("", errout_str()); - check("void f() { (void*)0; }"); + check("void f() { (void*)0; }\n"); ASSERT_EQUALS("[test.cpp:1:12]: (warning) Redundant code: Found unused cast in expression '(void*)0'. [constStatement]\n", errout_str()); check("void f() {\n" // #13148 @@ -200,12 +200,12 @@ class TestIncompleteStatement : public TestFixture { errout_str()); check("#define X 0\n" - "void f() { X; }"); + "void f() { X; }\n"); ASSERT_EQUALS("", errout_str()); } void intarray() { - check("int arr[] = { 100/2, 1*100 };"); + check("int arr[] = { 100/2, 1*100 };\n"); ASSERT_EQUALS("", errout_str()); } @@ -213,7 +213,7 @@ class TestIncompleteStatement : public TestFixture { check("struct st arr[] = {\n" " { 100/2, 1*100 }\n" " { 90, 70 }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -221,14 +221,14 @@ class TestIncompleteStatement : public TestFixture { check("struct st arr[] = {\n" " { 100/2, 1*100 }\n" " { 90, 70 }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } void conditionalcall() { check("void f() {\n" " 0==x ? X() : Y();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -236,7 +236,7 @@ class TestIncompleteStatement : public TestFixture { // #2462 - C++11 struct initialization check("void f() {\n" " ABC abc{1,2,3};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #6260 - C++11 array initialization @@ -244,30 +244,30 @@ class TestIncompleteStatement : public TestFixture { " static const char* a[][2] {\n" " {\"b\", \"\"},\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #2482 - false positive for empty struct - check("struct A {};"); + check("struct A {};\n"); ASSERT_EQUALS("", errout_str()); // #4387 - C++11 initializer list - check("A::A() : abc{0} {}"); + check("A::A() : abc{0} {}\n"); ASSERT_EQUALS("", errout_str()); // #5042 - C++11 initializer list - check("A::A() : abc::def{0} {}"); + check("A::A() : abc::def{0} {}\n"); ASSERT_EQUALS("", errout_str()); // #4503 - vector init - check("void f() { vector v{1}; }"); + check("void f() { vector v{1}; }\n"); ASSERT_EQUALS("", errout_str()); } void returnstruct() { check("struct s foo() {\n" " return (struct s){0,0};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #4754 @@ -276,19 +276,19 @@ class TestIncompleteStatement : public TestFixture { " {\"hi\", \"there\"},\n" " {\"happy\", \"sad\"}\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct s foo() {\n" " return (struct s){0};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void cast() { check("void f() {\n" " ((struct foo *)(0x1234))->xy = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(const std::exception& e) {\n" // #10918 @@ -307,14 +307,14 @@ class TestIncompleteStatement : public TestFixture { check("void f() {\n" " int x = 1;\n" " x++, x++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void cpp11init() { check("void f() {\n" " int x{1};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::vector f(int* p) {\n" @@ -326,7 +326,7 @@ class TestIncompleteStatement : public TestFixture { void cpp11init2() { check("x handlers{\n" " { \"mode2\", []() { return 2; } },\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -334,33 +334,33 @@ class TestIncompleteStatement : public TestFixture { check("struct A { void operator()(int); };\n" "void f() {\n" "A{}(0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("template struct A { void operator()(int); };\n" "void f() {\n" "A{}(0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void block() { check("void f() {\n" " ({ do_something(); 0; });\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" "out:\n" " ({ do_something(); 0; });\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void mapindex() { check("void f() {\n" " map[{\"1\",\"2\"}]=0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -368,7 +368,7 @@ class TestIncompleteStatement : public TestFixture { check("void foo(int,const char*,int);\n" // #8827 "void f(int value) {\n" " foo(42,\"test\",42),(value&42);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:22]: (warning) Found suspicious operator ',', result is not used. [constStatement]\n", errout_str()); check("int f() {\n" // #11257 @@ -456,13 +456,13 @@ class TestIncompleteStatement : public TestFixture { "[test.cpp:9:5]: (warning, inconclusive) Found suspicious operator '~', result is not used. [constStatement]\n", errout_str()); - check("void f1(int x) { x; }", dinit(CheckOptions, $.inconclusive = true)); + check("void f1(int x) { x; }\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:1:18]: (warning) Unused variable value 'x' [constStatement]\n", errout_str()); - check("void f() { if (Type t; g(t)) {} }"); // #9776 + check("void f() { if (Type t; g(t)) {} }\n"); // #9776 ASSERT_EQUALS("", errout_str()); - check("void f(int x) { static_cast(x); }"); + check("void f(int x) { static_cast(x); }\n"); ASSERT_EQUALS("[test.cpp:1:38]: (warning) Redundant code: Found unused cast in expression 'static_cast(x)'. [constStatement]\n", errout_str()); check("void f(int x, int* p) {\n" @@ -473,7 +473,7 @@ class TestIncompleteStatement : public TestFixture { "}\n"); ASSERT_EQUALS("", errout_str()); - check("void f() { false; }"); // #10856 + check("void f() { false; }\n"); // #10856 ASSERT_EQUALS("[test.cpp:1:12]: (warning) Redundant code: Found a statement that begins with bool constant. [constStatement]\n", errout_str()); check("void f(int i) {\n" @@ -783,55 +783,55 @@ class TestIncompleteStatement : public TestFixture { void vardecl() { // #8984 - check("void f() { a::b *c = d(); }", dinit(CheckOptions, $.inconclusive = true)); + check("void f() { a::b *c = d(); }\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); - check("void f() { std::vector *c; }", dinit(CheckOptions, $.inconclusive = true)); + check("void f() { std::vector *c; }\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); - check("void f() { a::b &c = d(); }", dinit(CheckOptions, $.inconclusive = true)); + check("void f() { a::b &c = d(); }\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); - check("void f() { std::vector &c; }", dinit(CheckOptions, $.inconclusive = true)); + check("void f() { std::vector &c; }\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); - check("void f() { a::b &&c = d(); }", dinit(CheckOptions, $.inconclusive = true)); + check("void f() { a::b &&c = d(); }\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); - check("void f() { std::vector &&c; }", dinit(CheckOptions, $.inconclusive = true)); + check("void f() { std::vector &&c; }\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); - check("void f() { char * const * a, * const * b; }", dinit(CheckOptions, $.inconclusive = true)); + check("void f() { char * const * a, * const * b; }\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); - check("void f() { char * const * a = 0, * volatile restrict * b; }", dinit(CheckOptions, $.inconclusive = true, $.cpp = false)); + check("void f() { char * const * a = 0, * volatile restrict * b; }\n", dinit(CheckOptions, $.inconclusive = true, $.cpp = false)); ASSERT_EQUALS("", errout_str()); - check("void f() { char * const * a = 0, * volatile const * b; }", dinit(CheckOptions, $.inconclusive = true)); + check("void f() { char * const * a = 0, * volatile const * b; }\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } void archive() { check("void f(Archive &ar) {\n" " ar & x;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void f(int ar) {\n" " ar & x;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2:6]: (warning, inconclusive) Found suspicious operator '&', result is not used. [constStatement]\n", errout_str()); } void ast() { - check("struct c { void a() const { for (int x=0; x;); } };", dinit(CheckOptions, $.inconclusive = true)); + check("struct c { void a() const { for (int x=0; x;); } };\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } void oror() { check("void foo() {\n" " params_given (params, \"overrides\") || (overrides = \"1\");\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void f(std::ifstream& file) {\n" // #10930 diff --git a/test/testio.cpp b/test/testio.cpp index 2d191555ba6..2a7518706d5 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -124,50 +124,50 @@ class TestIO : public TestFixture { check( "void foo() {\n" " std::cout << std::cout;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:3]: (error) Invalid usage of output stream: '<< std::cout'. [coutCerrMisusage]\n", errout_str()); check( "void foo() {\n" " std::cout << (std::cout);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:3]: (error) Invalid usage of output stream: '<< std::cout'. [coutCerrMisusage]\n", errout_str()); check( "void foo() {\n" " std::cout << \"xyz\" << std::cout;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:3]: (error) Invalid usage of output stream: '<< std::cout'. [coutCerrMisusage]\n", errout_str()); check( "void foo(int i) {\n" " std::cout << i << std::cerr;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:3]: (error) Invalid usage of output stream: '<< std::cerr'. [coutCerrMisusage]\n", errout_str()); check( "void foo() {\n" " std::cout << \"xyz\";\n" " std::cout << \"xyz\";\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check( "void foo() {\n" " std::cout << std::cout.good();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check( "void foo() {\n" " unknownObject << std::cout;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check( "void foo() {\n" " MACRO(std::cout <<, << std::cout)\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -180,7 +180,7 @@ class TestIO : public TestFixture { " fread(buffer, 5, 6, f);\n" " rewind(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\n", errout_str()); check("void foo(FILE*& f) {\n" @@ -188,7 +188,7 @@ class TestIO : public TestFixture { " fread(buffer, 5, 6, f);\n" " rewind(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\n", errout_str()); check("void foo(FILE*& f) {\n" @@ -196,7 +196,7 @@ class TestIO : public TestFixture { " fread(buffer, 5, 6, f);\n" " rewind(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:5:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\n", errout_str()); check("void foo(FILE*& f) {\n" @@ -204,7 +204,7 @@ class TestIO : public TestFixture { " fread(buffer, 5, 6, f);\n" " rewind(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\n", errout_str()); check("void foo(FILE*& f) {\n" @@ -212,7 +212,7 @@ class TestIO : public TestFixture { " fread(buffer, 5, 6, f);\n" " rewind(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\n", errout_str()); check("void foo(FILE*& f) {\n" @@ -220,7 +220,7 @@ class TestIO : public TestFixture { " fread(buffer, 5, 6, f);\n" " rewind(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:5:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\n", errout_str()); check("void foo(FILE*& f) {\n" @@ -228,55 +228,55 @@ class TestIO : public TestFixture { " fread(buffer, 5, 6, f);\n" " rewind(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\n", errout_str()); check("void foo(FILE*& f) {\n" " f = fopen(name, \"r+\");\n" " fwrite(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(FILE*& f) {\n" " f = _wfopen(name, L\"r+\");\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("", errout_str()); check("void foo(FILE*& f) {\n" " f = _tfopen(name, _T(\"r+\"));\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("", errout_str()); check("void foo(FILE*& f) {\n" " f = _tfopen(name, _T(\"r+\"));\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("", errout_str()); check("void foo(FILE*& f) {\n" " _wfopen_s(&f, name, L\"r+\");\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("", errout_str()); check("void foo(FILE*& f) {\n" " _tfopen_s(&f, name, _T(\"r+\"));\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("", errout_str()); check("void foo(FILE*& f) {\n" " _tfopen_s(&f, name, _T(\"r+\"));\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("", errout_str()); check("void foo(FILE*& f) {\n" " f = tmpfile();\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("", errout_str()); // Write mode @@ -285,19 +285,19 @@ class TestIO : public TestFixture { " fwrite(buffer, 5, 6, f);\n" " rewind(f);\n" " fread(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5]: (error) Read operation on a file that was opened only for writing. [readWriteOnlyFile]\n", errout_str()); check("void foo(FILE*& f) {\n" " f = fopen(name, \"w+\");\n" " fread(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(FILE*& f) {\n" " f = tmpfile();\n" " fread(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Append mode @@ -306,14 +306,14 @@ class TestIO : public TestFixture { " fwrite(buffer, 5, 6, f);\n" " rewind(f);\n" " fread(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) Repositioning operation performed on a file opened in append mode has no effect. [seekOnAppendedFile]\n" "[test.cpp:5:5]: (error) Read operation on a file that was opened only for writing. [readWriteOnlyFile]\n", errout_str()); check("void foo(FILE*& f) {\n" " f = fopen(name, \"a+\");\n" " fread(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Variable declared locally @@ -321,7 +321,7 @@ class TestIO : public TestFixture { " FILE* f = fopen(name, \"r\");\n" " fwrite(buffer, 5, 6, f);\n" " fclose(f);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\n", errout_str()); // Call unknown function @@ -330,60 +330,60 @@ class TestIO : public TestFixture { " fwrite(buffer, 5, 6, f);\n" " bar(f);\n" " fread(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // freopen and tmpfile check("void foo(FILE*& f) {\n" " f = freopen(name, \"r\", f);\n" " fwrite(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\n", errout_str()); check("void foo(FILE*& f) {\n" " f = _wfreopen(name, L\"r\", f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\n", errout_str()); check("void foo(FILE*& f) {\n" " f = _tfreopen(name, _T(\"r\"), f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\n", errout_str()); check("void foo(FILE*& f) {\n" " f = _tfreopen(name, _T(\"r\"), f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\n", errout_str()); check("void foo(FILE*& f) {\n" " f = _wfreopen_s(&f, name, L\"r\", f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\n", errout_str()); check("void foo(FILE*& f) {\n" " f = _tfreopen_s(&f, name, _T(\"r\"), f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\n", errout_str()); check("void foo(FILE*& f) {\n" " f = _tfreopen_s(&f, name, _T(\"r\"), f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:3:5]: (error) Write operation on a file that was opened only for reading. [writeReadOnlyFile]\n", errout_str()); // Crash tests check("void foo(FILE*& f) {\n" " f = fopen(name, mode);\n" // No assertion failure (#3830) " fwrite(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); - check("void fopen(std::string const &filepath, std::string const &mode);"); // #3832 + check("void fopen(std::string const &filepath, std::string const &mode);\n"); // #3832 } void wrongMode_complex() { @@ -392,7 +392,7 @@ class TestIO : public TestFixture { " else f = fopen(name, \"r\");\n" " if(a) fwrite(buffer, 5, 6, f);\n" " else fread(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -401,14 +401,14 @@ class TestIO : public TestFixture { " else f = fopen(name, \"r\");\n" " if(a) fwrite(buffer, 5, 6, f);\n" " else fread(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " FILE* f = fopen(name, \"w\");\n" " if(a) fwrite(buffer, 5, 6, f);\n" " else fread(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:11]: (error) Read operation on a file that was opened only for writing. [readWriteOnlyFile]\n", errout_str()); } @@ -421,7 +421,7 @@ class TestIO : public TestFixture { " ungetc('a', f);\n" " ungetwc(L'a', f);\n" " rewind(f);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Used file that is not opened. [useClosedFile]\n" "[test.cpp:4:5]: (error) Used file that is not opened. [useClosedFile]\n" "[test.cpp:5:5]: (error) Used file that is not opened. [useClosedFile]\n" @@ -435,40 +435,40 @@ class TestIO : public TestFixture { " return;" " }\n" " fwrite(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(FILE*& f) {\n" " fclose(f);\n" " f = fopen(name, \"r\");\n" " fread(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(FILE*& f) {\n" " f = fopen(name, \"r\");\n" " f = g;\n" " fwrite(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " FILE* f;\n" " fwrite(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Used file that is not opened. [useClosedFile]\n", errout_str()); check("void foo() {\n" " FILE* f(stdout);\n" " fwrite(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" // #3965 " FILE* f[3];\n" " f[0] = fopen(name, mode);\n" " fclose(f[0]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #4368: multiple functions @@ -491,7 +491,7 @@ class TestIO : public TestFixture { " dump();\n" " close();\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("static FILE *fp = NULL;\n" @@ -505,7 +505,7 @@ class TestIO : public TestFixture { "{\n" " fclose(fp);\n" " fprintf(fp, \"Here's the output.\\n\");\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:11:3]: (error) Used file that is not opened. [useClosedFile]\n", errout_str()); // #4466 @@ -518,7 +518,7 @@ class TestIO : public TestFixture { " fclose(infile);\n" " return;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void chdcd_parse_nero(FILE *infile) {\n" @@ -530,7 +530,7 @@ class TestIO : public TestFixture { " fclose(infile);\n" " return;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #4649 @@ -540,14 +540,14 @@ class TestIO : public TestFixture { " a.f2 = fopen(name,mode);\n" " fclose(a.f1);\n" " fclose(a.f2);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #1473 check("void foo() {\n" " FILE *a = fopen(\"aa\", \"r\");\n" " while (fclose(a)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:12]: (warning) fclose() used as loop condition may skip loop body or double-close file handle. [fcloseInLoopCondition]\n", errout_str()); check("void foo() {\n" @@ -555,7 +555,7 @@ class TestIO : public TestFixture { " while (fclose(a)) {\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -563,13 +563,13 @@ class TestIO : public TestFixture { " while (fclose(a)) {\n" " a = fopen(\"aa\", \"r\");\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " FILE *a = fopen(\"aa\", \"r\");\n" " do {} while (fclose(a));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:18]: (warning) fclose() used as loop condition may skip loop body or double-close file handle. [fcloseInLoopCondition]\n", errout_str()); // #6823 @@ -579,7 +579,7 @@ class TestIO : public TestFixture { " f[1] = fopen(\"2\", \"w\");\n" " fclose(f[0]);\n" " fclose(f[1]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #12236 @@ -595,13 +595,13 @@ class TestIO : public TestFixture { check("void foo(FILE* f) {\n" " fwrite(buffer, 5, 6, f);\n" " fread(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. [IOWithoutPositioning]\n", errout_str()); check("void foo(FILE* f) {\n" " fread(buffer, 5, 6, f);\n" " fwrite(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. [IOWithoutPositioning]\n", errout_str()); check("void foo(FILE* f, bool read) {\n" @@ -609,42 +609,42 @@ class TestIO : public TestFixture { " fread(buffer, 5, 6, f);\n" " else\n" " fwrite(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(FILE* f) {\n" " fread(buffer, 5, 6, f);\n" " fflush(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(FILE* f) {\n" " fread(buffer, 5, 6, f);\n" " rewind(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(FILE* f) {\n" " fread(buffer, 5, 6, f);\n" " fsetpos(f, pos);\n" " fwrite(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(FILE* f) {\n" " fread(buffer, 5, 6, f);\n" " fseek(f, 0, SEEK_SET);\n" " fwrite(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(FILE* f) {\n" " fread(buffer, 5, 6, f);\n" " long pos = ftell(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. [IOWithoutPositioning]\n", errout_str()); // #6452 - member functions @@ -657,7 +657,7 @@ class TestIO : public TestFixture { " int bytesRead = fread(aboutToOverwrite.data(), 1, bufferLength, d->file);\n" " seek(writePosition);\n" " fwrite(buffer.data(), sizeof(char), buffer.size(), d->file);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class FileStream {\n" @@ -668,7 +668,7 @@ class TestIO : public TestFixture { " int bytesRead = fread(aboutToOverwrite.data(), 1, bufferLength, d->file);\n" " unknown(writePosition);\n" " fwrite(buffer.data(), sizeof(char), buffer.size(), d->file);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class FileStream {\n" @@ -680,7 +680,7 @@ class TestIO : public TestFixture { " int bytesRead = fread(aboutToOverwrite.data(), 1, bufferLength, d->file);\n" " known(writePosition);\n" " fwrite(buffer.data(), sizeof(char), buffer.size(), d->file);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:5]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. [IOWithoutPositioning]\n", errout_str()); check("class FileStream {\n" @@ -692,7 +692,7 @@ class TestIO : public TestFixture { " int bytesRead = fread(X::data(), 1, bufferLength, d->file);\n" " known(writePosition);\n" " fwrite(X::data(), sizeof(char), buffer.size(), d->file);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:5]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. [IOWithoutPositioning]\n", errout_str()); check("struct MemStream {\n" @@ -717,25 +717,25 @@ class TestIO : public TestFixture { check("void foo() {\n" " FILE* f = fopen(\"\", \"a+\");\n" " fseek(f, 0, SEEK_SET);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " FILE* f = fopen(\"\", \"w\");\n" " fseek(f, 0, SEEK_SET);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " FILE* f = fopen(\"\", \"a\");\n" " fseek(f, 0, SEEK_SET);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning) Repositioning operation performed on a file opened in append mode has no effect. [seekOnAppendedFile]\n", errout_str()); check("void foo() {\n" " FILE* f = fopen(\"\", \"a\");\n" " fflush(f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #5578 check("void foo() {\n" @@ -743,7 +743,7 @@ class TestIO : public TestFixture { " fclose(f);\n" " f = fopen(\"\", \"r\");\n" " fseek(f, 0, SEEK_SET);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #6566 } @@ -767,30 +767,30 @@ class TestIO : public TestFixture { check("void foo()\n" "{\n" " fflush(stdin);\n" - "}", dinit(CheckOptions, $.portability = true)); + "}\n", dinit(CheckOptions, $.portability = true)); ASSERT_EQUALS("[test.cpp:3:5]: (portability) fflush() called on input stream 'stdin' may result in undefined behaviour on non-linux systems. [fflushOnInputStream]\n", errout_str()); check("void foo()\n" "{\n" " fflush(stdout);\n" - "}", dinit(CheckOptions, $.portability = true)); + "}\n", dinit(CheckOptions, $.portability = true)); ASSERT_EQUALS("", errout_str()); check("void foo(FILE*& f) {\n" " f = fopen(path, \"r\");\n" " fflush(f);\n" - "}", dinit(CheckOptions, $.portability = true)); + "}\n", dinit(CheckOptions, $.portability = true)); ASSERT_EQUALS("[test.cpp:3:5]: (portability) fflush() called on input stream 'f' may result in undefined behaviour on non-linux systems. [fflushOnInputStream]\n", errout_str()); check("void foo(FILE*& f) {\n" " f = fopen(path, \"w\");\n" " fflush(f);\n" - "}", dinit(CheckOptions, $.portability = true)); + "}\n", dinit(CheckOptions, $.portability = true)); ASSERT_EQUALS("", errout_str()); check("void foo(FILE*& f) {\n" " fflush(f);\n" - "}", dinit(CheckOptions, $.portability = true)); + "}\n", dinit(CheckOptions, $.portability = true)); ASSERT_EQUALS("", errout_str()); } @@ -798,7 +798,7 @@ class TestIO : public TestFixture { check("void foo() {\n" " FILE *f1 = fopen(\"tmp\", \"wt\");\n" " FILE *f2 = fopen(\"tmp\", \"rt\");\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:16]: (warning) The file '\"tmp\"' is opened for read and write access at the same time on different streams [incompatibleFileOpen]\n", errout_str()); } @@ -810,7 +810,7 @@ class TestIO : public TestFixture { " fgets(line, sizeof(line), fp);\n" " dostuff(line);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (warning) Using feof() as a loop condition causes the last line to be processed twice. [wrongfeofUsage]\n", errout_str()); check("int foo(FILE *fp) {\n" @@ -819,7 +819,7 @@ class TestIO : public TestFixture { " if (!feof(fp))\n" " return 1;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(FILE *fp){\n" @@ -829,7 +829,7 @@ class TestIO : public TestFixture { " dostuff(line);\n" " fgets(line, sizeof(line), fp);" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(FILE *fp) {\n" @@ -838,7 +838,7 @@ class TestIO : public TestFixture { " fgets(line, sizeof(line), fp);\n" " dostuff(line);\n" " } while (!feof(fp));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:12]: (warning) Using feof() as a loop condition causes the last line to be processed twice. [wrongfeofUsage]\n", errout_str()); check("void foo(FILE *fp) {\n" @@ -847,7 +847,7 @@ class TestIO : public TestFixture { " dostuff(line);\n" " fgets(line, sizeof(line), fp);\n" " } while (!feof(fp));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -862,7 +862,7 @@ class TestIO : public TestFixture { " sscanf(foo, \"%[^~]\", bar);\n" " scanf(\"%dx%s\", &b, bar);\n" " fclose(file);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (warning) fscanf() without field width limits can crash with huge input data. [invalidscanf]\n" "[test.cpp:5:9]: (warning) scanf() without field width limits can crash with huge input data. [invalidscanf]\n" "[test.cpp:6:9]: (warning) scanf() without field width limits can crash with huge input data. [invalidscanf]\n" @@ -878,7 +878,7 @@ class TestIO : public TestFixture { " scanf(\"aa%d\", &a);\n" // No %s " scanf(\"aa%ld\", &a);\n" // No %s " scanf(\"%*[^~]\");\n" // Ignore input - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) scanf format string requires 0 parameters but 1 is given. [wrongPrintfScanfArgNum]\n", errout_str()); } @@ -888,7 +888,7 @@ class TestIO : public TestFixture { " scanf(\"%7c\", str);\n" " scanf(\"%8c\", str);\n" " scanf(\"%9c\", str);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:3]: (error) Width 9 given in format string (no. 1) is larger than destination buffer 'str[8]', use %8c to prevent overflowing it. [invalidScanfFormatWidth]\n", errout_str()); } @@ -897,7 +897,7 @@ class TestIO : public TestFixture { "{\n" " char str [8];\n" " scanf (\"%70s\",str);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:3]: (error) Width 70 given in format string (no. 1) is larger than destination buffer 'str[8]', use %7s to prevent overflowing it. [invalidScanfFormatWidth]\n", errout_str()); } @@ -905,7 +905,7 @@ class TestIO : public TestFixture { check("char s1[42], s2[42];\n" "void test() {\n" " scanf(\"%42s%42[a-z]\", s1, s2);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Width 42 given in format string (no. 1) is larger than destination buffer 's1[42]', use %41s to prevent overflowing it. [invalidScanfFormatWidth]\n" "[test.cpp:3:5]: (error) Width 42 given in format string (no. 2) is larger than destination buffer 's2[42]', use %41[a-z] to prevent overflowing it. [invalidScanfFormatWidth]\n", errout_str()); } @@ -920,7 +920,7 @@ class TestIO : public TestFixture { #define TEST_SCANF_CODE(format, type) \ - "void f(){" type " x; scanf(\"" format "\", &x);}" + "void f(){" type " x; scanf(\"" format "\", &x);}\n" #define TEST_SCANF_ERR(format, formatStr, type) \ "[test.c:1]: (warning) " format " in format string (no. 1) requires '" formatStr " *' but the argument type is '" type " *'.\n" @@ -935,7 +935,7 @@ class TestIO : public TestFixture { TEST_SCANF_ERR_AKA_("test.cpp", format, formatStr, type, akaType) #define TEST_PRINTF_CODE(format, type) \ - "void f(" type " x){printf(\"" format "\", x);}" + "void f(" type " x){printf(\"" format "\", x);}\n" #define TEST_PRINTF_ERR(format, requiredType, actualType) \ "[test.c:1]: (warning) " format " in format string (no. 1) requires '" requiredType "' but the argument type is '" actualType "'.\n" @@ -1074,7 +1074,7 @@ class TestIO : public TestFixture { " scanf(\"%*1x %1x %29s\", &count, KeyName);\n" // #3373 " fscanf(f, \"%7ms\", &ref);\n" // #3461 " sscanf(ip_port, \"%*[^:]:%4d\", &port);\n" // #3468 - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -1082,7 +1082,7 @@ class TestIO : public TestFixture { " scanf(\"%1d\", &foo, &bar);\n" " fscanf(bar, \"%1d\", &foo, &bar);\n" " scanf(\"%*1x %1x %29s\", &count, KeyName, foo);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) scanf format string requires 0 parameters but 1 is given.\n" "[test.cpp:3]: (warning) scanf format string requires 1 parameter but 2 are given.\n" "[test.cpp:4]: (warning) fscanf format string requires 1 parameter but 2 are given.\n" @@ -1093,7 +1093,7 @@ class TestIO : public TestFixture { " scanf(\"%1u%1u\", bar());\n" " sscanf(bar, \"%1d%1d\", &foo);\n" " scanf(\"%*1x %1x %29s\", &count);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (error) scanf format string requires 1 parameter but only 0 are given.\n" "[test.cpp:3]: (error) scanf format string requires 2 parameters but only 1 is given.\n" "[test.cpp:4]: (error) sscanf format string requires 2 parameters but only 1 is given.\n" @@ -1105,7 +1105,7 @@ class TestIO : public TestFixture { " sscanf(input, \"%3s\", output);\n" " sscanf(input, \"%4s\", output);\n" " sscanf(input, \"%5s\", output);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6]: (error) Width 5 given in format string (no. 1) is larger than destination buffer 'output[5]', use %4s to prevent overflowing it.\n", errout_str()); check("void foo() {\n" @@ -1115,7 +1115,7 @@ class TestIO : public TestFixture { " sscanf(input, \"%3s\", output);\n" " sscanf(input, \"%4s\", output);\n" " sscanf(input, \"%5s\", output);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:5]: (warning, inconclusive) Width 3 given in format string (no. 1) is smaller than destination buffer 'output[5]'.\n" "[test.cpp:7]: (error) Width 5 given in format string (no. 1) is larger than destination buffer 'output[5]', use %4s to prevent overflowing it.\n" "[test.cpp:4]: (warning) sscanf() without field width limits can crash with huge input data.\n", errout_str()); @@ -1127,7 +1127,7 @@ class TestIO : public TestFixture { " bufT projectId= {0};\n" " const int scanrc=sscanf(line, \"Project(\\\"{%36s}\\\")\", projectId);\n" " sscanf(input, \"%5s\", output);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:6]: (warning, inconclusive) Width 36 given in format string (no. 1) is smaller than destination buffer 'projectId[2048]'.\n", errout_str()); check("void foo(unsigned int i) {\n" @@ -1140,7 +1140,7 @@ class TestIO : public TestFixture { " scanf(\"%t\", &i);\n" " scanf(\"%L\", &i);\n" " scanf(\"%I\", &i);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) 'h' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\n" "[test.cpp:3]: (warning) 'hh' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\n" "[test.cpp:4]: (warning) 'l' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\n" @@ -1196,13 +1196,13 @@ class TestIO : public TestFixture { check("void foo() {\n" " scanf(\"%u\", \"s3\");\n" " scanf(\"%u\", L\"s5W\");\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %u in format string (no. 1) requires 'unsigned int *' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) %u in format string (no. 1) requires 'unsigned int *' but the argument type is 'const wchar_t *'.\n", errout_str()); check("void foo(long l) {\n" " scanf(\"%u\", l);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %u in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed long'.\n", errout_str()); TEST_SCANF_WARN("%lu","unsigned long","bool"); @@ -1584,13 +1584,13 @@ class TestIO : public TestFixture { check("void foo() {\n" " scanf(\"%Ld\", \"s3\");\n" " scanf(\"%Ld\", L\"s5W\");\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %Ld in format string (no. 1) requires 'long long *' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) %Ld in format string (no. 1) requires 'long long *' but the argument type is 'const wchar_t *'.\n", errout_str()); check("void foo(int i) {\n" " scanf(\"%Ld\", i);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %Ld in format string (no. 1) requires 'long long *' but the argument type is 'signed int'.\n", errout_str()); TEST_SCANF_WARN("%ju", "uintmax_t", "bool"); @@ -2061,13 +2061,13 @@ class TestIO : public TestFixture { check("void foo() {\n" " scanf(\"%d\", \"s3\");\n" " scanf(\"%d\", L\"s5W\");\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %d in format string (no. 1) requires 'int *' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int *' but the argument type is 'const wchar_t *'.\n", errout_str()); check("void foo(long l) {\n" " scanf(\"%d\", l);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %d in format string (no. 1) requires 'int *' but the argument type is 'signed long'.\n", errout_str()); TEST_SCANF_WARN("%x", "unsigned int", "bool"); @@ -2105,13 +2105,13 @@ class TestIO : public TestFixture { check("void foo() {\n" " scanf(\"%x\", \"s3\");\n" " scanf(\"%x\", L\"s5W\");\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'const wchar_t *'.\n", errout_str()); check("void foo(long l) {\n" " scanf(\"%x\", l);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed long'.\n", errout_str()); TEST_SCANF_WARN("%f", "float", "bool"); @@ -2145,13 +2145,13 @@ class TestIO : public TestFixture { check("void foo() {\n" " scanf(\"%f\", \"s3\");\n" " scanf(\"%f\", L\"s5W\");\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %f in format string (no. 1) requires 'float *' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) %f in format string (no. 1) requires 'float *' but the argument type is 'const wchar_t *'.\n", errout_str()); check("void foo(float f) {\n" " scanf(\"%f\", f);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %f in format string (no. 1) requires 'float *' but the argument type is 'float'.\n", errout_str()); TEST_SCANF_WARN("%lf", "double", "bool"); @@ -2241,13 +2241,13 @@ class TestIO : public TestFixture { check("void foo() {\n" " scanf(\"%n\", \"s3\");\n" " scanf(\"%n\", L\"s5W\");\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'const wchar_t *'.\n", errout_str()); check("void foo(long l) {\n" " scanf(\"%n\", l);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'signed long'.\n", errout_str()); check("void g() {\n" // #5104 @@ -2261,7 +2261,7 @@ class TestIO : public TestFixture { " scanf(\"%lf\",&v4[0]);\n" " myvector v5(1);\n" " scanf(\"%10s\",v5[0]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); { @@ -2293,7 +2293,7 @@ class TestIO : public TestFixture { check("void g() {\n" " const char c[]=\"42\";\n" " scanf(\"%s\", c);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %s in format string (no. 1) requires a 'char *' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) scanf() without field width limits can crash with huge input data.\n", errout_str()); } @@ -2303,7 +2303,7 @@ class TestIO : public TestFixture { "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %i in format string (no. 1) requires 'int *' but the argument type is 'const char *'.\n", errout_str()); - check("struct S { unsigned char a[1]; };" // #14302 + check("struct S { unsigned char a[1]; };\n" // #14302 "void f(S s) {\n" " scanf(\"%hhu\", s.a);\n" "}\n"); @@ -2321,7 +2321,7 @@ class TestIO : public TestFixture { " snprintf(str,10,\"%u%s\");\n" " sprintf(string1, \"%-*.*s\", 32, string2);\n" // #3364 " snprintf(a, 9, \"%s%d\", \"11223344\");\n" // #3655 - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (error) printf format string requires 1 parameter but only 0 are given.\n" "[test.cpp:3]: (error) printf format string requires 2 parameters but only 1 is given.\n" "[test.cpp:4]: (error) printf format string requires 3 parameters but only 2 are given.\n" @@ -2336,7 +2336,7 @@ class TestIO : public TestFixture { " printf(\"\", 0);\n" " printf(\"%i\", 123, bar());\n" " printf(\"%i%s\", 0, bar(), 43123);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) printf format string requires 0 parameters but 1 is given.\n" "[test.cpp:3]: (warning) printf format string requires 1 parameter but 2 are given.\n" "[test.cpp:4]: (warning) printf format string requires 2 parameters but 3 are given.\n", errout_str()); @@ -2346,7 +2346,7 @@ class TestIO : public TestFixture { " swprintf(string1, L\"%s%s\", L\"a\", string2);\n" // MSVC implementation " swprintf(string1, 6, L\"%i\", 32, string2);\n" // Standard implementation " swprintf(string1, 6, L\"%i%s\", 32, string2);\n" // Standard implementation - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) swprintf format string requires 1 parameter but 2 are given.\n" "[test.cpp:4]: (warning) swprintf format string requires 1 parameter but 2 are given.\n", errout_str()); @@ -2363,7 +2363,7 @@ class TestIO : public TestFixture { " printf(\"string: %.*s\", len, string);\n" // #3311 " fprintf(stderr, \"%*cText.\", indent, ' ');\n" // #3313 " sprintf(string1, \"%*\", 32);\n" // #3364 - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char* s, const char* s2, std::string s3, int i) {\n" @@ -2373,7 +2373,7 @@ class TestIO : public TestFixture { " printf(\"%s\", s3);\n" " printf(\"%s\", \"s4\");\n" " printf(\"%u\", s);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'signed int'.\n" "[test.cpp:4]: (warning) %s in format string (no. 2) requires 'char *' but the argument type is 'signed int'.\n" "[test.cpp:5]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'std::string'.\n" @@ -2386,7 +2386,7 @@ class TestIO : public TestFixture { " printf(\"%jo\", s3);\n" " printf(\"%jx\", i);\n" " printf(\"%jX\", i);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %jd in format string (no. 1) requires 'intmax_t' but the argument type is 'char *'.\n" "[test.cpp:3]: (warning) %ji in format string (no. 1) requires 'intmax_t' but the argument type is 'char *'.\n" "[test.cpp:4]: (warning) %ju in format string (no. 1) requires 'uintmax_t' but the argument type is 'const char *'.\n" @@ -2400,7 +2400,7 @@ class TestIO : public TestFixture { " printf(\"%jd\", ui);\n" " printf(\"%jd\", s3);\n" " printf(\"%jd\", i);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %ju in format string (no. 1) requires 'uintmax_t' but the argument type is 'unsigned int'.\n" "[test.cpp:4]: (warning) %jd in format string (no. 1) requires 'intmax_t' but the argument type is 'unsigned int'.\n" "[test.cpp:5]: (warning) %jd in format string (no. 1) requires 'intmax_t' but the argument type is 'std::string'.\n" @@ -2413,7 +2413,7 @@ class TestIO : public TestFixture { " printf(\"%n\", pi);\n" " printf(\"%n\", s);\n" " printf(\"%n\", \"s4\");\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'signed int'.\n" "[test.cpp:4]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'signed int'.\n" "[test.cpp:6]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'std::string'.\n" @@ -2421,7 +2421,7 @@ class TestIO : public TestFixture { check("void foo() {\n" " printf(\"%n\", L\"s5W\");\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'const wchar_t *'.\n", errout_str()); check("class foo {};\n" @@ -2434,7 +2434,7 @@ class TestIO : public TestFixture { " printf(\"%X\", bp);\n" " printf(\"%X\", u);\n" " printf(\"%X\", i);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %X in format string (no. 1) requires 'unsigned int' but the argument type is 'foo'.\n" "[test.cpp:4]: (warning) %c in format string (no. 1) requires 'unsigned int' but the argument type is 'const char *'.\n" "[test.cpp:5]: (warning) %o in format string (no. 1) requires 'unsigned int' but the argument type is 'double'.\n" @@ -2445,7 +2445,7 @@ class TestIO : public TestFixture { "void foo(const char* cpc, char* pc) {\n" " printf(\"%x\", cpc);\n" " printf(\"%x\", pc);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %x in format string (no. 1) requires 'unsigned int' but the argument type is 'const char *'.\n" "[test.cpp:4]: (warning) %x in format string (no. 1) requires 'unsigned int' but the argument type is 'char *'.\n", errout_str()); @@ -2455,7 +2455,7 @@ class TestIO : public TestFixture { " printf(\"%X\", L\"s5W\");\n" " printf(\"%c\", L\"s5W\");\n" " printf(\"%o\", L\"s5W\");\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %x in format string (no. 1) requires 'unsigned int' but the argument type is 'const wchar_t *'.\n" "[test.cpp:4]: (warning) %X in format string (no. 1) requires 'unsigned int' but the argument type is 'const wchar_t *'.\n" "[test.cpp:5]: (warning) %c in format string (no. 1) requires 'unsigned int' but the argument type is 'const wchar_t *'.\n" @@ -2471,7 +2471,7 @@ class TestIO : public TestFixture { " printf(\"%i\", b);\n" " printf(\"%i\", bp);\n" " printf(\"%i\", uc);\n" // char is smaller than int, so there shouldn't be a problem - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'foo'.\n" "[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'const char *'.\n" "[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'double'.\n" @@ -2483,7 +2483,7 @@ class TestIO : public TestFixture { "void foo() {\n" " printf(\"%i\", L\"s5W\");\n" " printf(\"%d\", L\"s5W\");\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'const wchar_t *'.\n" "[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'const wchar_t *'.\n", errout_str()); @@ -2497,7 +2497,7 @@ class TestIO : public TestFixture { " printf(\"%u\", b);\n" " printf(\"%u\", bp);\n" " printf(\"%u\", bo);\n" // bool shouldn't have a negative sign - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'foo'.\n" "[test.cpp:4]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'const char *'.\n" "[test.cpp:5]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'double'.\n" @@ -2508,7 +2508,7 @@ class TestIO : public TestFixture { check("class foo {};\n" "void foo(const int* cpi, foo f, bar b, bar* bp, double d, int i, bool bo) {\n" " printf(\"%u\", L\"s5W\");\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'const wchar_t *'.\n", errout_str()); check("class foo {};\n" @@ -2518,7 +2518,7 @@ class TestIO : public TestFixture { " printf(\"%p\", bp);\n" " printf(\"%p\", cpi);\n" " printf(\"%p\", b);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %p in format string (no. 1) requires an address but the argument type is 'foo'.\n" "[test.cpp:4]: (warning) %p in format string (no. 1) requires an address but the argument type is 'char'.\n", errout_str()); @@ -2530,7 +2530,7 @@ class TestIO : public TestFixture { " printf(\"%p\", cpwc);\n" " printf(\"%p\", \"s4\");\n" " printf(\"%p\", L\"s5W\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class foo {};\n" @@ -2542,7 +2542,7 @@ class TestIO : public TestFixture { " printf(\"%f\", d);\n" " printf(\"%f\", b);\n" " printf(\"%f\", (float)cpi);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %e in format string (no. 1) requires 'double' but the argument type is 'foo'.\n" "[test.cpp:4]: (warning) %E in format string (no. 1) requires 'double' but the argument type is 'const char *'.\n" "[test.cpp:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'const signed int *'.\n" @@ -2555,7 +2555,7 @@ class TestIO : public TestFixture { " printf(\"%f\", cpc);\n" " printf(\"%G\", pc);\n" " printf(\"%f\", pc);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %e in format string (no. 1) requires 'double' but the argument type is 'const char *'.\n" "[test.cpp:4]: (warning) %E in format string (no. 1) requires 'double' but the argument type is 'char *'.\n" "[test.cpp:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'const char *'.\n" @@ -2568,7 +2568,7 @@ class TestIO : public TestFixture { " printf(\"%E\", L\"s5W\");\n" " printf(\"%f\", L\"s5W\");\n" " printf(\"%G\", L\"s5W\");\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %e in format string (no. 1) requires 'double' but the argument type is 'const wchar_t *'.\n" "[test.cpp:4]: (warning) %E in format string (no. 1) requires 'double' but the argument type is 'const wchar_t *'.\n" "[test.cpp:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'const wchar_t *'.\n" @@ -2579,7 +2579,7 @@ class TestIO : public TestFixture { " printf(\"%u\", f);\n" " printf(\"%f\", f);\n" " printf(\"%p\", f);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'foo'.\n" "[test.cpp:4]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'foo'.\n" "[test.cpp:5]: (warning) %p in format string (no. 1) requires an address but the argument type is 'foo'.\n", errout_str()); @@ -2589,14 +2589,14 @@ class TestIO : public TestFixture { check("void foo(signed char sc, unsigned char uc, short int si, unsigned short int usi) {\n" " printf(\"%hhx %hhd\", sc, uc);\n" " printf(\"%hd %hu\", si, usi);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %hhx in format string (no. 1) requires 'unsigned char' but the argument type is 'signed char'.\n" "[test.cpp:2]: (warning) %hhd in format string (no. 2) requires 'char' but the argument type is 'unsigned char'.\n", errout_str()); check("void foo(long long int lli, unsigned long long int ulli, long int li, unsigned long int uli) {\n" " printf(\"%llo %llx\", lli, ulli);\n" " printf(\"%ld %lu\", li, uli);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(intmax_t im, uintmax_t uim, size_t s, ptrdiff_t p, long double ld, std::size_t ss, std::ptrdiff_t sp) {\n" @@ -2606,7 +2606,7 @@ class TestIO : public TestFixture { " printf(\"%Lf\", ld);\n" " printf(\"%zx\", ss);\n" " printf(\"%ti\", sp);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Unrecognized (and non-existent in standard library) specifiers. @@ -2618,31 +2618,31 @@ class TestIO : public TestFixture { " printf(\"%La\", ld);\n" " printf(\"%zv\", ss);\n" " printf(\"%tp\", sp);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(long long l, ptrdiff_t p, std::ptrdiff_t sp) {\n" " printf(\"%td\", p);\n" " printf(\"%td\", sp);\n" " printf(\"%td\", l);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4]: (warning) %td in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'signed long long'.\n", errout_str()); check("void foo(int i, long double ld) {\n" " printf(\"%zx %zu\", i, ld);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %zx in format string (no. 1) requires 'size_t' but the argument type is 'signed int'.\n" "[test.cpp:2]: (warning) %zu in format string (no. 2) requires 'size_t' but the argument type is 'long double'.\n", errout_str()); check("void foo(unsigned int ui, long double ld) {\n" " printf(\"%zu %zx\", ui, ld);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %zu in format string (no. 1) requires 'size_t' but the argument type is 'unsigned int'.\n" "[test.cpp:2]: (warning) %zx in format string (no. 2) requires 'size_t' but the argument type is 'long double'.\n", errout_str()); check("void foo(int i, long double ld) {\n" " printf(\"%tx %tu\", i, ld);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %tx in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'signed int'.\n" "[test.cpp:2]: (warning) %tu in format string (no. 2) requires 'unsigned ptrdiff_t' but the argument type is 'long double'.\n", errout_str()); @@ -2657,7 +2657,7 @@ class TestIO : public TestFixture { " printf(\"%t\", i);\n" " printf(\"%L\", i);\n" " printf(\"%I\", i);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) 'h' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\n" "[test.cpp:3]: (warning) 'hh' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\n" "[test.cpp:4]: (warning) 'l' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\n" @@ -2673,7 +2673,7 @@ class TestIO : public TestFixture { " printf(\"%hhd\", i);\n" " printf(\"%ld\", i);\n" " printf(\"%lld\", i);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %hd in format string (no. 1) requires 'short' but the argument type is 'unsigned int'.\n" "[test.cpp:3]: (warning) %hhd in format string (no. 1) requires 'char' but the argument type is 'unsigned int'.\n" "[test.cpp:4]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'unsigned int'.\n" @@ -2682,56 +2682,56 @@ class TestIO : public TestFixture { check("void foo(size_t s, ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n", errout_str()); check("void foo(std::size_t s, std::ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long}'.\n", errout_str()); check("void foo(size_t s, ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n", errout_str()); check("void foo(std::size_t s, std::ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long}'.\n", errout_str()); check("void foo(size_t s, ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n", errout_str()); check("void foo(std::size_t s, std::ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long}'.\n", errout_str()); check("void foo(size_t s, ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long long}'.\n", errout_str()); check("void foo(std::size_t s, std::ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long long}'.\n", errout_str()); @@ -2740,7 +2740,7 @@ class TestIO : public TestFixture { " printf(\"%lu\", um);\n" " printf(\"%llu\", s);\n" " printf(\"%llu\", um);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:2]: (portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'size_t {aka unsigned long long}'.\n" "[test.cpp:3]: (portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'uintmax_t {aka unsigned long long}'.\n" "[test.cpp:4]: (portability) %llu in format string (no. 1) requires 'unsigned long long' but the argument type is 'size_t {aka unsigned long long}'.\n" @@ -2753,7 +2753,7 @@ class TestIO : public TestFixture { " printf(\"%llu\", i);\n" " printf(\"%lx\", i);\n" " printf(\"%llx\", i);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'unsigned int'.\n" "[test.cpp:3]: (warning) %lld in format string (no. 1) requires 'long long' but the argument type is 'unsigned int'.\n" "[test.cpp:4]: (warning) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'unsigned int'.\n" @@ -2765,13 +2765,13 @@ class TestIO : public TestFixture { " printf(\"%lld\", i);\n" " printf(\"%lld\", im);\n" " printf(\"%lld\", p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %lld in format string (no. 1) requires 'long long' but the argument type is 'signed int'.\n", errout_str()); check("void foo(intmax_t im, ptrdiff_t p) {\n" " printf(\"%lld\", im);\n" " printf(\"%lld\", p);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:2]: (portability) %lld in format string (no. 1) requires 'long long' but the argument type is 'intmax_t {aka signed long long}'.\n" "[test.cpp:3]: (portability) %lld in format string (no. 1) requires 'long long' but the argument type is 'ptrdiff_t {aka signed long long}'.\n", errout_str()); @@ -2790,7 +2790,7 @@ class TestIO : public TestFixture { " printf(\"%d %f %f %d %f %f\",\n" " foo->d, foo->bar[0].i, a[0],\n" " f[0].d, f[0].baz.i, f[0].bar[0].i);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:13]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'double'.\n" "[test.cpp:13]: (warning) %f in format string (no. 2) requires 'double' but the argument type is 'signed int'.\n" "[test.cpp:13]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'int'.\n" @@ -2799,7 +2799,7 @@ class TestIO : public TestFixture { "[test.cpp:13]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'int'.\n", errout_str()); check("short f() { return 0; }\n" - "void foo() { printf(\"%d %u %lu %I64u %I64d %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }"); + "void foo() { printf(\"%d %u %lu %I64u %I64d %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed short'.\n" "[test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed short'.\n" "[test.cpp:2]: (warning) %I64u in format string (no. 4) requires 'unsigned __int64' but the argument type is 'signed short'.\n" @@ -2809,7 +2809,7 @@ class TestIO : public TestFixture { "[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'signed short'.\n", errout_str()); check("unsigned short f() { return 0; }\n" - "void foo() { printf(\"%u %d %ld %I64d %I64u %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }"); + "void foo() { printf(\"%u %d %ld %I64d %I64u %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned short'.\n" "[test.cpp:2]: (warning) %I64d in format string (no. 4) requires '__int64' but the argument type is 'unsigned short'.\n" "[test.cpp:2]: (warning) %I64u in format string (no. 5) requires 'unsigned __int64' but the argument type is 'unsigned short'.\n" @@ -2818,7 +2818,7 @@ class TestIO : public TestFixture { "[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'unsigned short'.\n", errout_str()); check("int f() { return 0; }\n" - "void foo() { printf(\"%d %u %lu %I64u %I64d %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }"); + "void foo() { printf(\"%d %u %lu %I64u %I64d %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\n" "[test.cpp:2]: (warning) %I64u in format string (no. 4) requires 'unsigned __int64' but the argument type is 'signed int'.\n" @@ -2828,7 +2828,7 @@ class TestIO : public TestFixture { "[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'signed int'.\n", errout_str()); check("unsigned int f() { return 0; }\n" - "void foo() { printf(\"%u %d %ld %I64d %I64u %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }"); + "void foo() { printf(\"%u %d %ld %I64d %I64u %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned int'.\n" "[test.cpp:2]: (warning) %I64d in format string (no. 4) requires '__int64' but the argument type is 'unsigned int'.\n" @@ -2838,7 +2838,7 @@ class TestIO : public TestFixture { "[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'unsigned int'.\n", errout_str()); check("long f() { return 0; }\n" - "void foo() { printf(\"%ld %u %lu %I64u %I64d %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }"); + "void foo() { printf(\"%ld %u %lu %I64u %I64d %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed long'.\n" "[test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed long'.\n" "[test.cpp:2]: (warning) %I64u in format string (no. 4) requires 'unsigned __int64' but the argument type is 'signed long'.\n" @@ -2848,7 +2848,7 @@ class TestIO : public TestFixture { "[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'signed long'.\n", errout_str()); check("unsigned long f() { return 0; }\n" - "void foo() { printf(\"%lu %d %ld %I64d %I64u %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }"); + "void foo() { printf(\"%lu %d %ld %I64d %I64u %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned long'.\n" "[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned long'.\n" "[test.cpp:2]: (warning) %I64d in format string (no. 4) requires '__int64' but the argument type is 'unsigned long'.\n" @@ -2858,7 +2858,7 @@ class TestIO : public TestFixture { "[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'unsigned long'.\n", errout_str()); check("long long f() { return 0; }\n" - "void foo() { printf(\"%lld %u %lu %I64u %I64d %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }"); + "void foo() { printf(\"%lld %u %lu %I64u %I64d %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed long long'.\n" "[test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed long long'.\n" "[test.cpp:2]: (warning) %I64u in format string (no. 4) requires 'unsigned __int64' but the argument type is 'signed long long'.\n" @@ -2867,7 +2867,7 @@ class TestIO : public TestFixture { "[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'signed long long'.\n", errout_str()); check("unsigned long long f() { return 0; }\n" - "void foo() { printf(\"%llu %d %ld %I64d %I64u %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }"); + "void foo() { printf(\"%llu %d %ld %I64d %I64u %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned long long'.\n" "[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned long long'.\n" "[test.cpp:2]: (warning) %I64d in format string (no. 4) requires '__int64' but the argument type is 'unsigned long long'.\n" @@ -2876,7 +2876,7 @@ class TestIO : public TestFixture { "[test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'unsigned long long'.\n", errout_str()); check("float f() { return 0; }\n" - "void foo() { printf(\"%f %d %ld %u %lu %I64d %I64u %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f(), f()); }"); + "void foo() { printf(\"%f %d %ld %u %lu %I64d %I64u %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'float'.\n" "[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'float'.\n" "[test.cpp:2]: (warning) %u in format string (no. 4) requires 'unsigned int' but the argument type is 'float'.\n" @@ -2887,7 +2887,7 @@ class TestIO : public TestFixture { "[test.cpp:2]: (warning) %p in format string (no. 9) requires an address but the argument type is 'float'.\n", errout_str()); check("double f() { return 0; }\n" - "void foo() { printf(\"%f %d %ld %u %lu %I64d %I64u %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f(), f()); }"); + "void foo() { printf(\"%f %d %ld %u %lu %I64d %I64u %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'double'.\n" "[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'double'.\n" "[test.cpp:2]: (warning) %u in format string (no. 4) requires 'unsigned int' but the argument type is 'double'.\n" @@ -2898,7 +2898,7 @@ class TestIO : public TestFixture { "[test.cpp:2]: (warning) %p in format string (no. 9) requires an address but the argument type is 'double'.\n", errout_str()); check("long double f() { return 0; }\n" - "void foo() { printf(\"%Lf %d %ld %u %lu %I64d %I64u %f %p\", f(), f(), f(), f(), f(), f(), f(), f(), f()); }"); + "void foo() { printf(\"%Lf %d %ld %u %lu %I64d %I64u %f %p\", f(), f(), f(), f(), f(), f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'long double'.\n" "[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'long double'.\n" "[test.cpp:2]: (warning) %u in format string (no. 4) requires 'unsigned int' but the argument type is 'long double'.\n" @@ -2909,37 +2909,37 @@ class TestIO : public TestFixture { "[test.cpp:2]: (warning) %p in format string (no. 9) requires an address but the argument type is 'long double'.\n", errout_str()); check("int f() { return 0; }\n" - "void foo() { printf(\"%I64d %I64u %I64x %d\", f(), f(), f(), f()); }"); + "void foo() { printf(\"%I64d %I64u %I64x %d\", f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %I64d in format string (no. 1) requires '__int64' but the argument type is 'signed int'.\n" "[test.cpp:2]: (warning) %I64u in format string (no. 2) requires 'unsigned __int64' but the argument type is 'signed int'.\n" "[test.cpp:2]: (warning) %I64x in format string (no. 3) requires 'unsigned __int64' but the argument type is 'signed int'.\n", errout_str()); check("long long f() { return 0; }\n" - "void foo() { printf(\"%I32d %I32u %I32x %lld\", f(), f(), f(), f()); }"); + "void foo() { printf(\"%I32d %I32u %I32x %lld\", f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %I32d in format string (no. 1) requires '__int32' but the argument type is 'signed long long'.\n" "[test.cpp:2]: (warning) %I32u in format string (no. 2) requires 'unsigned __int32' but the argument type is 'signed long long'.\n" "[test.cpp:2]: (warning) %I32x in format string (no. 3) requires 'unsigned __int32' but the argument type is 'signed long long'.\n", errout_str()); check("unsigned long long f() { return 0; }\n" - "void foo() { printf(\"%I32d %I32u %I32x %llx\", f(), f(), f(), f()); }"); + "void foo() { printf(\"%I32d %I32u %I32x %llx\", f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned long long'.\n" "[test.cpp:2]: (warning) %I32u in format string (no. 2) requires 'unsigned __int32' but the argument type is 'unsigned long long'.\n" "[test.cpp:2]: (warning) %I32x in format string (no. 3) requires 'unsigned __int32' but the argument type is 'unsigned long long'.\n", errout_str()); check("signed char f() { return 0; }\n" - "void foo() { printf(\"%Id %Iu %Ix %hhi\", f(), f(), f(), f()); }"); + "void foo() { printf(\"%Id %Iu %Ix %hhi\", f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'signed char'.\n" "[test.cpp:2]: (warning) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'signed char'.\n" "[test.cpp:2]: (warning) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'signed char'.\n", errout_str()); check("unsigned char f() { return 0; }\n" - "void foo() { printf(\"%Id %Iu %Ix %hho\", f(), f(), f(), f()); }"); + "void foo() { printf(\"%Id %Iu %Ix %hho\", f(), f(), f(), f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'unsigned char'.\n" "[test.cpp:2]: (warning) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'unsigned char'.\n" "[test.cpp:2]: (warning) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'unsigned char'.\n", errout_str()); check("namespace bar { int f() { return 0; } }\n" - "void foo() { printf(\"%d %u %lu %f %Lf %p\", bar::f(), bar::f(), bar::f(), bar::f(), bar::f(), bar::f()); }"); + "void foo() { printf(\"%d %u %lu %f %Lf %p\", bar::f(), bar::f(), bar::f(), bar::f(), bar::f(), bar::f()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\n" "[test.cpp:2]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\n" @@ -2947,7 +2947,7 @@ class TestIO : public TestFixture { "[test.cpp:2]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'.\n", errout_str()); check("struct Fred { int i; } f;\n" - "void foo() { printf(\"%d %u %lu %f %Lf %p\", f.i, f.i, f.i, f.i, f.i, f.i); }"); + "void foo() { printf(\"%d %u %lu %f %Lf %p\", f.i, f.i, f.i, f.i, f.i, f.i); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\n" "[test.cpp:2]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\n" @@ -2955,7 +2955,7 @@ class TestIO : public TestFixture { "[test.cpp:2]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'.\n", errout_str()); check("struct Fred { unsigned int u; } f;\n" - "void foo() { printf(\"%u %d %ld %f %Lf %p\", f.u, f.u, f.u, f.u, f.u, f.u); }"); + "void foo() { printf(\"%u %d %ld %f %Lf %p\", f.u, f.u, f.u, f.u, f.u, f.u); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned int'.\n" "[test.cpp:2]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'unsigned int'.\n" @@ -2963,7 +2963,7 @@ class TestIO : public TestFixture { "[test.cpp:2]: (warning) %p in format string (no. 6) requires an address but the argument type is 'unsigned int'.\n", errout_str()); check("struct Fred { unsigned int ui() { return 0; } } f;\n" - "void foo() { printf(\"%u %d %ld %f %Lf %p\", f.ui(), f.ui(), f.ui(), f.ui(), f.ui(), f.ui()); }"); + "void foo() { printf(\"%u %d %ld %f %Lf %p\", f.ui(), f.ui(), f.ui(), f.ui(), f.ui(), f.ui()); }\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned int'.\n" "[test.cpp:2]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'unsigned int'.\n" @@ -2974,12 +2974,12 @@ class TestIO : public TestFixture { check("void f(int len, int newline) {\n" " printf(\"%s\", newline ? a : str + len);\n" " printf(\"%s\", newline + newline);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'signed int'.\n", errout_str()); check("struct Fred { int i; } f;\n" "struct Fred & bar() { };\n" - "void foo() { printf(\"%d %u %lu %f %Lf %p\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }"); + "void foo() { printf(\"%d %u %lu %f %Lf %p\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\n" @@ -2988,7 +2988,7 @@ class TestIO : public TestFixture { check("struct Fred { int i; } f;\n" "const struct Fred & bar() { };\n" - "void foo() { printf(\"%d %u %lu %f %Lf %p\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }"); + "void foo() { printf(\"%d %u %lu %f %Lf %p\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\n" @@ -2997,7 +2997,7 @@ class TestIO : public TestFixture { check("struct Fred { int i; } f;\n" "static const struct Fred & bar() { };\n" - "void foo() { printf(\"%d %u %lu %f %Lf %p\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }"); + "void foo() { printf(\"%d %u %lu %f %Lf %p\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\n" @@ -3006,7 +3006,7 @@ class TestIO : public TestFixture { check("struct Fred { int i; } f[2];\n" "struct Fred * bar() { return f; };\n" - "void foo() { printf(\"%d %u %lu %f %Lf %p\", bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i); }"); + "void foo() { printf(\"%d %u %lu %f %Lf %p\", bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i); }\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\n" @@ -3015,7 +3015,7 @@ class TestIO : public TestFixture { check("struct Fred { int i; } f[2];\n" "const struct Fred * bar() { return f; };\n" - "void foo() { printf(\"%d %u %lu %f %Lf %p\", bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i); }"); + "void foo() { printf(\"%d %u %lu %f %Lf %p\", bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i); }\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\n" @@ -3024,7 +3024,7 @@ class TestIO : public TestFixture { check("struct Fred { int i; } f[2];\n" "static const struct Fred * bar() { return f; };\n" - "void foo() { printf(\"%d %u %lu %f %Lf %p\", bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i); }"); + "void foo() { printf(\"%d %u %lu %f %Lf %p\", bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i); }\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\n" @@ -3033,7 +3033,7 @@ class TestIO : public TestFixture { check("struct Fred { int32_t i; } f;\n" "struct Fred & bar() { };\n" - "void foo() { printf(\"%d %ld %u %lu %f %Lf\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }"); + "void foo() { printf(\"%d %ld %u %lu %f %Lf\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %ld in format string (no. 2) requires 'long' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %lu in format string (no. 4) requires 'unsigned long' but the argument type is 'signed int'.\n" @@ -3044,27 +3044,27 @@ class TestIO : public TestFixture { // #4984 check("void f(double *x) {\n" " printf(\"%f\", x[0]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int array[10];\n" "int * foo() { return array; }\n" "void f() {\n" " printf(\"%f\", foo()[0]);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\n", errout_str()); check("struct Base { int length() { } };\n" "struct Derived : public Base { };\n" "void foo(Derived * d) {\n" " printf(\"%f\", d.length());\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\n", errout_str()); check("std::vector v;\n" "void foo() {\n" " printf(\"%d %u %f\", v[0], v[0], v[0]);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'signed int'.\n", errout_str()); @@ -3072,7 +3072,7 @@ class TestIO : public TestFixture { check("int bar(int a);\n" "void foo() {\n" " printf(\"%d\", bar(0));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::vector v;\n" @@ -3318,20 +3318,20 @@ class TestIO : public TestFixture { check("void foo() {\n" " printf(\"%f %d\", static_cast(1.0f), reinterpret_cast(0));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\n" "[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const void *'.\n", errout_str()); check("void foo() {\n" " UNKNOWN * u;\n" " printf(\"%d %x %u %f\", u[i], u[i], u[i], u[i]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " long * l;\n" " printf(\"%d %x %u %f\", l[i], l[i], l[i], l[i]);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'signed long'.\n" "[test.cpp:3]: (warning) %x in format string (no. 2) requires 'unsigned int' but the argument type is 'signed long'.\n" "[test.cpp:3]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed long'.\n" @@ -3352,27 +3352,27 @@ class TestIO : public TestFixture { " printf(\"%u\",v6[0]);\n" " myvector v7(1,0);\n" " printf(\"%s\",v7[0]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::vector v;\n" // #5151 "void foo() {\n" " printf(\"%c %u %f\", v.at(32), v.at(32), v.at(32));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'char'.\n" "[test.cpp:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'char'.\n", errout_str()); // #5195 (segmentation fault) check("void T::a(const std::vector& vx) {\n" " printf(\"%f\", vx.at(0));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #5486 check("void foo() {\n" " ssize_t test = 0;\n" " printf(\"%zd\", test);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #6009 @@ -3380,7 +3380,7 @@ class TestIO : public TestFixture { "extern int IntByReturnValue();\n" "void MyFunction() {\n" " printf( \"%s - %s\", StringByReturnValue(), IntByReturnValue() );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'std::string'.\n" "[test.cpp:4]: (warning) %s in format string (no. 2) requires 'char *' but the argument type is 'signed int'.\n", errout_str()); @@ -3393,7 +3393,7 @@ class TestIO : public TestFixture { " Array array1;\n" " Array array2;\n" " printf(\"%u %u\", array1[0], array2[0]);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'int'.\n" "[test.cpp:9]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'float'.\n", errout_str()); @@ -3401,19 +3401,19 @@ class TestIO : public TestFixture { check("struct S { unsigned short x; } s = {0};\n" "void foo() {\n" " printf(\"%d\", s.x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Ticket #7601 check("void foo(int i, unsigned int ui, long long ll, unsigned long long ull) {\n" " printf(\"%Ld %Lu %Ld %Lu\", i, ui, ll, ull);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %Ld in format string (no. 1) requires 'long long' but the argument type is 'signed int'.\n" "[test.cpp:2]: (warning) %Lu in format string (no. 2) requires 'unsigned long long' but the argument type is 'unsigned int'.\n", errout_str()); check("void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) {\n" " printf(\"%hhd %hhd %hhd %hhd %hhd %hhd %hhd %hhd\", c, uc, s, us, i, ui, l, ul);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %hhd in format string (no. 2) requires 'char' but the argument type is 'unsigned char'.\n" "[test.cpp:2]: (warning) %hhd in format string (no. 3) requires 'char' but the argument type is 'signed short'.\n" "[test.cpp:2]: (warning) %hhd in format string (no. 4) requires 'char' but the argument type is 'unsigned short'.\n" @@ -3424,7 +3424,7 @@ class TestIO : public TestFixture { check("void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) {\n" " printf(\"%hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu\", c, uc, s, us, i, ui, l, ul);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %hhu in format string (no. 1) requires 'unsigned char' but the argument type is 'char'.\n" "[test.cpp:2]: (warning) %hhu in format string (no. 3) requires 'unsigned char' but the argument type is 'signed short'.\n" "[test.cpp:2]: (warning) %hhu in format string (no. 4) requires 'unsigned char' but the argument type is 'unsigned short'.\n" @@ -3435,7 +3435,7 @@ class TestIO : public TestFixture { check("void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) {\n" " printf(\"%hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx\", c, uc, s, us, i, ui, l, ul);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %hhx in format string (no. 1) requires 'unsigned char' but the argument type is 'char'.\n" "[test.cpp:2]: (warning) %hhx in format string (no. 3) requires 'unsigned char' but the argument type is 'signed short'.\n" "[test.cpp:2]: (warning) %hhx in format string (no. 4) requires 'unsigned char' but the argument type is 'unsigned short'.\n" @@ -3446,7 +3446,7 @@ class TestIO : public TestFixture { check("void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) {\n" " printf(\"%hd %hd %hd %hd %hd %hd %hd %hd\", c, uc, s, us, i, ui, l, ul);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %hd in format string (no. 1) requires 'short' but the argument type is 'char'.\n" "[test.cpp:2]: (warning) %hd in format string (no. 2) requires 'short' but the argument type is 'unsigned char'.\n" "[test.cpp:2]: (warning) %hd in format string (no. 4) requires 'short' but the argument type is 'unsigned short'.\n" @@ -3457,7 +3457,7 @@ class TestIO : public TestFixture { check("void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) {\n" " printf(\"%hu %hu %hu %hu %hu %hu %hu %hu\", c, uc, s, us, i, ui, l, ul);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %hu in format string (no. 1) requires 'unsigned short' but the argument type is 'char'.\n" "[test.cpp:2]: (warning) %hu in format string (no. 2) requires 'unsigned short' but the argument type is 'unsigned char'.\n" "[test.cpp:2]: (warning) %hu in format string (no. 3) requires 'unsigned short' but the argument type is 'signed short'.\n" @@ -3468,7 +3468,7 @@ class TestIO : public TestFixture { check("void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) {\n" " printf(\"%hx %hx %hx %hx %hx %hx %hx %hx\", c, uc, s, us, i, ui, l, ul);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2]: (warning) %hx in format string (no. 1) requires 'unsigned short' but the argument type is 'char'.\n" "[test.cpp:2]: (warning) %hx in format string (no. 2) requires 'unsigned short' but the argument type is 'unsigned char'.\n" "[test.cpp:2]: (warning) %hx in format string (no. 3) requires 'unsigned short' but the argument type is 'signed short'.\n" @@ -3484,19 +3484,19 @@ class TestIO : public TestFixture { "\n" "void foo(struct S x) {\n" " printf(\"%f\", x.f(4.0));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("enum E : uint8_t { E0 }; \n" // #7959 "void f(E e) {\n" " printf(\"%hhu\", e);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("enum E : uint8_t { E0 }; \n" "void f(E e) {\n" " printf(\"%lu\", e);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'uint8_t'.\n", "", errout_str()); @@ -4259,7 +4259,7 @@ class TestIO : public TestFixture { " printf(\"%1$d\", 1);" " printf(\"%1$d, %d, %1$d\", 1, 2);" " scanf(\"%1$d\", &bar);" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -4268,7 +4268,7 @@ class TestIO : public TestFixture { " printf(\"%1$d, %d, %4$d\", 1, 2, 3);\n" " scanf(\"%2$d\", &bar);\n" " printf(\"%0$f\", 0.0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:3]: (error) printf format string requires 1 parameter but only 0 are given. [wrongPrintfScanfArgNum]\n" "[test.cpp:4:3]: (warning) printf: referencing parameter 4 while 3 arguments given [wrongPrintfScanfParameterPositionError]\n" "[test.cpp:5:3]: (warning) scanf: referencing parameter 2 while 1 arguments given [wrongPrintfScanfParameterPositionError]\n" @@ -4291,7 +4291,7 @@ class TestIO : public TestFixture { " printf(\"%I32d %I32u %I32x\", u32, u32, u32);\n" " printf(\"%I64d %I64u %I64x\", i64, i64, i64);\n" " printf(\"%I64d %I64u %I64x\", u64, u64, u64);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:8:5]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'size_t {aka unsigned long}'. [invalidPrintfArgType_sint]\n" "[test.cpp:9:5]: (portability) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long}'. [invalidPrintfArgType_uint]\n" "[test.cpp:9:5]: (portability) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long}'. [invalidPrintfArgType_uint]\n" @@ -4313,7 +4313,7 @@ class TestIO : public TestFixture { " printf(\"%I32d %I32u %I32x\", u32, u32, u32);\n" " printf(\"%I64d %I64u %I64x\", i64, i64, i64);\n" " printf(\"%I64d %I64u %I64x\", u64, u64, u64);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:8:5]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'size_t {aka unsigned long long}'. [invalidPrintfArgType_sint]\n" "[test.cpp:9:5]: (portability) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long long}'. [invalidPrintfArgType_uint]\n" "[test.cpp:9:5]: (portability) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long long}'. [invalidPrintfArgType_uint]\n" @@ -4339,7 +4339,7 @@ class TestIO : public TestFixture { " printf(\"%I16x%i\", s, i);\n" " printf(\"%I32%i\", s, i);\n" " printf(\"%I64%i\", s, i);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\n" "[test.cpp:5:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\n" "[test.cpp:6:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\n" @@ -4384,7 +4384,7 @@ class TestIO : public TestFixture { " printf(\"%zd\", s);\n" " printf(\"%zd%i\", s, i);\n" " printf(\"%zu\", s);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:6:5]: (portability) %zu in format string (no. 1) requires 'size_t' but the argument type is 'SSIZE_T {aka signed long}'. [invalidPrintfArgType_uint]\n", errout_str()); check("void foo() {\n" @@ -4393,7 +4393,7 @@ class TestIO : public TestFixture { " printf(\"%zd\", s);\n" " printf(\"%zd%i\", s, i);\n" " printf(\"%zu\", s);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:6:5]: (portability) %zu in format string (no. 1) requires 'size_t' but the argument type is 'SSIZE_T {aka signed long long}'. [invalidPrintfArgType_uint]\n", errout_str()); check("void foo() {\n" @@ -4402,7 +4402,7 @@ class TestIO : public TestFixture { " printf(\"%zd\", s);\n" " printf(\"%zd%i\", s, i);\n" " printf(\"%zu\", s);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -4412,7 +4412,7 @@ class TestIO : public TestFixture { " printf(\"%zd\", s);\n" " printf(\"%zd%i\", s, i);\n" " printf(\"%zu\", s);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:7:5]: (portability) %zu in format string (no. 1) requires 'size_t' but the argument type is 'SSIZE_T {aka signed long long}'. [invalidPrintfArgType_uint]\n", errout_str()); } @@ -4431,7 +4431,7 @@ class TestIO : public TestFixture { " scanf(\"%I32d %I32u %I32x\", &u32, &u32, &u32);\n" " scanf(\"%I64d %I64u %I64x\", &i64, &i64, &i64);\n" " scanf(\"%I64d %I64u %I64x\", &u64, &u64, &u64);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:8:5]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t *' but the argument type is 'size_t * {aka unsigned long *}'. [invalidScanfArgType_int]\n" "[test.cpp:9:5]: (portability) %Iu in format string (no. 2) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long *}'. [invalidScanfArgType_int]\n" "[test.cpp:9:5]: (portability) %Ix in format string (no. 3) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long *}'. [invalidScanfArgType_int]\n" @@ -4455,7 +4455,7 @@ class TestIO : public TestFixture { " scanf(\"%I32d %I32u %I32x\", &u32, &u32, &u32);\n" " scanf(\"%I64d %I64u %I64x\", &i64, &i64, &i64);\n" " scanf(\"%I64d %I64u %I64x\", &u64, &u64, &u64);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:8:5]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t *' but the argument type is 'size_t * {aka unsigned long long *}'. [invalidScanfArgType_int]\n" "[test.cpp:9:5]: (portability) %Iu in format string (no. 2) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long long *}'. [invalidScanfArgType_int]\n" "[test.cpp:9:5]: (portability) %Ix in format string (no. 3) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long long *}'. [invalidScanfArgType_int]\n" @@ -4483,7 +4483,7 @@ class TestIO : public TestFixture { " scanf(\"%I16x%i\", &s, &i);\n" " scanf(\"%I32%i\", &s, &i);\n" " scanf(\"%I64%i\", &s, &i);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\n" "[test.cpp:5:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\n" "[test.cpp:6:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. [invalidLengthModifierError]\n" @@ -4505,7 +4505,7 @@ class TestIO : public TestFixture { " scanf(\"%zd\", &s);\n" " scanf(\"%zd%i\", &s, &i);\n" " scanf(\"%zu\", &s);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:6:5]: (portability) %zu in format string (no. 1) requires 'size_t *' but the argument type is 'SSIZE_T * {aka signed long *}'. [invalidScanfArgType_int]\n", errout_str()); check("void foo() {\n" @@ -4514,7 +4514,7 @@ class TestIO : public TestFixture { " scanf(\"%zd\", &s);\n" " scanf(\"%zd%i\", &s, &i);\n" " scanf(\"%zu\", &s);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:6:5]: (portability) %zu in format string (no. 1) requires 'size_t *' but the argument type is 'SSIZE_T * {aka signed long long *}'. [invalidScanfArgType_int]\n", errout_str()); check("void foo() {\n" @@ -4523,7 +4523,7 @@ class TestIO : public TestFixture { " scanf(\"%zd\", &s);\n" " scanf(\"%zd%i\", &s, &i);\n" " scanf(\"%zu\", &s);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -4533,7 +4533,7 @@ class TestIO : public TestFixture { " scanf(\"%zd\", &s);\n" " scanf(\"%zd%i\", &s, &i);\n" " scanf(\"%zu\", &s);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:7:5]: (portability) %zu in format string (no. 1) requires 'size_t *' but the argument type is 'SSIZE_T * {aka signed long long *}'. [invalidScanfArgType_int]\n", errout_str()); } @@ -4544,7 +4544,7 @@ class TestIO : public TestFixture { " String string;\n" " string.Format(\"%I32d\", u32);\n" " string.AppendFormat(\"%I32d\", u32);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -4552,7 +4552,7 @@ class TestIO : public TestFixture { " CString string;\n" " string.Format(\"%I32d\", u32);\n" " string.AppendFormat(\"%I32d\", u32);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32)); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -4561,7 +4561,7 @@ class TestIO : public TestFixture { " string.Format(\"%I32d\", u32);\n" " string.AppendFormat(\"%I32d\", u32);\n" " CString::Format(\"%I32d\", u32);\n" - "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:4:12]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'. [invalidPrintfArgType_sint]\n" "[test.cpp:5:12]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'. [invalidPrintfArgType_sint]\n" "[test.cpp:6:14]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'. [invalidPrintfArgType_sint]\n", errout_str()); @@ -4943,20 +4943,20 @@ class TestIO : public TestFixture { check("void foo(float f) {\n" " QString string;\n" " string.sprintf(\"%d\", f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:3:12]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'float'. [invalidPrintfArgType_sint]\n", errout_str()); check("void foo(float f) {\n" " QString string;\n" " string = QString::asprintf(\"%d\", f);\n" - "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:3:23]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'float'. [invalidPrintfArgType_sint]\n", errout_str()); } void testTernary() { // ticket #6182 check("void test(const std::string &val) {\n" " printf(\"%s\", val.empty() ? \"I like to eat bananas\" : val.c_str());\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -4964,30 +4964,30 @@ class TestIO : public TestFixture { check("void test() {\n" " unsigned const x = 5;\n" " printf(\"%u\", x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void testAstType() { // ticket #7014 check("void test() {\n" " printf(\"%c\", \"hello\"[0]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void test() {\n" " printf(\"%lld\", (long long)1);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void test() {\n" " printf(\"%i\", (short *)x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'signed short *'. [invalidPrintfArgType_sint]\n", errout_str()); check("int (*fp)();\n" // #7178 - function pointer call "void test() {\n" " printf(\"%i\", fp());\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -4995,7 +4995,7 @@ class TestIO : public TestFixture { check("void foo() {\n" " printf(\"%u %lu %llu\", 0U, 0UL, 0ULL);\n" " printf(\"%u %lu %llu\", 0u, 0ul, 0ull);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -5003,7 +5003,7 @@ class TestIO : public TestFixture { check("void f() {\n" " const char *s = \"0\";\n" " printf(\"%ld%lld\", atol(s), atoll(s));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // 8141 @@ -5022,7 +5022,7 @@ class TestIO : public TestFixture { "PCINT pci;" "void foo() {\n" " printf(\"%d %p %p\", i, pi, pci);\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("using INT = int;\n\n" @@ -5033,7 +5033,7 @@ class TestIO : public TestFixture { "PCINT pci;" "void foo() {\n" " printf(\"%f %f %f\", i, pi, pci);\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:8:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'. [invalidPrintfArgType_float]\n" "[test.cpp:8:5]: (warning) %f in format string (no. 2) requires 'double' but the argument type is 'signed int *'. [invalidPrintfArgType_float]\n" "[test.cpp:8:5]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'const signed int *'. [invalidPrintfArgType_float]\n", errout_str()); @@ -5051,17 +5051,17 @@ class TestIO : public TestFixture { void testPrintfParenthesis() { // #8489 check("void f(int a) {\n" " printf(\"%f\", (a >> 24) & 0xff);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'. [invalidPrintfArgType_float]\n", errout_str()); check("void f(int a) {\n" " printf(\"%f\", 0xff & (a >> 24));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'. [invalidPrintfArgType_float]\n", errout_str()); check("void f(int a) {\n" " printf(\"%f\", ((a >> 24) + 1) & 0xff);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'. [invalidPrintfArgType_float]\n", errout_str()); } @@ -5069,7 +5069,7 @@ class TestIO : public TestFixture { check("void foo(const std::vector& IO, const int* pio) {\n" "const auto Idx = std::distance(&IO.front(), pio);\n" "printf(\"Idx = %td\", Idx);\n" - "}", dinit(CheckOptions, $.portability = true)); + "}\n", dinit(CheckOptions, $.portability = true)); ASSERT_EQUALS("", errout_str()); } diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 6b6397851fb..cb5f9d53c8a 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -245,7 +245,7 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(10);\n" " p = NULL;\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:5]: (error) Memory leak: p [memleak]\n", errout_str()); } @@ -254,7 +254,7 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(10);\n" " char *q = p;\n" " free(q);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -263,7 +263,7 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(10);\n" " char *q = p + 1;\n" " free(q - 1);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -272,7 +272,7 @@ class TestLeakAutoVar : public TestFixture { " char *a = malloc(10);\n" " a += 10;\n" " free(a - 10);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -281,7 +281,7 @@ class TestLeakAutoVar : public TestFixture { "{\n" " char *p = new char[100];\n" " list += p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -290,7 +290,7 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(10);\n" " p = strcpy(p,q);\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -298,7 +298,7 @@ class TestLeakAutoVar : public TestFixture { check("void foo(struct str *d) {\n" " struct str *p = malloc(10);\n" " d->p = p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -306,7 +306,7 @@ class TestLeakAutoVar : public TestFixture { check("void foo(struct str *d) {\n" " struct str *p = malloc(10);\n" " d->p = &p->x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -315,7 +315,7 @@ class TestLeakAutoVar : public TestFixture { " char *p = x();\n" " free(p);\n" " p = NULL;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -325,7 +325,7 @@ class TestLeakAutoVar : public TestFixture { " if (x) { p = malloc(10); }\n" " if (!x) { p = NULL; }\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -333,7 +333,7 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " char *p = malloc(10);\n" " x = a(b(p));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:4:1]: (information) --check-library: Function b() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); } @@ -343,7 +343,7 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " bar(&p);\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -353,22 +353,22 @@ class TestLeakAutoVar : public TestFixture { " char * &ref = p;\n" " p = malloc(10);\n" " free(ref);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); TODO_ASSERT_EQUALS("", "[test.cpp:6:1]: (error) Memory leak: p [memleak]\n", errout_str()); } void assign14() { check("void f(int x) {\n" " char *p;\n" - " if (x && (p = malloc(10))) { }" - "}"); - ASSERT_EQUALS("[test.c:3:35]: (error) Memory leak: p [memleak]\n", errout_str()); + " if (x && (p = malloc(10))) { }\n" + "}\n"); + ASSERT_EQUALS("[test.c:4:1]: (error) Memory leak: p [memleak]\n", errout_str()); check("void f(int x) {\n" " char *p;\n" - " if (x && (p = new char[10])) { }" - "}", dinit(CheckOptions, $.cpp = true)); - ASSERT_EQUALS("[test.cpp:3:37]: (error) Memory leak: p [memleak]\n", errout_str()); + " if (x && (p = new char[10])) { }\n" + "}\n", dinit(CheckOptions, $.cpp = true)); + ASSERT_EQUALS("[test.cpp:4:1]: (error) Memory leak: p [memleak]\n", errout_str()); } void assign15() { @@ -379,7 +379,7 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " p = malloc(sizeof *p);\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -388,48 +388,48 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(10);\n" " free(p);\n" " if (p=dostuff()) *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void assign17() { // #9047 check("void f() {\n" " char *p = (char*)malloc(10);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:1]: (error) Memory leak: p [memleak]\n", errout_str()); check("void f() {\n" " char *p = (char*)(int*)malloc(10);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:1]: (error) Memory leak: p [memleak]\n", errout_str()); } void assign18() { check("void f(int x) {\n" " char *p;\n" - " if (x && (p = (char*)malloc(10))) { }" - "}"); - ASSERT_EQUALS("[test.c:3:42]: (error) Memory leak: p [memleak]\n", errout_str()); + " if (x && (p = (char*)malloc(10))) { }\n" + "}\n"); + ASSERT_EQUALS("[test.c:4:1]: (error) Memory leak: p [memleak]\n", errout_str()); check("void f(int x) {\n" " char *p;\n" - " if (x && (p = (char*)(int*)malloc(10))) { }" - "}"); - ASSERT_EQUALS("[test.c:3:48]: (error) Memory leak: p [memleak]\n", errout_str()); + " if (x && (p = (char*)(int*)malloc(10))) { }\n" + "}\n"); + ASSERT_EQUALS("[test.c:4:1]: (error) Memory leak: p [memleak]\n", errout_str()); } void assign19() { check("void f() {\n" " char *p = malloc(10);\n" " free((void*)p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void assign20() { // #9187 check("void f() {\n" " char *p = static_cast(malloc(10));\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:3:1]: (error) Memory leak: p [memleak]\n", errout_str()); } @@ -437,14 +437,14 @@ class TestLeakAutoVar : public TestFixture { check("void f(int **x) {\n" // #10186 " void *p = malloc(10);\n" " *x = (int*)p;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("struct S { int i; };\n" // #10996 "void f() {\n" " S* s = new S();\n" " (void)s;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:5:1]: (error) Memory leak: s [memleak]\n", errout_str()); } @@ -452,12 +452,12 @@ class TestLeakAutoVar : public TestFixture { const Settings s = settingsBuilder().library("posix.cfg").checkLibrary().build(); check("void f(char tempFileName[256]) {\n" " const int fd = socket(AF_INET, SOCK_PACKET, 0 );\n" - "}", dinit(CheckOptions, $.cpp = true, $.s = &s)); + "}\n", dinit(CheckOptions, $.cpp = true, $.s = &s)); ASSERT_EQUALS("[test.cpp:3:1]: (error) Resource leak: fd [resourceLeak]\n", errout_str()); check("void f() {\n" " const void * const p = malloc(10);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:3:1]: (error) Memory leak: p [memleak]\n", errout_str()); } @@ -565,7 +565,7 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" // #11796 " int* p{ new int };\n" " int* q(new int);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:4:1]: (error) Memory leak: p [memleak]\n" "[test.cpp:4:1]: (error) Memory leak: q [memleak]\n", errout_str()); @@ -629,13 +629,13 @@ class TestLeakAutoVar : public TestFixture { check("void f(int*& x) {\n" // #8235 " int* p = (int*)malloc(10);\n" " x = p ? p : nullptr;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void f(int*& x) {\n" " int* p = (int*)malloc(10);\n" " x = p != nullptr ? p : nullptr;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void f(const char* n) {\n" // #12724 @@ -666,17 +666,17 @@ class TestLeakAutoVar : public TestFixture { void isAutoDealloc() { check("void f() {\n" " char *p = new char[100];" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:2:29]: (error) Memory leak: p [memleak]\n", errout_str()); check("void f() {\n" " Fred *fred = new Fred;" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " std::string *str = new std::string;" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:2:40]: (error) Memory leak: str [memleak]\n", errout_str()); check("class TestType {\n" // #9028 @@ -685,13 +685,13 @@ class TestLeakAutoVar : public TestFixture { "};\n" "void f() {\n" " TestType *tt = new TestType();\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:7:1]: (error) Memory leak: tt [memleak]\n", errout_str()); check("void f(Bar& b) {\n" // #7622 " char* data = new char[10];\n" " b = Bar(*new Foo(data));\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:4:1]: (information) --check-library: Function Foo() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); check("class B {};\n" @@ -699,7 +699,7 @@ class TestLeakAutoVar : public TestFixture { " void g() {\n" " auto d = new D();\n" " if (d) {}\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:6:1]: (error) Memory leak: d [memleak]\n", errout_str()); check("struct S {\n" // #12354 @@ -710,7 +710,7 @@ class TestLeakAutoVar : public TestFixture { " if (b)\n" " p = new S();\n" " p->f();\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:9:1]: (error) Memory leak: p [memleak]\n", errout_str()); } @@ -719,7 +719,7 @@ class TestLeakAutoVar : public TestFixture { " void *p = malloc(10);\n" " void *q = realloc(p, 20);\n" " free(q)\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -727,7 +727,7 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " void *p = malloc(10);\n" " void *q = realloc(p, 20);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:4:1]: (error) Memory leak: q [memleak]\n", errout_str()); } @@ -735,7 +735,7 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " char *p = malloc(10);\n" " char *q = (char*) realloc(p, 20);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:4:1]: (error) Memory leak: q [memleak]\n", errout_str()); } @@ -744,7 +744,7 @@ class TestLeakAutoVar : public TestFixture { " void * q = realloc(p, 10);\n" " if (q == NULL)\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:5:1]: (error) Memory leak: q [memleak]\n", errout_str()); } @@ -755,7 +755,7 @@ class TestLeakAutoVar : public TestFixture { " if (size && !datap)\n" " free(ptr);\n" " return datap;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9990 @@ -769,7 +769,7 @@ class TestLeakAutoVar : public TestFixture { " return;\n" " }\n" " free(p2);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -778,7 +778,7 @@ class TestLeakAutoVar : public TestFixture { " void *p = fopen(name,a);\n" " void *q = freopen(name, b, p);\n" " fclose(q)\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -786,7 +786,7 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " void *p = fopen(name,a);\n" " void *q = freopen(name, b, p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:4:1]: (error) Resource leak: q [resourceLeak]\n", errout_str()); } @@ -794,13 +794,13 @@ class TestLeakAutoVar : public TestFixture { check("void f(char *p) {\n" " free(p);\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:6]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n", errout_str()); check("void f(char *p) {\n" " free(p);\n" " char c = *p;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:15]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n", errout_str()); } @@ -808,7 +808,7 @@ class TestLeakAutoVar : public TestFixture { check("void f(struct str *p) {\n" " free(p);\n" " p = p->next;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:9]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n", errout_str()); } @@ -816,25 +816,25 @@ class TestLeakAutoVar : public TestFixture { check("void f(char *p) {\n" " free(p);\n" " return p;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:2:5] -> [test.c:3:5]: (error) Returning/dereferencing 'p' after it is deallocated / released [deallocret]\n", errout_str()); check("void f(char *p) {\n" " if (!p) free(p);\n" " return p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(char *p) {\n" " if (!p) delete p;\n" " return p;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void f(char *p) {\n" " if (!p) delete [] p;\n" " return p;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void f(void* p) {\n" @@ -844,7 +844,7 @@ class TestLeakAutoVar : public TestFixture { " }\n" " g(p);\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -852,7 +852,7 @@ class TestLeakAutoVar : public TestFixture { check("void f(char *p) {\n" " free(p), p = 0;\n" " *p = 0;\n" // <- Make sure pointer info is reset. It is NOT a freed pointer dereference - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -860,7 +860,7 @@ class TestLeakAutoVar : public TestFixture { check("void f(char *p) {\n" " free(p);\n" " x = p = foo();\n" // <- p is not dereferenced - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -869,14 +869,14 @@ class TestLeakAutoVar : public TestFixture { "void f(Foo* foo) {\n" " delete foo->ptr;\n" " foo->ptr = new Foo;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("struct Foo { int* ptr; };\n" "void f(Foo* foo) {\n" " delete foo->ptr;\n" " x = *foo->ptr;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); TODO_ASSERT_EQUALS("[test.cpp:4:6]: (error) Dereferencing 'ptr' after it is deallocated / released [deallocuse]\n", "", errout_str()); check("void parse() {\n" @@ -885,7 +885,7 @@ class TestLeakAutoVar : public TestFixture { " ~Buf() { delete[]m_buf; }\n" " uint8_t *m_buf;\n" " };\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("struct Foo {\n" @@ -897,14 +897,14 @@ class TestLeakAutoVar : public TestFixture { " delete foo->ptr;\n" " foo->ptr = new Foo;\n" " foo->ptr->func();\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void foo(void (*conv)(char**)) {\n" " char * ptr=(char*)malloc(42);\n" " free(ptr);\n" " (*conv)(&ptr);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -913,7 +913,7 @@ class TestLeakAutoVar : public TestFixture { " int *ptr = new int;\n" " delete(ptr);\n" " *ptr = 0;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:4:6]: (error) Dereferencing 'ptr' after it is deallocated / released [deallocuse]\n", errout_str()); } @@ -964,14 +964,14 @@ class TestLeakAutoVar : public TestFixture { " int *array = new int[42];\n" " delete [] array;\n" " return array[1];" // << - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:3:3] -> [test.cpp:4:3]: (error) Returning/dereferencing 'array' after it is deallocated / released [deallocret]\n", errout_str()); check("int f() {\n" " int *array = (int*)malloc(40);\n" " free(array);\n" " return array[1];" // << - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:3] -> [test.c:4:3]: (error) Returning/dereferencing 'array' after it is deallocated / released [deallocret]\n", errout_str()); } @@ -982,7 +982,7 @@ class TestLeakAutoVar : public TestFixture { "}\n" "void f2(struct foo *f, int *out) {\n" " *out = f->x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1120,35 +1120,35 @@ class TestLeakAutoVar : public TestFixture { " else\n" " p = 0;\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:9] -> [test.c:6:5]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( "void foo(char *p) {\n" " free(p);\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:2:3] -> [test.c:3:3]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( "void foo(char *p, char *r) {\n" " free(p);\n" " free(r);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check( "void foo() {\n" " free(p);\n" " free(r);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check( "void foo(char *p) {\n" " if (x < 3) free(p);\n" " else { if (x > 9) free(p); }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check( @@ -1156,7 +1156,7 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " getNext(&p);\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check( @@ -1164,7 +1164,7 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " bar();\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:2:3] -> [test.c:4:3]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( @@ -1172,7 +1172,7 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " printf(\"Freed memory at location %x\", p);\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:41]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n" "[test.c:2:3] -> [test.c:4:3]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); @@ -1181,21 +1181,21 @@ class TestLeakAutoVar : public TestFixture { "void foo(FILE *p) {\n" " fclose(p);\n" " fclose(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:2:3] -> [test.c:3:3]: (error) Resource handle 'p' freed twice. [doubleFree]\n", errout_str()); check( "void foo(FILE *p, FILE *r) {\n" " fclose(p);\n" " fclose(r);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check( "void foo(FILE *p) {\n" " if (x < 3) fclose(p);\n" " else { if (x > 9) fclose(p); }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check( @@ -1203,7 +1203,7 @@ class TestLeakAutoVar : public TestFixture { " fclose(p);\n" " gethandle(&p);\n" " fclose(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check( @@ -1211,14 +1211,14 @@ class TestLeakAutoVar : public TestFixture { " fclose(p);\n" " gethandle();\n" " fclose(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:2:3] -> [test.c:4:3]: (error) Resource handle 'p' freed twice. [doubleFree]\n", errout_str()); check( "void foo(Data* p) {\n" " free(p->a);\n" " free(p->b);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check( @@ -1229,7 +1229,7 @@ class TestLeakAutoVar : public TestFixture { " exit();\n" " }\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check( @@ -1240,7 +1240,7 @@ class TestLeakAutoVar : public TestFixture { " x = 0;\n" " }\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:4:9] -> [test.c:7:5]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( @@ -1249,35 +1249,35 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " p = do_something();\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check( "void foo(char *p) {\n" " delete p;\n" " delete p;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:3:10]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( "void foo(char *p, char *r) {\n" " delete p;\n" " delete r;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check( "void foo(P p) {\n" " delete p.x;\n" " delete p;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check( "void foo(char **p) {\n" " delete p[0];\n" " delete p[1];\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check( @@ -1285,7 +1285,7 @@ class TestLeakAutoVar : public TestFixture { " delete p;\n" " getNext(&p);\n" " delete p;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check( @@ -1293,21 +1293,21 @@ class TestLeakAutoVar : public TestFixture { " delete p;\n" " bar();\n" " delete p;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:4:10]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( "void foo(char *p) {\n" " delete[] p;\n" " delete[] p;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:3:12]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( "void foo(char *p, char *r) {\n" " delete[] p;\n" " delete[] r;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check( @@ -1315,7 +1315,7 @@ class TestLeakAutoVar : public TestFixture { " delete[] p;\n" " getNext(&p);\n" " delete[] p;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check( @@ -1323,7 +1323,7 @@ class TestLeakAutoVar : public TestFixture { " delete[] p;\n" " bar();\n" " delete[] p;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:4:12]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( @@ -1334,7 +1334,7 @@ class TestLeakAutoVar : public TestFixture { " delete pxpm;\n" " pxpm = NULL;\n" " return *this;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check( @@ -1351,7 +1351,7 @@ class TestLeakAutoVar : public TestFixture { " throw;\n" " }\n" " delete ptr;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check( @@ -1367,7 +1367,7 @@ class TestLeakAutoVar : public TestFixture { " if(doDelete)\n" " delete a;\n" " return 0;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); TODO_ASSERT_EQUALS("", "[test.cpp:8:8] -> [test.cpp:11:15]: (error) Memory pointed to by 'a' is freed twice. [doubleFree]\n", errout_str()); check( @@ -1381,7 +1381,7 @@ class TestLeakAutoVar : public TestFixture { " delete[] x;\n" " }\n" " delete[] x;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check( @@ -1393,7 +1393,7 @@ class TestLeakAutoVar : public TestFixture { " delete[] x;\n" " }\n" " delete[] x;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); TODO_ASSERT_EQUALS("[test.cpp:8]: (error) Memory pointed to by 'x' is freed twice.\n", "", errout_str()); check( @@ -1405,7 +1405,7 @@ class TestLeakAutoVar : public TestFixture { " delete[] x;\n" " }\n" " delete[] x;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); TODO_ASSERT_EQUALS("[test.cpp:8]: (error) Memory pointed to by 'x' is freed twice.\n", "", errout_str()); check( @@ -1417,7 +1417,7 @@ class TestLeakAutoVar : public TestFixture { " free(x);\n" " }\n" " free(x);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.c:8]: (error) Memory pointed to by 'x' is freed twice.\n", "", errout_str()); check( @@ -1431,7 +1431,7 @@ class TestLeakAutoVar : public TestFixture { " delete[] x;\n" " }\n" " delete[] x;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check( @@ -1445,7 +1445,7 @@ class TestLeakAutoVar : public TestFixture { " delete[] x;\n" " } while (true);\n" " delete[] x;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check( @@ -1457,7 +1457,7 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " }\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:6:9] -> [test.c:8:5]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); check( @@ -1478,7 +1478,7 @@ class TestLeakAutoVar : public TestFixture { "void MyThrow(err)\n" "{\n" " throw(err);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check( @@ -1499,7 +1499,7 @@ class TestLeakAutoVar : public TestFixture { "void MyExit(err)\n" "{\n" " exit(err);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check( // #6252 @@ -1514,14 +1514,14 @@ class TestLeakAutoVar : public TestFixture { " delete m_thing;\n" " m_thing = new Thing;\n" " }\n" - "};", dinit(CheckOptions, $.cpp = true)); + "};\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); // #7401 check("void pCodeLabelDestruct(pCode *pc) {\n" " free(PCL(pc)->label);\n" " free(pc);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1531,7 +1531,7 @@ class TestLeakAutoVar : public TestFixture { " if (a == 2) { free(p); return ((void*)1); }\n" " free(p);\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1548,7 +1548,7 @@ class TestLeakAutoVar : public TestFixture { " free(bar)\n" " } while(!done);\n" " return;" - "}" + "}\n" ); ASSERT_EQUALS("", errout_str()); } @@ -1560,7 +1560,7 @@ class TestLeakAutoVar : public TestFixture { " exit(1);\n" " }\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(void* p, int i) {\n" // #11391 @@ -1580,7 +1580,7 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " x = (q == p);\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:2:3] -> [test.c:4:3]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); } @@ -1588,7 +1588,7 @@ class TestLeakAutoVar : public TestFixture { check("void do_wordexp(FILE *f) {\n" " free(getword(f));\n" " fclose(f);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1597,14 +1597,14 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " if (x && (p = malloc(10)))\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(char *p, int x) {\n" " delete[] p;\n" " if (x && (p = new char[10]))\n" " delete[] p;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); } @@ -1717,7 +1717,7 @@ class TestLeakAutoVar : public TestFixture { " if (q == NULL)\n" " return;\n" " free(q);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:16] -> [test.c:8:5]: (error) Memory pointed to by 'p' is freed twice. [doubleFree]\n", errout_str()); } @@ -1753,7 +1753,7 @@ class TestLeakAutoVar : public TestFixture { " int *i = new int;\n" " unique_ptr x(i);\n" " delete i;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:6:5] -> [test.cpp:7:12]: (error) Memory pointed to by 'i' is freed twice. [doubleFree]\n", errout_str()); check("using namespace std;\n" @@ -1762,14 +1762,14 @@ class TestLeakAutoVar : public TestFixture { "{\n" " int *i = new int;\n" " unique_ptr x(i);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); } void doublefree15() { // #11966 check("void f(FILE* fp) {\n" " static_cast(fclose(fp));\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); } @@ -1831,7 +1831,7 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " char *p = malloc(10);\n" " exit(0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1839,7 +1839,7 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " char *p = malloc(10);\n" " fatal_error();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:18]: (information) --check-library: Function fatal_error() should have configuration [checkLibraryNoReturn]\n", errout_str()); } @@ -1850,9 +1850,9 @@ class TestLeakAutoVar : public TestFixture { " if (x) {\n" " free(p);\n" " ::exit(0);\n" - " }" + " }\n" " free(p);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -1860,9 +1860,9 @@ class TestLeakAutoVar : public TestFixture { " if (x) {\n" " free(p);\n" " std::exit(0);\n" - " }" + " }\n" " free(p);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); } @@ -1875,7 +1875,7 @@ class TestLeakAutoVar : public TestFixture { " func_notret();\n" " }\n" " free(ptr);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1884,7 +1884,7 @@ class TestLeakAutoVar : public TestFixture { " p->x = malloc(10);\n" " free(p->x);\n" " p->x = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(s_t s) {\n" // #11061 @@ -1906,7 +1906,7 @@ class TestLeakAutoVar : public TestFixture { check("void g(size_t len) {\n" // #12365 " char* b = new char[len + 1]{};\n" " std::string str = std::string(b);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:4:1]: (error) Memory leak: b [memleak]\n", errout_str()); } @@ -1917,7 +1917,7 @@ class TestLeakAutoVar : public TestFixture { " if (err) {\n" " free(reg);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1930,7 +1930,7 @@ class TestLeakAutoVar : public TestFixture { " goto x;\n" " }\n" " return p;\n" // no error since there is a goto - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1955,7 +1955,7 @@ class TestLeakAutoVar : public TestFixture { " if (x) { p = malloc(10); }\n" " else { return 0; }\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1964,7 +1964,7 @@ class TestLeakAutoVar : public TestFixture { " char *p = NULL;\n" " if (x) { p = malloc(10); }\n" " else { return 0; }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:5:1]: (error) Memory leak: p [memleak]\n", errout_str()); } @@ -1973,7 +1973,7 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(10);\n" " if (!p) { return; }\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("char * f(size_t size) {" @@ -1981,14 +1981,14 @@ class TestLeakAutoVar : public TestFixture { " if (!p && size != 0)" " return NULL;" " return p;" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " char *p = malloc(10);\n" " if (p) { } else { return; }\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #3866 - UNLIKELY @@ -1996,7 +1996,7 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(10);\n" " if (UNLIKELY(!p)) { return; }\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2005,7 +2005,7 @@ class TestLeakAutoVar : public TestFixture { " char *p;\n" " if (x) { p = malloc(10); }\n" " if (x) { free(p); }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" @@ -2013,7 +2013,7 @@ class TestLeakAutoVar : public TestFixture { " if (x) { p = malloc(10); }\n" " if (!x) { return; }\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2022,7 +2022,7 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(10);\n" " if (!p && x) { p = malloc(10); }\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2033,7 +2033,7 @@ class TestLeakAutoVar : public TestFixture { " free(a);\n" " else\n" " a = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:6:9]: (error) Memory leak: a [memleak]\n", errout_str()); } @@ -2043,7 +2043,7 @@ class TestLeakAutoVar : public TestFixture { " if (x < 0)\n" // assume negative value indicates its unallocated " return;\n" " free(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2053,7 +2053,7 @@ class TestLeakAutoVar : public TestFixture { " if (fd == -1)\n" " return -1;\n" " return fd;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f() {\n" @@ -2061,7 +2061,7 @@ class TestLeakAutoVar : public TestFixture { " if (fd != -1)\n" " return fd;\n" " return -1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2071,7 +2071,7 @@ class TestLeakAutoVar : public TestFixture { " if (dostuff(p==NULL,0))\n" " return;\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2081,7 +2081,7 @@ class TestLeakAutoVar : public TestFixture { " if (!(x != NULL))\n" " return;\n" " free(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2091,7 +2091,7 @@ class TestLeakAutoVar : public TestFixture { " if (NULL == (p = malloc(4)))\n" " return;\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2099,7 +2099,7 @@ class TestLeakAutoVar : public TestFixture { check("void f(char **p) {\n" " if ((*p = malloc(4)) == NULL)\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2110,7 +2110,7 @@ class TestLeakAutoVar : public TestFixture { " return 1;\n" " free(path);\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(int fd, const char *mode) {\n" @@ -2119,7 +2119,7 @@ class TestLeakAutoVar : public TestFixture { " return 1;\n" // <- memory leak " free(path);\n" " return 0;\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4] memory leak", "", errout_str()); } @@ -2129,7 +2129,7 @@ class TestLeakAutoVar : public TestFixture { " if (buf == (char*)NULL)\n" " return NULL;\n" " return buf;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2139,14 +2139,14 @@ class TestLeakAutoVar : public TestFixture { "void test_alloc() {\n" " if ( global_ptr = new SSS()) {}\n" " return;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("FILE* hFile;\n" "int openFile( void ) {\n" " if ((hFile = fopen(\"1.txt\", \"wb\" )) == NULL) return 0;\n" " return 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2157,7 +2157,7 @@ class TestLeakAutoVar : public TestFixture { " return;\n" " free(p);\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(void) {\n" @@ -2166,7 +2166,7 @@ class TestLeakAutoVar : public TestFixture { " return;\n" " free(p);\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2176,7 +2176,7 @@ class TestLeakAutoVar : public TestFixture { " if (!p)\n" " return NULL;\n" " return p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int *f() {\n" @@ -2184,7 +2184,7 @@ class TestLeakAutoVar : public TestFixture { " if (!!(!p))\n" " return NULL;\n" " return p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2195,7 +2195,7 @@ class TestLeakAutoVar : public TestFixture { " if (q == 0)\n" " return;\n" " free(q);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:5:9]: (error) Memory leak: p [memleak]\n", errout_str()); check("void f() {\n" @@ -2206,7 +2206,7 @@ class TestLeakAutoVar : public TestFixture { " return;\n" " } else\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:8:9]: (error) Memory leak: p [memleak]\n", errout_str()); } @@ -2217,7 +2217,7 @@ class TestLeakAutoVar : public TestFixture { " if (!b)\n" " return;\n" " a = b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2228,7 +2228,7 @@ class TestLeakAutoVar : public TestFixture { " else\n" " void * p2 = malloc(2);\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:30]: (error) Memory leak: p1 [memleak]\n" "[test.c:5:30]: (error) Memory leak: p2 [memleak]\n", errout_str()); @@ -2237,7 +2237,7 @@ class TestLeakAutoVar : public TestFixture { " void * p1 = malloc(5);\n" " else\n" " void * p2 = malloc(2);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:30]: (error) Memory leak: p1 [memleak]\n" "[test.c:5:30]: (error) Memory leak: p2 [memleak]\n", errout_str()); } @@ -2250,7 +2250,7 @@ class TestLeakAutoVar : public TestFixture { " p = malloc(5);\n" " }\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:6:5]: (error) Memory leak: p [memleak]\n", errout_str()); } @@ -2260,7 +2260,7 @@ class TestLeakAutoVar : public TestFixture { " if (fd >= 0)\n" " return fd;\n" " return -1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(const char * pathname, int flags) {\n" @@ -2268,7 +2268,7 @@ class TestLeakAutoVar : public TestFixture { " if (fd <= -1)\n" " return -1;\n" " return fd;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2410,7 +2410,7 @@ class TestLeakAutoVar : public TestFixture { " default: return;\n" " }\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2421,7 +2421,7 @@ class TestLeakAutoVar : public TestFixture { " for (i=0;i<5;i++) { }\n" " if (x) { free(p) }\n" " else { a = p; }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2456,13 +2456,13 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " FILE*f=fopen(fname,a);\n" " free(f);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:2:12] -> [test.c:3:5]: (error) Mismatching allocation and deallocation: f [mismatchAllocDealloc]\n", errout_str()); check("void f() {\n" " FILE*f=fopen(fname,a);\n" " free((void*)f);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:2:12] -> [test.c:3:5]: (error) Mismatching allocation and deallocation: f [mismatchAllocDealloc]\n", errout_str()); check("void f() {\n" @@ -2472,18 +2472,18 @@ class TestLeakAutoVar : public TestFixture { " delete[] cPtr;\n" " cPtr = new char[100];\n" " delete cPtr;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:6:12] -> [test.cpp:7:12]: (error) Mismatching allocation and deallocation: cPtr [mismatchAllocDealloc]\n", errout_str()); check("void f() {\n" " char *cPtr = new char[100];\n" " free(cPtr);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:2:18] -> [test.cpp:3:5]: (error) Mismatching allocation and deallocation: cPtr [mismatchAllocDealloc]\n", errout_str()); check("void f() {\n" " char *cPtr = new (buf) char[100];\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -2502,7 +2502,7 @@ class TestLeakAutoVar : public TestFixture { " void* a = malloc(1);\n" " void* b = freopen(f, p, a);\n" " free(b);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:2:14] -> [test.c:3:14]: (error) Mismatching allocation and deallocation: a [mismatchAllocDealloc]\n" "[test.c:3:14] -> [test.c:4:4]: (error) Mismatching allocation and deallocation: b [mismatchAllocDealloc]\n", errout_str()); @@ -2510,14 +2510,14 @@ class TestLeakAutoVar : public TestFixture { " void* a;\n" " void* b = realloc(a, 10);\n" " free(b);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int * i = new int;\n" " int * j = realloc(i, 2 * sizeof(int));\n" " delete[] j;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:2:14] -> [test.cpp:3:14]: (error) Mismatching allocation and deallocation: i [mismatchAllocDealloc]\n" "[test.cpp:3:14] -> [test.cpp:4:13]: (error) Mismatching allocation and deallocation: j [mismatchAllocDealloc]\n", errout_str()); @@ -2547,26 +2547,26 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " FILE*f=fopen(fname,a);\n" " std::unique_ptr fp{f};\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:3:30]: (error) Mismatching allocation and deallocation: f [mismatchAllocDealloc]\n", errout_str()); check("void f() {\n" " FILE*f=fopen(fname,a);\n" " std::unique_ptr fp{f, &fclose};\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " FILE*f=fopen(fname,a);\n" " std::shared_ptr fp{f, &fclose};\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("struct deleter { void operator()(FILE* f) { fclose(f); }};\n" "void f() {\n" " FILE*f=fopen(fname,a);\n" " std::unique_ptr fp{f};\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("int * create();\n" @@ -2588,39 +2588,39 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " FILE*f=fopen(fname,a);\n" " std::shared_ptr fp{f, [](FILE* x) { fclose(x); }};\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " FILE*f=fopen(fname,a);\n" " std::shared_ptr fp{f, +[](FILE* x) { fclose(x); }};\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " FILE*f=fopen(fname,a);\n" " std::shared_ptr fp{f, [](FILE* x) { free(f); }};\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:3:30]: (error) Mismatching allocation and deallocation: f [mismatchAllocDealloc]\n", errout_str()); check("void f() {\n" " FILE*f=fopen(fname,a);\n" " std::shared_ptr fp{f, [](FILE* x) {}};\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:3:30]: (error) Mismatching allocation and deallocation: f [mismatchAllocDealloc]\n", errout_str()); check("class C;\n" "void f() {\n" " C* c = new C{};\n" " std::shared_ptr a{c, [](C*) {}};\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("class C;\n" "void f() {\n" " C* c = new C{};\n" " std::shared_ptr a{c, [](C* x) { delete x; }};\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("struct DirDeleter {\n" // #12544 @@ -2652,7 +2652,7 @@ class TestLeakAutoVar : public TestFixture { check("int f() {\n" " char *p = malloc(100);\n" " return 123;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:5]: (error) Memory leak: p [memleak]\n", errout_str()); } @@ -2660,7 +2660,7 @@ class TestLeakAutoVar : public TestFixture { check("char *f() {\n" " char *p = malloc(100);\n" " return p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2668,7 +2668,7 @@ class TestLeakAutoVar : public TestFixture { check("struct dev * f() {\n" " struct ABC *abc = malloc(100);\n" " return &abc->dev;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2680,7 +2680,7 @@ class TestLeakAutoVar : public TestFixture { " throw 1;\n" " }\n" " free(p);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void f(char *p, int x) {\n" @@ -2689,7 +2689,7 @@ class TestLeakAutoVar : public TestFixture { " throw 1;\n" " }\n" " delete p;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void f(char *p, int x) {\n" @@ -2698,7 +2698,7 @@ class TestLeakAutoVar : public TestFixture { " throw 1;\n" " }\n" " delete [] p;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); } @@ -2712,7 +2712,7 @@ class TestLeakAutoVar : public TestFixture { " return;\n" " }\n" " *p = 0;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); } @@ -2720,7 +2720,7 @@ class TestLeakAutoVar : public TestFixture { check("std::pair f(size_t n) {\n" " char* p = (char* )malloc(n);\n" " return {p, p};\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); } @@ -2728,43 +2728,43 @@ class TestLeakAutoVar : public TestFixture { check("uint8_t *f() {\n" " void *x = malloc(1);\n" " return (uint8_t *)x;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("uint8_t f() {\n" " void *x = malloc(1);\n" " return (uint8_t)x;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:3:5]: (error) Memory leak: x [memleak]\n", errout_str()); check("void** f() {\n" " void *x = malloc(1);\n" " return (void**)x;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void* f() {\n" " void *x = malloc(1);\n" " return (long long)x;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void* f() {\n" " void *x = malloc(1);\n" " return (void*)(short)x;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:3:5]: (error) Memory leak: x [memleak]\n", errout_str()); check("void* f() {\n" " void *x = malloc(1);\n" " return (mytype)x;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void* f() {\n" // Do not crash " void *x = malloc(1);\n" " return (mytype)y;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:3:5]: (error) Memory leak: x [memleak]\n", errout_str()); } @@ -2772,25 +2772,25 @@ class TestLeakAutoVar : public TestFixture { check("void* f() {\n" " void *x = malloc(1);\n" " return (x);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void* f() {\n" " void *x = malloc(1);\n" " return ((x));\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void* f() {\n" " void *x = malloc(1);\n" " return ((((x))));\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("char* f() {\n" " void *x = malloc(1);\n" " return (char*)(x);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); } @@ -2798,7 +2798,7 @@ class TestLeakAutoVar : public TestFixture { check("void* f() {\n" " void *x = malloc (sizeof (struct alloc));\n" " return x + sizeof (struct alloc);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); } @@ -2807,7 +2807,7 @@ class TestLeakAutoVar : public TestFixture { " char* p = (char*)malloc(1);\n" " p[0] = 'x';\n" " return p[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:4:5]: (error) Memory leak: p [memleak]\n", errout_str()); check("struct S { int f(); };\n" // #11746 @@ -2815,14 +2815,14 @@ class TestLeakAutoVar : public TestFixture { " S* s = new S;\n" " delete s;\n" " return s->f();\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:4:5] -> [test.cpp:5:5]: (error) Returning/dereferencing 's' after it is deallocated / released [deallocret]\n", errout_str()); check("int f() {\n" " int* p = new int(3);\n" " delete p;\n" " return *p;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:3:5] -> [test.cpp:4:5]: (error) Returning/dereferencing 'p' after it is deallocated / released [deallocret]\n", errout_str()); } @@ -2878,7 +2878,7 @@ class TestLeakAutoVar : public TestFixture { void test1() { check("void f(double*&p) {\n" // 3809 " p = malloc(0x100);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); check("void f(int*& p) {\n" // #4400 @@ -2907,7 +2907,7 @@ class TestLeakAutoVar : public TestFixture { check("struct Fred {\n" " char *p;\n" " void f1() { free(p); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -2915,7 +2915,7 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " char *&p = x();\n" " p = malloc(10);\n" - "};", dinit(CheckOptions, $.cpp = true)); + "};\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); } @@ -2924,21 +2924,21 @@ class TestLeakAutoVar : public TestFixture { " static char *p;\n" " if (!p) p = malloc(10);\n" " if (x) { free(p); p = 0; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } void test5() { // unknown type - check("void f() { Fred *p = malloc(10); }", dinit(CheckOptions, $.cpp = true)); + check("void f() { Fred *p = malloc(10); }\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:1:34]: (error) Memory leak: p [memleak]\n", errout_str()); - check("void f() { Fred *p = malloc(10); }"); + check("void f() { Fred *p = malloc(10); }\n"); ASSERT_EQUALS("[test.c:1:34]: (error) Memory leak: p [memleak]\n", errout_str()); - check("void f() { Fred *p = new Fred; }", dinit(CheckOptions, $.cpp = true)); + check("void f() { Fred *p = new Fred; }\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); - check("void f() { Fred fred = malloc(10); }", dinit(CheckOptions, $.cpp = true)); + check("void f() { Fred fred = malloc(10); }\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); } @@ -2946,7 +2946,7 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " char *p = malloc(10);\n" " throw 123;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:3:5]: (error) Memory leak: p [memleak]\n", errout_str()); check("void f() {\n" @@ -2956,7 +2956,7 @@ class TestLeakAutoVar : public TestFixture { " throw 123;\n" " } catch (...) { }\n" " free(p);\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); } @@ -2973,7 +2973,7 @@ class TestLeakAutoVar : public TestFixture { " throw ::NS::Except();\n" " }\n" " delete pi;\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("", errout_str()); } @@ -2986,7 +2986,7 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " char *p = malloc(10);\n" " x(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:9]: (information) --check-library: Function x() should have configuration [checkLibraryNoReturn]\n" "[test.c:4:1]: (information) --check-library: Function x() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); @@ -3004,7 +3004,7 @@ class TestLeakAutoVar : public TestFixture { check("void f() {\n" " char *p = malloc(10);\n" " x(&p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:10]: (information) --check-library: Function x() should have configuration [checkLibraryNoReturn]\n" "[test.c:4:1]: (information) --check-library: Function x() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); @@ -3015,7 +3015,7 @@ class TestLeakAutoVar : public TestFixture { const char code[] = "void f() {\n" " char *p = malloc(10);\n" " if (set_data(p)) { }\n" - "}"; + "}\n"; check(code); ASSERT_EQUALS("[test.c:4:1]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); check(code, dinit(CheckOptions, $.cpp = true)); @@ -3026,7 +3026,7 @@ class TestLeakAutoVar : public TestFixture { const char code[] = "void f() {\n" " char *p = malloc(10);\n" " if (set_data(p)) { return; }\n" - "}"; + "}\n"; check(code); ASSERT_EQUALS("[test.c:3:24]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\n" "[test.c:4:1]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\n" @@ -3043,7 +3043,7 @@ class TestLeakAutoVar : public TestFixture { " char *p = malloc(10);\n" " int ret = set_data(p);\n" " return ret;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:4:5]: (information) --check-library: Function set_data() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); } @@ -3121,7 +3121,7 @@ class TestLeakAutoVar : public TestFixture { void ptrptr() { check("void f() {\n" " char **p = malloc(10);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.c:3:1]: (error) Memory leak: p [memleak]\n", errout_str()); } @@ -3129,19 +3129,19 @@ class TestLeakAutoVar : public TestFixture { check("void QueueDSMCCPacket(unsigned char *data, int length) {\n" " unsigned char *dataCopy = malloc(length * sizeof(unsigned char));\n" " m_dsmccQueue.enqueue(new DSMCCPacket(dataCopy));\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:4:1]: (information) --check-library: Function DSMCCPacket() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); check("void QueueDSMCCPacket(unsigned char *data, int length) {\n" " unsigned char *dataCopy = malloc(length * sizeof(unsigned char));\n" " m_dsmccQueue.enqueue(new DSMCCPacket(somethingunrelated));\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:4:1]: (error) Memory leak: dataCopy [memleak]\n", errout_str()); check("void f() {\n" " char *buf = new char[1000];\n" " clist.push_back(new (std::nothrow) C(buf));\n" - "}", dinit(CheckOptions, $.cpp = true)); + "}\n", dinit(CheckOptions, $.cpp = true)); ASSERT_EQUALS("[test.cpp:4:1]: (information) --check-library: Function C() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); } @@ -3150,7 +3150,7 @@ class TestLeakAutoVar : public TestFixture { " double *new = malloc(1*sizeof(double));\n" " free(new);\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3163,7 +3163,7 @@ class TestLeakAutoVar : public TestFixture { " }\n" " c = malloc(128);\n" " return ret();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3226,7 +3226,7 @@ class TestLeakAutoVar : public TestFixture { "{\n" " char * buf = malloc(4);\n" " free_func((void *)(1), buf);\n" - "}", settingsFunctionCall); + "}\n", settingsFunctionCall); ASSERT_EQUALS("[test.cpp:5:1]: (information) --check-library: Function free_func() should have / configuration [checkLibraryUseIgnore]\n", errout_str()); check("void g(void*);\n" @@ -3312,7 +3312,7 @@ class TestLeakAutoVarRecursiveCountLimit : public TestFixture { "void foo() {\n" " if (0) { }\n" " THOU THOU\n" - "}"), LIMIT, "Internal limit: CheckLeakAutoVar::checkScope() Maximum recursive count of 1000 reached."); + "}\n"), LIMIT, "Internal limit: CheckLeakAutoVar::checkScope() Maximum recursive count of 1000 reached."); ASSERT_NO_THROW(checkP("#define ONE if (0) { }\n" "#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n" "#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n" @@ -3320,7 +3320,7 @@ class TestLeakAutoVarRecursiveCountLimit : public TestFixture { "void foo() {\n" " if (0) { }\n" " THOU THOU\n" - "}")); + "}\n")); } }; @@ -3362,7 +3362,7 @@ class TestLeakAutoVarStrcpy : public TestFixture { "{\n" " char* ptr = new char[strlen(str)+1];\n" " m = strcpy(ptr, str);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3370,7 +3370,7 @@ class TestLeakAutoVarStrcpy : public TestFixture { check("void f(char *p) {\n" " free(p);\n" " strcpy(a, p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:15]: (error) Dereferencing 'p' after it is deallocated / released [deallocuse]\n", errout_str()); check("void f(char *p, const char *q) {\n" // #11665 @@ -3383,12 +3383,12 @@ class TestLeakAutoVarStrcpy : public TestFixture { check("void f(char *p) {\n" // #3041 - assigning pointer when it's used " free(p);\n" " strcpy(a, p=b());\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void fclose_false_positive() { // #9575 - check("int f(FILE *fp) { return fclose(fp); }"); + check("int f(FILE *fp) { return fclose(fp); }\n"); ASSERT_EQUALS("", errout_str()); } @@ -3418,7 +3418,7 @@ class TestLeakAutoVarStrcpy : public TestFixture { " if (b)\n" " p = new S();\n" " p->f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:1]: (error) Memory leak: p [memleak]\n", errout_str()); check("class B { std::string s; };\n" // #12062 diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index a531ac4cba9..28264a02a53 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -109,7 +109,7 @@ class TestLibrary : public TestFixture { " \n" ""; - const char code[] = "foo();"; + const char code[] = "foo();\n"; SimpleTokenList tokenList(code); tokenList.front()->next()->astOperand1(tokenList.front()); @@ -131,13 +131,13 @@ class TestLibrary : public TestFixture { Library library; ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); { - const char code[] = "fred.foo(123);"; // <- wrong scope, not library function + const char code[] = "fred.foo(123);\n"; // <- wrong scope, not library function const SimpleTokenList tokenList(code); ASSERT(library.isNotLibraryFunction(tokenList.front()->tokAt(2))); } { - const char code[] = "Fred::foo(123);"; // <- wrong scope, not library function + const char code[] = "Fred::foo(123);\n"; // <- wrong scope, not library function const SimpleTokenList tokenList(code); ASSERT(library.isNotLibraryFunction(tokenList.front()->tokAt(2))); @@ -153,7 +153,7 @@ class TestLibrary : public TestFixture { ""; TokenList tokenList(settingsDefault, Standards::Language::CPP); - const char code[] = "foo();"; // <- too few arguments, not library function + const char code[] = "foo();\n"; // <- too few arguments, not library function ASSERT(tokenList.createTokensFromString(code)); Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous()); tokenList.createAst(); @@ -177,7 +177,7 @@ class TestLibrary : public TestFixture { { TokenList tokenList(settingsDefault, Standards::Language::CPP); - const char code[] = "foo();"; // <- too few arguments, not library function + const char code[] = "foo();\n"; // <- too few arguments, not library function ASSERT(tokenList.createTokensFromString(code)); Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous()); tokenList.createAst(); @@ -186,7 +186,7 @@ class TestLibrary : public TestFixture { } { TokenList tokenList(settingsDefault, Standards::Language::CPP); - const char code[] = "foo(a);"; // <- library function + const char code[] = "foo(a);\n"; // <- library function ASSERT(tokenList.createTokensFromString(code)); Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous()); tokenList.createAst(); @@ -197,7 +197,7 @@ class TestLibrary : public TestFixture { } { TokenList tokenList(settingsDefault, Standards::Language::CPP); - const char code[] = "foo(a, b);"; // <- library function + const char code[] = "foo(a, b);\n"; // <- library function ASSERT(tokenList.createTokensFromString(code)); Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous()); tokenList.createAst(); @@ -208,7 +208,7 @@ class TestLibrary : public TestFixture { } { TokenList tokenList(settingsDefault, Standards::Language::CPP); - const char code[] = "foo(a, b, c);"; // <- too much arguments, not library function + const char code[] = "foo(a, b, c);\n"; // <- too much arguments, not library function ASSERT(tokenList.createTokensFromString(code)); Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous()); tokenList.createAst(); @@ -225,7 +225,7 @@ class TestLibrary : public TestFixture { " \n" ""; - const char code[] = "Fred foo(123);"; // <- Variable declaration, not library function + const char code[] = "Fred foo(123);\n"; // <- Variable declaration, not library function SimpleTokenList tokenList(code); tokenList.front()->next()->astOperand1(tokenList.front()); tokenList.front()->next()->varId(1); @@ -285,7 +285,7 @@ class TestLibrary : public TestFixture { ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); ASSERT_EQUALS(0, library.functions().at("foo").argumentChecks.at(-1).notuninit); - const char code[] = "foo(a,b,c,d,e);"; + const char code[] = "foo(a,b,c,d,e);\n"; SimpleTokenList tokenList(code); tokenList.front()->next()->astOperand1(tokenList.front()); @@ -309,7 +309,7 @@ class TestLibrary : public TestFixture { Library library; ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); - const char code[] = "foo(a,b,c,d);"; + const char code[] = "foo(a,b,c,d);\n"; SimpleTokenList tokenList(code); tokenList.front()->next()->astOperand1(tokenList.front()); @@ -340,7 +340,7 @@ class TestLibrary : public TestFixture { Library library; ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); - const char code[] = "foo(a,b,c,d,e,f,g,h,i,j,k);"; + const char code[] = "foo(a,b,c,d,e,f,g,h,i,j,k);\n"; SimpleTokenList tokenList(code); tokenList.front()->next()->astOperand1(tokenList.front()); @@ -481,7 +481,7 @@ class TestLibrary : public TestFixture { Library library; ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); - const char code[] = "foo(a,b,c,d,e);"; + const char code[] = "foo(a,b,c,d,e);\n"; SimpleTokenList tokenList(code); tokenList.front()->next()->astOperand1(tokenList.front()); @@ -543,13 +543,13 @@ class TestLibrary : public TestFixture { ASSERT(library.functions().at("bar").argumentChecks.empty()); { - const char code[] = "Foo::foo();"; + const char code[] = "Foo::foo();\n"; const SimpleTokenList tokenList(code); ASSERT(library.isnotnoreturn(tokenList.front()->tokAt(2))); } { - const char code[] = "bar();"; + const char code[] = "bar();\n"; const SimpleTokenList tokenList(code); ASSERT(library.isnotnoreturn(tokenList.front())); } @@ -569,14 +569,14 @@ class TestLibrary : public TestFixture { { SimpleTokenizer tokenizer(settingsDefault, *this); - const char code[] = "CString str; str.Format();"; + const char code[] = "CString str; str.Format();\n"; ASSERT(tokenizer.tokenize(code)); ASSERT(library.isnotnoreturn(Token::findsimplematch(tokenizer.tokens(), "Format"))); } { SimpleTokenizer tokenizer(settingsDefault, *this); - const char code[] = "HardDrive hd; hd.Format();"; + const char code[] = "HardDrive hd; hd.Format();\n"; ASSERT(tokenizer.tokenize(code)); ASSERT(!library.isnotnoreturn(Token::findsimplematch(tokenizer.tokens(), "Format"))); } @@ -595,14 +595,14 @@ class TestLibrary : public TestFixture { { SimpleTokenizer tokenizer(settingsDefault, *this); - const char code[] = "struct X : public Base { void dostuff() { f(0); } };"; + const char code[] = "struct X : public Base { void dostuff() { f(0); } };\n"; ASSERT(tokenizer.tokenize(code)); ASSERT(library.isnullargbad(Token::findsimplematch(tokenizer.tokens(), "f"),1)); } { SimpleTokenizer tokenizer(settingsDefault, *this); - const char code[] = "struct X : public Base { void dostuff() { f(1,2); } };"; + const char code[] = "struct X : public Base { void dostuff() { f(1,2); } };\n"; ASSERT(tokenizer.tokenize(code)); ASSERT(!library.isnullargbad(Token::findsimplematch(tokenizer.tokens(), "f"),1)); } @@ -622,7 +622,7 @@ class TestLibrary : public TestFixture { Library library; ASSERT(LibraryHelper::loadxmldata(library, xmldata, sizeof(xmldata))); - const char code[] = "a(); b();"; + const char code[] = "a(); b();\n"; const SimpleTokenList tokenList(code); const Library::WarnInfo* a = library.getWarnInfo(tokenList.front()); @@ -872,7 +872,7 @@ class TestLibrary : public TestFixture { { SimpleTokenizer var(*this); - ASSERT(var.tokenize("std::A a;")); + ASSERT(var.tokenize("std::A a;\n")); ASSERT_EQUALS(&A, library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); bool isIterator; @@ -882,7 +882,7 @@ class TestLibrary : public TestFixture { { SimpleTokenizer var(*this); - ASSERT(var.tokenize("std::A::size_type a_s;")); + ASSERT(var.tokenize("std::A::size_type a_s;\n")); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); @@ -890,7 +890,7 @@ class TestLibrary : public TestFixture { { SimpleTokenizer var(*this); - ASSERT(var.tokenize("std::A::iterator a_it;")); + ASSERT(var.tokenize("std::A::iterator a_it;\n")); ASSERT(!library.detectContainer(var.tokens())); ASSERT_EQUALS(&A, library.detectIterator(var.tokens())); bool isIterator; @@ -900,7 +900,7 @@ class TestLibrary : public TestFixture { { SimpleTokenizer var(*this); - ASSERT(var.tokenize("std::B b;")); + ASSERT(var.tokenize("std::B b;\n")); ASSERT_EQUALS(&B, library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); bool isIterator; @@ -910,7 +910,7 @@ class TestLibrary : public TestFixture { { SimpleTokenizer var(*this); - ASSERT(var.tokenize("std::B::size_type b_s;")); + ASSERT(var.tokenize("std::B::size_type b_s;\n")); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); @@ -918,7 +918,7 @@ class TestLibrary : public TestFixture { { SimpleTokenizer var(*this); - ASSERT(var.tokenize("std::B::iterator b_it;")); + ASSERT(var.tokenize("std::B::iterator b_it;\n")); ASSERT(!library.detectContainer(var.tokens())); ASSERT_EQUALS(&B, library.detectIterator(var.tokens())); bool isIterator; @@ -928,7 +928,7 @@ class TestLibrary : public TestFixture { { SimpleTokenizer var(*this); - ASSERT(var.tokenize("C c;")); + ASSERT(var.tokenize("C c;\n")); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); @@ -936,7 +936,7 @@ class TestLibrary : public TestFixture { { SimpleTokenizer var(*this); - ASSERT(var.tokenize("D d;")); + ASSERT(var.tokenize("D d;\n")); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); @@ -944,7 +944,7 @@ class TestLibrary : public TestFixture { { SimpleTokenizer var(*this); - ASSERT(var.tokenize("std::E e;")); + ASSERT(var.tokenize("std::E e;\n")); ASSERT(library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); bool isIterator; @@ -955,7 +955,7 @@ class TestLibrary : public TestFixture { { SimpleTokenizer var(*this); - ASSERT(var.tokenize("E e;")); + ASSERT(var.tokenize("E e;\n")); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); @@ -964,7 +964,7 @@ class TestLibrary : public TestFixture { { SimpleTokenizer var(*this); - ASSERT(var.tokenize("std::E::iterator I;")); + ASSERT(var.tokenize("std::E::iterator I;\n")); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); @@ -973,7 +973,7 @@ class TestLibrary : public TestFixture { { SimpleTokenizer var(*this); - ASSERT(var.tokenize("std::E::size_type p;")); + ASSERT(var.tokenize("std::E::size_type p;\n")); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); @@ -982,7 +982,7 @@ class TestLibrary : public TestFixture { { SimpleTokenizer var(*this); - ASSERT(var.tokenize("std::F f;")); + ASSERT(var.tokenize("std::F f;\n")); ASSERT(library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); bool isIterator; @@ -992,7 +992,7 @@ class TestLibrary : public TestFixture { { SimpleTokenizer var(*this); - ASSERT(var.tokenize("std::F::iterator I;")); + ASSERT(var.tokenize("std::F::iterator I;\n")); ASSERT(!library.detectContainer(var.tokens())); TODO_ASSERT(library.detectIterator(var.tokens())); bool isIterator = false; @@ -1002,7 +1002,7 @@ class TestLibrary : public TestFixture { { SimpleTokenizer var(*this); - ASSERT(var.tokenize("F::iterator I;")); + ASSERT(var.tokenize("F::iterator I;\n")); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 2999fd3f441..e05698ae23e 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -51,19 +51,19 @@ class TestMemleak : public TestFixture { void testFunctionReturnType() { { const char code[] = "const char *foo()\n" - "{ return 0; }"; + "{ return 0; }\n"; ASSERT_EQUALS(CheckMemoryLeakImpl::No, functionReturnType(code)); } { const char code[] = "Fred *newFred()\n" - "{ return new Fred; }"; + "{ return new Fred; }\n"; ASSERT_EQUALS(CheckMemoryLeakImpl::New, functionReturnType(code)); } { const char code[] = "char *foo()\n" - "{ return new char[100]; }"; + "{ return new char[100]; }\n"; ASSERT_EQUALS(CheckMemoryLeakImpl::NewArray, functionReturnType(code)); } @@ -72,7 +72,7 @@ class TestMemleak : public TestFixture { "{\n" " char *p = new char[100];\n" " return p;\n" - "}"; + "}\n"; ASSERT_EQUALS(CheckMemoryLeakImpl::NewArray, functionReturnType(code)); } } @@ -157,7 +157,7 @@ class TestMemleakInFunction : public TestFixture { "{\n" " char *a = (char *)malloc(10);\n" " a = realloc(a, 100);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure [memleakOnRealloc]\n", errout_str()); } @@ -167,7 +167,7 @@ class TestMemleakInFunction : public TestFixture { " char *a = (char *)malloc(10);\n" " a = (char *)realloc(a, 100);\n" " free(a);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure [memleakOnRealloc]\n", errout_str()); } @@ -179,7 +179,7 @@ class TestMemleakInFunction : public TestFixture { " if ((a = realloc(a, 100)) == NULL)\n" " return;\n" " free(a);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -191,7 +191,7 @@ class TestMemleakInFunction : public TestFixture { " if ((a = realloc(a, 100)) == NULL)\n" " return;\n" " free(a);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: a\n", "[test.cpp:4:10]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure [memleakOnRealloc]\n", @@ -209,7 +209,7 @@ class TestMemleakInFunction : public TestFixture { " free(buf);\n" " else\n" " free(new_buf);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -223,7 +223,7 @@ class TestMemleakInFunction : public TestFixture { " }\n" " free(pData);\n" " return true;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -235,7 +235,7 @@ class TestMemleakInFunction : public TestFixture { " if (!m_buf) {\n" " m_buf = origBuf;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -243,7 +243,7 @@ class TestMemleakInFunction : public TestFixture { check("void foo()\n" "{\n" " x = realloc(x,100);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -253,7 +253,7 @@ class TestMemleakInFunction : public TestFixture { " pa = pb = malloc(10);\n" " pa = realloc(pa, 20);" " exit();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -264,7 +264,7 @@ class TestMemleakInFunction : public TestFixture { " if (!p)\n" " error();\n" " usep(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -275,7 +275,7 @@ class TestMemleakInFunction : public TestFixture { " if ((a = realloc(a, x + 100)) == NULL)\n" " return;\n" " free(a);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -285,7 +285,7 @@ class TestMemleakInFunction : public TestFixture { " char **str;\n" " *str = realloc(*str,100);\n" " free (*str);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:6]: (error) Common realloc mistake: \'str\' nulled but not freed upon failure [memleakOnRealloc]\n", errout_str()); } @@ -296,7 +296,7 @@ class TestMemleakInFunction : public TestFixture { " if (!p)\n" " error();\n" " usep(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -307,7 +307,7 @@ class TestMemleakInFunction : public TestFixture { " if( m_options == NULL )\n" " return false;\n" " return true;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Common realloc mistake: \'m_options\' nulled but not freed upon failure [memleakOnRealloc]\n", errout_str()); } @@ -317,7 +317,7 @@ class TestMemleakInFunction : public TestFixture { " if (zLine) {\n" " free(zLine);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -326,7 +326,7 @@ class TestMemleakInFunction : public TestFixture { "{\n" " void ***a = malloc(sizeof(a));\n" " ***a = realloc(***(a), sizeof(a) * 2);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:8]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure [memleakOnRealloc]\n", errout_str()); } @@ -335,7 +335,7 @@ class TestMemleakInFunction : public TestFixture { "{\n" " void *a = malloc(sizeof(a));\n" " a = realloc((void*)a, sizeof(a) * 2);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure [memleakOnRealloc]\n", errout_str()); } @@ -344,7 +344,7 @@ class TestMemleakInFunction : public TestFixture { "{\n" " void *a = malloc(sizeof(a));\n" " a = (realloc((void*)((a)), sizeof(a) * 2));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure [memleakOnRealloc]\n", errout_str()); } @@ -353,7 +353,7 @@ class TestMemleakInFunction : public TestFixture { "{\n" " void *a = malloc(sizeof(a));\n" " a = realloc((a) + 1, sizeof(a) * 2);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -364,7 +364,7 @@ class TestMemleakInFunction : public TestFixture { " bs = realloc(bs, 100);\n" " if (bs == NULL) return bs0;\n" " return bs;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -375,7 +375,7 @@ class TestMemleakInFunction : public TestFixture { " bs = realloc(bs, 100);\n" " if (bs == NULL) return;\n" " *bsp = bs;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -386,7 +386,7 @@ class TestMemleakInFunction : public TestFixture { " if (!(cigar = realloc(cigar, 100 * sizeof(*cigar))))\n" " return;\n" " s->cigar = cigar;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -394,28 +394,28 @@ class TestMemleakInFunction : public TestFixture { check("void f() {\n" "void *a = NULL;\n" "a = realloc(a, 20);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" "void *a = NULL;\n" "a = malloc(10);\n" "a = realloc(a, 20);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:1]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure [memleakOnRealloc]\n", errout_str()); check("void f() {\n" "void *a = nullptr;\n" "a = malloc(10);\n" "a = realloc(a, 20);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:1]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure [memleakOnRealloc]\n", errout_str()); check("void f(char *b) {\n" "void *a = NULL;\n" "a = b;\n" "a = realloc(a, 20);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -568,7 +568,7 @@ class TestMemleakInClass : public TestFixture { "Fred::~Fred()\n" "{\n" " delete [] str2;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:11]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); check("class Fred\n" @@ -586,7 +586,7 @@ class TestMemleakInClass : public TestFixture { " {\n" " delete [] str2;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:11]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); } @@ -608,7 +608,7 @@ class TestMemleakInClass : public TestFixture { "Fred::~Fred()\n" "{\n" " free(str1);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:17:5]: (error) Mismatching allocation and deallocation: Fred::str1 [mismatchAllocDealloc]\n", errout_str()); check("class Fred\n" @@ -624,7 +624,7 @@ class TestMemleakInClass : public TestFixture { " {\n" " free(str1);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:12:9]: (error) Mismatching allocation and deallocation: Fred::str1 [mismatchAllocDealloc]\n", errout_str()); } @@ -660,7 +660,7 @@ class TestMemleakInClass : public TestFixture { " delete tok;\n" " tok = next;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); @@ -689,7 +689,7 @@ class TestMemleakInClass : public TestFixture { " tok = next;\n" " }\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -713,7 +713,7 @@ class TestMemleakInClass : public TestFixture { "{\n" " ABC *p = new ABC;\n" " addAbc( p );\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct ABC;\n" @@ -730,7 +730,7 @@ class TestMemleakInClass : public TestFixture { " ABC *p = new ABC;\n" " addAbc( p );\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -746,7 +746,7 @@ class TestMemleakInClass : public TestFixture { " char *str = new char[100];\n" " delete [] str;\n" " hello();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class Fred\n" @@ -758,7 +758,7 @@ class TestMemleakInClass : public TestFixture { " delete [] str;\n" " hello();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -778,7 +778,7 @@ class TestMemleakInClass : public TestFixture { "Fred::~Fred()\n" "{\n" " delete this->i;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class Fred\n" @@ -793,7 +793,7 @@ class TestMemleakInClass : public TestFixture { " {\n" " delete this->i;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -810,7 +810,7 @@ class TestMemleakInClass : public TestFixture { " int* c = new int(1);\n" " delete c;\n" " doNothing(c);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class A\n" @@ -823,7 +823,7 @@ class TestMemleakInClass : public TestFixture { " doNothing(c);\n" " }\n" " void doNothing() { }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -840,7 +840,7 @@ class TestMemleakInClass : public TestFixture { "{ p = new int; }\n" "\n" "A::~A()\n" - "{ delete (p); }"); + "{ delete (p); }\n"); ASSERT_EQUALS("", errout_str()); check("class A\n" @@ -851,7 +851,7 @@ class TestMemleakInClass : public TestFixture { " { p = new int; }\n" " ~A()\n" " { delete (p); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -863,7 +863,7 @@ class TestMemleakInClass : public TestFixture { " A();\n" "};\n" "A::A()\n" - "{ p = new int; }"); + "{ p = new int; }\n"); ASSERT_EQUALS("[test.cpp:4:11]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); check("class A\n" @@ -871,7 +871,7 @@ class TestMemleakInClass : public TestFixture { "public:\n" " int * p;\n" " A() { p = new int; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:11]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); } @@ -881,8 +881,8 @@ class TestMemleakInClass : public TestFixture { "public:\n" " int * p;\n" " A() : p(new int[10])\n" - " { }" - "};"); + " { }\n" + "};\n"); ASSERT_EQUALS("[test.cpp:4:11]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); check("class A\n" @@ -892,7 +892,7 @@ class TestMemleakInClass : public TestFixture { " A();\n" "};\n" "A::A() : p(new int[10])\n" - "{ }"); + "{ }\n"); ASSERT_EQUALS("[test.cpp:4:11]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); } @@ -914,7 +914,7 @@ class TestMemleakInClass : public TestFixture { "{ }\n" "\n" "void A::cleanup()\n" - "{ delete [] p; }"); + "{ delete [] p; }\n"); ASSERT_EQUALS("[test.cpp:4:10]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); check("class A\n" @@ -928,7 +928,7 @@ class TestMemleakInClass : public TestFixture { " { }\n" " void cleanup()\n" " { delete [] p; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:4:10]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); } @@ -950,7 +950,7 @@ class TestMemleakInClass : public TestFixture { "{ }\n" "\n" "void A::foo()\n" - "{ p = new int[10]; delete [] p; }"); + "{ p = new int[10]; delete [] p; }\n"); ASSERT_EQUALS("[test.cpp:17:3]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated. [publicAllocationError]\n", errout_str()); check("class A\n" @@ -964,7 +964,7 @@ class TestMemleakInClass : public TestFixture { " { }\n" " void foo()\n" " { p = new int[10]; delete [] p; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:11:7]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated. [publicAllocationError]\n", errout_str()); } @@ -977,7 +977,7 @@ class TestMemleakInClass : public TestFixture { "};\n" "\n" "void A::init()\n" - "{ p = new int[10]; }"); + "{ p = new int[10]; }\n"); ASSERT_EQUALS("[test.cpp:9:3]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated. [publicAllocationError]\n" "[test.cpp:3:10]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); @@ -987,7 +987,7 @@ class TestMemleakInClass : public TestFixture { "public:\n" " void init()\n" " { p = new int[10]; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:7]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated. [publicAllocationError]\n" "[test.cpp:3:10]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); @@ -1000,7 +1000,7 @@ class TestMemleakInClass : public TestFixture { "};\n" "\n" "void A::init()\n" - "{ p = new int; }"); + "{ p = new int; }\n"); ASSERT_EQUALS("[test.cpp:9:3]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated. [publicAllocationError]\n" "[test.cpp:3:10]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); @@ -1010,7 +1010,7 @@ class TestMemleakInClass : public TestFixture { "public:\n" " void init()\n" " { p = new int; }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:7]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated. [publicAllocationError]\n" "[test.cpp:3:10]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); @@ -1023,7 +1023,7 @@ class TestMemleakInClass : public TestFixture { "};\n" "\n" "void A::init()\n" - "{ p = malloc(sizeof(int)*10); }"); + "{ p = malloc(sizeof(int)*10); }\n"); ASSERT_EQUALS("[test.cpp:9:3]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated. [publicAllocationError]\n" "[test.cpp:3:10]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); @@ -1033,7 +1033,7 @@ class TestMemleakInClass : public TestFixture { "public:\n" " void init()\n" " { p = malloc(sizeof(int)*10); }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:7]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated. [publicAllocationError]\n" "[test.cpp:3:10]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); } @@ -1047,7 +1047,7 @@ class TestMemleakInClass : public TestFixture { " ~A() { delete [] p; }\n" "};\n" "A::A()\n" - "{ p = new int[10]; }"); + "{ p = new int[10]; }\n"); ASSERT_EQUALS("", errout_str()); check("class A\n" @@ -1057,7 +1057,7 @@ class TestMemleakInClass : public TestFixture { " A()\n" " { p = new int[10]; }\n" " ~A() { delete [] p; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -1069,7 +1069,7 @@ class TestMemleakInClass : public TestFixture { " ~A() { delete p; }\n" "};\n" "A::A()\n" - "{ p = new int; }"); + "{ p = new int; }\n"); ASSERT_EQUALS("", errout_str()); check("class A\n" @@ -1079,7 +1079,7 @@ class TestMemleakInClass : public TestFixture { " A()\n" " { p = new int; }\n" " ~A() { delete p; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); @@ -1091,7 +1091,7 @@ class TestMemleakInClass : public TestFixture { " ~A() { free(p); }\n" "};\n" "A::A()\n" - "{ p = malloc(sizeof(int)*10); }"); + "{ p = malloc(sizeof(int)*10); }\n"); ASSERT_EQUALS("", errout_str()); check("class A\n" @@ -1101,7 +1101,7 @@ class TestMemleakInClass : public TestFixture { " A()\n" " { p = malloc(sizeof(int)*10); }\n" " ~A() { free(p); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1114,7 +1114,7 @@ class TestMemleakInClass : public TestFixture { "public:\n" " A() { a = b = new int[10]; }\n" " ~A() { delete [] a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1131,7 +1131,7 @@ class TestMemleakInClass : public TestFixture { "{\n" " A::pd = new char[12];\n" " delete [] A::pd;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:5]: (warning) Possible leak in public function. The pointer 'pd' is not deallocated before it is allocated. [publicAllocationError]\n", errout_str()); check("class A {\n" @@ -1143,7 +1143,7 @@ class TestMemleakInClass : public TestFixture { " pd = new char[12];\n" " delete [] pd;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:7:9]: (warning) Possible leak in public function. The pointer 'pd' is not deallocated before it is allocated. [publicAllocationError]\n", errout_str()); check("class A {\n" @@ -1157,7 +1157,7 @@ class TestMemleakInClass : public TestFixture { "{\n" " pd = new char[12];\n" " delete [] pd;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:5]: (warning) Possible leak in public function. The pointer 'pd' is not deallocated before it is allocated. [publicAllocationError]\n", errout_str()); } @@ -1173,7 +1173,7 @@ class TestMemleakInClass : public TestFixture { " }\n" "private:\n" " char *a;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class A : public x\n" @@ -1187,7 +1187,7 @@ class TestMemleakInClass : public TestFixture { "{\n" " a = new char[10];\n" " foo(a);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1205,7 +1205,7 @@ class TestMemleakInClass : public TestFixture { "{\n" " rp1 = new TRadioButton(this);\n" " rp2 = new TRadioButton(this);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class TRadioButton { };\n" @@ -1221,7 +1221,7 @@ class TestMemleakInClass : public TestFixture { "{\n" " rp1 = new TRadioButton;\n" " rp2 = new TRadioButton;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:19]: (style) Class 'Foo' is unsafe, 'Foo::rp1' can leak by wrong usage. [unsafeClassCanLeak]\n" "[test.cpp:6:19]: (style) Class 'Foo' is unsafe, 'Foo::rp2' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); @@ -1244,7 +1244,7 @@ class TestMemleakInClass : public TestFixture { "{\n" " delete rp1;\n" " delete rp2;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1266,7 +1266,7 @@ class TestMemleakInClass : public TestFixture { " delete [] str2;\n" " }\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:15]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); check("namespace ns1 {\n" @@ -1290,7 +1290,7 @@ class TestMemleakInClass : public TestFixture { " {\n" " delete [] str2;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:15]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); check("namespace ns1 {\n" @@ -1313,7 +1313,7 @@ class TestMemleakInClass : public TestFixture { "ns1::Fred::~Fred()\n" "{\n" " delete [] str2;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:15]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); check("namespace ns1 {\n" @@ -1338,7 +1338,7 @@ class TestMemleakInClass : public TestFixture { "ns1::ns2::Fred::~Fred()\n" "{\n" " delete [] str2;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:19]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); check("namespace ns1 {\n" @@ -1365,7 +1365,7 @@ class TestMemleakInClass : public TestFixture { "ns1::ns2::ns3::Fred::~Fred()\n" "{\n" " delete [] str2;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:23]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage. [unsafeClassCanLeak]\n", errout_str()); } @@ -1382,7 +1382,7 @@ class TestMemleakInClass : public TestFixture { " C *c;\n" "public:\n" " A() : b(new B()), c(new C(b)) { }\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:9:8]: (style) Class 'A' is unsafe, 'A::b' can leak by wrong usage. [unsafeClassCanLeak]\n" "[test.cpp:10]: (style) Class 'A' is unsafe, 'A::c' can leak by wrong usage.\n", "[test.cpp:9:8]: (style) Class 'A' is unsafe, 'A::b' can leak by wrong usage. [unsafeClassCanLeak]\n", @@ -1404,7 +1404,7 @@ class TestMemleakInClass : public TestFixture { " b = new B();\n" " c = new C(b);\n" " }\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:9:8]: (style) Class 'A' is unsafe, 'A::b' can leak by wrong usage. [unsafeClassCanLeak]\n" "[test.cpp:10]: (style) Class 'A' is unsafe, 'A::c' can leak by wrong usage.\n", "[test.cpp:9:8]: (style) Class 'A' is unsafe, 'A::b' can leak by wrong usage. [unsafeClassCanLeak]\n", @@ -1418,7 +1418,7 @@ class TestMemleakInClass : public TestFixture { "private:\n" " Fred() { a = new int; }\n" " ~Fred() { (delete(a), (a)=NULL); }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1437,7 +1437,7 @@ class TestMemleakInClass : public TestFixture { " ~CData() { if (m_impl) m_impl->Release(); }\n" "private:\n" " CDataImpl *m_impl;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1448,7 +1448,7 @@ class TestMemleakInClass : public TestFixture { "public:\n" " Fred(const Fred &fred) { a = new int; }\n" " ~Fred() { delete a; }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1459,7 +1459,7 @@ class TestMemleakInClass : public TestFixture { "public:\n" " Fred() { a = new int; }\n" " ~Fred();\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1505,7 +1505,7 @@ class TestMemleakInClass : public TestFixture { " if (!p)\n" " p = new int[100];\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -1537,7 +1537,7 @@ class TestMemleakInClass : public TestFixture { "void Tokenizer::deleteTokens(int *tok)\n" "{\n" " delete tok;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Global function @@ -1564,7 +1564,7 @@ class TestMemleakInClass : public TestFixture { "{\n" " deleteTokens(_tokens);\n" " _tokens = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1589,7 +1589,7 @@ class TestMemleakInClass : public TestFixture { "\n" "A::~A() {\n" " delete [] pkt_buffer;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:14:9]: (error) Mismatching allocation and deallocation: A::pkt_buffer [mismatchAllocDealloc]\n", errout_str()); check("struct S {\n" // 5678 @@ -1625,7 +1625,7 @@ class TestMemleakInClass : public TestFixture { " data_ = new char[42];\n" " delete data_;\n" " data_ = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:17:3]: (warning) Possible leak in public function. The pointer 'data_' is not deallocated before it is allocated. [publicAllocationError]\n" "[test.cpp:18:3]: (error) Mismatching allocation and deallocation: Foo::data_ [mismatchAllocDealloc]\n", errout_str()); @@ -1648,7 +1648,7 @@ class TestMemleakInClass : public TestFixture { " data_ = new char[42];\n" " delete data_;\n" " data_ = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:17:3]: (warning) Possible leak in public function. The pointer 'data_' is not deallocated before it is allocated. [publicAllocationError]\n" "[test.cpp:18:3]: (error) Mismatching allocation and deallocation: Foo::data_ [mismatchAllocDealloc]\n", errout_str()); } @@ -1663,7 +1663,7 @@ class TestMemleakInClass : public TestFixture { " ~Fred() { free(s); }\n" " void xy()\n" " { s = malloc(100); }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:9:7]: (warning) Possible leak in public function. The pointer 's' is not deallocated before it is allocated. [publicAllocationError]\n", errout_str()); check("class Fred\n" @@ -1675,7 +1675,7 @@ class TestMemleakInClass : public TestFixture { " { s = malloc(100); }\n" "private:\n" " char *s;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:7:7]: (warning) Possible leak in public function. The pointer 's' is not deallocated before it is allocated. [publicAllocationError]\n", errout_str()); } @@ -1689,7 +1689,7 @@ class TestMemleakInClass : public TestFixture { " ~Fred() { free(s); }\n" " const Fred & operator = (const Fred &f)\n" " { s = malloc(100); }\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:9:7]: (warning) Possible leak in public function. The pointer 's' is not deallocated before it is allocated. [publicAllocationError]\n", errout_str()); } }; @@ -1782,14 +1782,14 @@ class TestMemleakStructMember : public TestFixture { " struct ABC *abc = malloc(sizeof(struct ABC));\n" " abc->a = malloc(10);\n" " free(abc);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5]: (error) Memory leak: abc.a [memleak]\n", errout_str()); check("static void foo()\n" "{\n" " struct ABC *abc = malloc(sizeof(struct ABC));\n" " abc->a = malloc(10);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:1]: (error) Memory leak: abc.a [memleak]\n", errout_str()); check("static ABC * foo()\n" @@ -1802,7 +1802,7 @@ class TestMemleakStructMember : public TestFixture { " return 0;\n" " }\n" " return abc;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:9]: (error) Memory leak: abc.a [memleak]\n", errout_str()); check("static void foo(int a)\n" @@ -1814,7 +1814,7 @@ class TestMemleakStructMember : public TestFixture { " free(abc->a);\n" " return;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:1]: (error) Memory leak: abc.a [memleak]\n", errout_str()); } @@ -1830,7 +1830,7 @@ class TestMemleakStructMember : public TestFixture { "out:\n" " free(abc->a);\n" " free(abc);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1840,13 +1840,13 @@ class TestMemleakStructMember : public TestFixture { " struct ABC *abc = malloc(sizeof(struct ABC));\n" " abc->a = malloc(10);\n" " return abc;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("static void foo(struct ABC *abc)\n" "{\n" " abc->a = malloc(10);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #7302 @@ -1854,14 +1854,14 @@ class TestMemleakStructMember : public TestFixture { " struct ABC abc;\n" " abc.a = malloc(10);\n" " return abc.a;\n" - "}", false); + "}\n", false); ASSERT_EQUALS("", errout_str()); check("void* foo() {\n" " struct ABC abc;\n" " abc.a = malloc(10);\n" " return abc.b;\n" - "}", false); + "}\n", false); ASSERT_EQUALS("[test.c:4:5]: (error) Memory leak: abc.a [memleak]\n", errout_str()); } @@ -1871,7 +1871,7 @@ class TestMemleakStructMember : public TestFixture { " struct ABC *abc = malloc(sizeof(struct ABC));\n" " abc->a = malloc(10);\n" " return &abc->self;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1880,7 +1880,7 @@ class TestMemleakStructMember : public TestFixture { "{\n" " struct ABC *abc = abc1;\n" " abc->a = malloc(10);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("static void foo()\n" @@ -1888,7 +1888,7 @@ class TestMemleakStructMember : public TestFixture { " struct ABC *abc;\n" " abc1 = abc = malloc(sizeof(ABC));\n" " abc->a = malloc(10);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("static void foo()\n" @@ -1897,7 +1897,7 @@ class TestMemleakStructMember : public TestFixture { " ptr = malloc(sizeof(struct msn_entry));\n" " ptr->msn = malloc(100);\n" " back = ptr;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1906,7 +1906,7 @@ class TestMemleakStructMember : public TestFixture { check("static void foo() {\n" " struct ABC *abc = malloc(123);\n" " abc->a = abc->b = malloc(10);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1915,7 +1915,7 @@ class TestMemleakStructMember : public TestFixture { " struct s f2;\n" " f2.a = malloc(100);\n" " *f1 = f2;\n" - "}", false); + "}\n", false); ASSERT_EQUALS("", errout_str()); } @@ -2041,7 +2041,7 @@ class TestMemleakStructMember : public TestFixture { " return 0;\n" " }\n" " return abc;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2052,7 +2052,7 @@ class TestMemleakStructMember : public TestFixture { " struct ABC *abc = malloc(sizeof(struct ABC));\n" " abc->a = malloc(10);\n" " func(abc);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("static void foo()\n" @@ -2060,7 +2060,7 @@ class TestMemleakStructMember : public TestFixture { " struct ABC *abc = malloc(sizeof(struct ABC));\n" " abclist.push_back(abc);\n" " abc->a = malloc(10);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2070,7 +2070,7 @@ class TestMemleakStructMember : public TestFixture { " A a = { 0 };\n" " a.foo = (char *) malloc(10);\n" " assign(&a);\n" - "}", false); + "}\n", false); ASSERT_EQUALS("", errout_str()); } @@ -2080,7 +2080,7 @@ class TestMemleakStructMember : public TestFixture { " struct ABC *abc = malloc(100);\n" " abc.a = (char *) malloc(10);\n" " list_add_tail(&abc->list, head);\n" - "}", false); + "}\n", false); ASSERT_EQUALS("", errout_str()); } @@ -2091,7 +2091,7 @@ class TestMemleakStructMember : public TestFixture { " struct ABC abc;\n" " abc.a = (char *) malloc(10);\n" " a(abc.a);\n" - "}", false); + "}\n", false); ASSERT_EQUALS("", errout_str()); } @@ -2100,14 +2100,14 @@ class TestMemleakStructMember : public TestFixture { " struct s s1;\n" " s1->x = malloc(1);\n" " return (s1);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct nc_rpc nc_rpc_getconfig() {\n" // #10382 " struct nc_rpc rpc;\n" " rpc->filter = malloc(1);\n" " return (nc_rpc)rpc;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("T* f(const char *str) {\n" // #10158 @@ -2154,7 +2154,7 @@ class TestMemleakStructMember : public TestFixture { " S* s = new S();\n" " s->p = new int();\n" " g((void*)s);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2173,7 +2173,7 @@ class TestMemleakStructMember : public TestFixture { " }\n" " free(abc->a);\n" " free(abc);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2189,7 +2189,7 @@ class TestMemleakStructMember : public TestFixture { " free(abc);\n" " abc = next;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2201,7 +2201,7 @@ class TestMemleakStructMember : public TestFixture { " abc = malloc(sizeof(struct ABC));\n" " abc->a = malloc(10);\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2219,7 +2219,7 @@ class TestMemleakStructMember : public TestFixture { " a.f = fopen(\"test\", \"r\");\n" " a.c = new char[12];\n" " a.m = malloc(12);\n" - "}"; + "}\n"; check(code1, true); ASSERT_EQUALS("[test.cpp:12:1]: (error) Resource leak: a.f [resourceLeak]\n" @@ -2244,7 +2244,7 @@ class TestMemleakStructMember : public TestFixture { " fclose(a.f);\n" " delete [] a.c;\n" " free(a.m);\n" - "}"; + "}\n"; check(code2, true); ASSERT_EQUALS("", errout_str()); @@ -2253,7 +2253,7 @@ class TestMemleakStructMember : public TestFixture { const char code3[] = "void func() {\n" " struct A a;\n" " a.f = fopen(\"test\", \"r\");\n" - "}"; + "}\n"; check(code3, true); ASSERT_EQUALS("", errout_str()); @@ -2268,7 +2268,7 @@ class TestMemleakStructMember : public TestFixture { "void func() {\n" " struct A a;\n" " a.f = fopen(\"test\", \"r\");\n" - "}"; + "}\n"; check(code4, true); ASSERT_EQUALS("", errout_str()); @@ -2284,7 +2284,7 @@ class TestMemleakStructMember : public TestFixture { "{\n" " Test& y = *x;\n" " y.data = malloc(10);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2294,7 +2294,7 @@ class TestMemleakStructMember : public TestFixture { "unique_ptrotherbuffer{new char[otherbufsize+1]};\n" "char *const oldbuffer = otherbuffer.get();\n" "int const oldbufsize = otherbufsize;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2307,7 +2307,7 @@ class TestMemleakStructMember : public TestFixture { " (s).state_check_buff = (void* )malloc(1);\n" " if (s.state_check_buff == 0)\n" " return;\n" - "}", false); + "}\n", false); ASSERT_EQUALS("[test.c:9:1]: (error) Memory leak: s.state_check_buff [memleak]\n", errout_str()); } @@ -2317,7 +2317,7 @@ class TestMemleakStructMember : public TestFixture { " foo f;\n" " ((f)->realm) = strdup(realm);\n" " if(f->realm == NULL) {}\n" - "}", false); + "}\n", false); ASSERT_EQUALS("[test.c:6:1]: (error) Memory leak: f.realm [memleak]\n", errout_str()); } @@ -2328,7 +2328,7 @@ class TestMemleakStructMember : public TestFixture { "void func() {\n" " struct ABC abc;\n" " abc.a = myalloc();\n" - "}", false); + "}\n", false); ASSERT_EQUALS("[test.c:7:1]: (error) Memory leak: abc.a [memleak]\n", errout_str()); } @@ -2344,7 +2344,7 @@ class TestMemleakStructMember : public TestFixture { " }\n" " delete[] s.p;\n" " return 0;\n" - "}", true); + "}\n", true); ASSERT_EQUALS("", errout_str()); check( @@ -2425,23 +2425,23 @@ class TestMemleakNoVar : public TestFixture { // standard function.. check("void x() {\n" " strcpy(a, strdup(p));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (error) Allocation with strdup, strcpy doesn't release it. [leakNoVarFunctionCall]\n", errout_str()); check("char *x() {\n" " char *ret = strcpy(malloc(10), \"abc\");\n" " return ret;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("char *x() {\n" " return strcpy(malloc(10), \"abc\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void x() {\n" " free(malloc(10));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // user function.. @@ -2450,7 +2450,7 @@ class TestMemleakNoVar : public TestFixture { "\n" "void x() {\n" " set_error(strdup(p));\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:5:15]: (error) Allocation with strdup, set_error doesn't release it. [leakNoVarFunctionCall]\n", "", errout_str()); check("void f()\n" @@ -2458,68 +2458,68 @@ class TestMemleakNoVar : public TestFixture { " int fd;\n" " fd = mkstemp(strdup(\"/tmp/file.XXXXXXXX\"));\n" " close(fd);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Allocation with strdup, mkstemp doesn't release it.\n", "", errout_str()); check("void f()\n" "{\n" " if(TRUE || strcmp(strdup(a), b));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:23]: (error) Allocation with strdup, strcmp doesn't release it. [leakNoVarFunctionCall]\n", errout_str()); check("void f()\n" "{\n" " if(!strcmp(strdup(a), b) == 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:16]: (error) Allocation with strdup, strcmp doesn't release it. [leakNoVarFunctionCall]\n", errout_str()); check("void f()\n" "{\n" " 42, strcmp(strdup(a), b);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:16]: (error) Allocation with strdup, strcmp doesn't release it. [leakNoVarFunctionCall]\n", errout_str()); check("void f() {\n" " assert(freopen(\"/dev/null\", \"r\", stdin));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void x() {\n" " strcpy(a, (void*)strdup(p));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:22]: (error) Allocation with strdup, strcpy doesn't release it. [leakNoVarFunctionCall]\n", errout_str()); check("void* malloc1() {\n" " return (malloc(1));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("char *x() {\n" " char *ret = (char*)strcpy(malloc(10), \"abc\");\n" " return ret;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " free(malloc(1));\n" " strcpy(a, strdup(p));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:15]: (error) Allocation with strdup, strcpy doesn't release it. [leakNoVarFunctionCall]\n", errout_str()); check("void f() {\n" " memcmp(calloc(10, 10), strdup(q), 100);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (error) Allocation with calloc, memcmp doesn't release it. [leakNoVarFunctionCall]\n" "[test.cpp:2:28]: (error) Allocation with strdup, memcmp doesn't release it. [leakNoVarFunctionCall]\n", errout_str()); check("void* f(int size) {\n" " return (void*) malloc(size);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int* f(int size) {\n" " return static_cast(malloc(size));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() { if (new int[42]) {} }\n" // #10857 @@ -2644,25 +2644,25 @@ class TestMemleakNoVar : public TestFixture { check("void x()\n" "{\n" " malloc(10);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Return value of allocation function 'malloc' is not stored. [leakReturnValNotUsed]\n", errout_str()); check("void x()\n" "{\n" " calloc(10, 1);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Return value of allocation function 'calloc' is not stored. [leakReturnValNotUsed]\n", errout_str()); check("void x()\n" "{\n" " strdup(\"Test\");\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Return value of allocation function 'strdup' is not stored. [leakReturnValNotUsed]\n", errout_str()); check("void x()\n" "{\n" " (char*) malloc(10);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:13]: (error) Return value of allocation function 'malloc' is not stored. [leakReturnValNotUsed]\n", errout_str()); check("void x()\n" @@ -2670,7 +2670,7 @@ class TestMemleakNoVar : public TestFixture { " char* ptr = malloc(10);\n" " foo(ptr);\n" " free(ptr);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f( void ) {\n" // FP: #11246 @@ -2679,19 +2679,19 @@ class TestMemleakNoVar : public TestFixture { " if ( ok )\n" " free( address ), address = 0;\n" " return 0;\n" - "} "); + "} \n"); ASSERT_EQUALS("", errout_str()); check("char** x(const char* str) {\n" " char* ptr[] = { malloc(10), malloc(5), strdup(str) };\n" " return ptr;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void x()\n" "{\n" " 42,malloc(42);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8]: (error) Return value of allocation function 'malloc' is not stored. [leakReturnValNotUsed]\n", errout_str()); check("void *f()\n" @@ -2701,7 +2701,7 @@ class TestMemleakNoVar : public TestFixture { "void x()\n" "{\n" " f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:5]: (error) Return value of allocation function 'f' is not stored. [leakReturnValNotUsed]\n", errout_str()); check("void f()\n" // #8100 @@ -2711,7 +2711,7 @@ class TestMemleakNoVar : public TestFixture { "void x()\n" "{\n" " f();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void *f() {\n" // #8848 @@ -2720,26 +2720,26 @@ class TestMemleakNoVar : public TestFixture { "void x()\n" "{\n" " f();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void x()\n" "{\n" " if(!malloc(5)) fail();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9]: (error) Return value of allocation function 'malloc' is not stored. [leakReturnValNotUsed]\n", errout_str()); check("FOO* factory() {\n" " FOO* foo = new (std::nothrow) FOO;\n" " return foo;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Ticket #6536 check("struct S { S(int) {} };\n" "void foo(int i) {\n" " S socket(i);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Ticket #6693 @@ -2749,12 +2749,12 @@ class TestMemleakNoVar : public TestFixture { "};\n" "void CTest::Initialise() {\n" " malloc();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" // #7348 - cast " p = (::X*)malloc(42);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #7182 "crash: CheckMemoryLeak::functionReturnType()" @@ -2762,7 +2762,7 @@ class TestMemleakNoVar : public TestFixture { "template auto binary_left_comma (T x, Ts... ts) { return (x , ... , ts); }\n" "int main() {\n" " unary_right_comma (a);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -2778,7 +2778,7 @@ class TestMemleakNoVar : public TestFixture { " new int{};\n" " new int{ 1 };\n" " new uint8_t[4];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (error) Return value of allocation function 'new' is not stored. [leakReturnValNotUsed]\n" "[test.cpp:3:5]: (error) Return value of allocation function 'new' is not stored. [leakReturnValNotUsed]\n" "[test.cpp:4:5]: (error) Return value of allocation function 'new' is not stored. [leakReturnValNotUsed]\n" @@ -2796,7 +2796,7 @@ class TestMemleakNoVar : public TestFixture { check("void f(int* p) {\n" " new auto('c');\n" " new(p) int;\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:1:29]: (error) Return value of allocation function 'new' is not stored. [leakReturnValNotUsed]\n" "[test.cpp:3]: (error) Return value of allocation function 'new' is not stored.\n", "", @@ -2833,7 +2833,7 @@ class TestMemleakNoVar : public TestFixture { " C{ new int(1), 1 };\n" " C{ new(p) int, 1 };\n" " C{ new QWidget, 1 };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool b) { if (b && malloc(42)) {} }\n" // // #10858 @@ -2896,54 +2896,54 @@ class TestMemleakNoVar : public TestFixture { void smartPointerFunctionParam() { check("void x() {\n" " f(shared_ptr(new int(42)), g());\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning, inconclusive) Unsafe allocation. If g() throws, memory could be leaked. Use make_shared() instead. [leakUnsafeArgAlloc]\n", errout_str()); check("void x() {\n" " h(12, f(shared_ptr(new int(42)), g()));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (warning, inconclusive) Unsafe allocation. If g() throws, memory could be leaked. Use make_shared() instead. [leakUnsafeArgAlloc]\n", errout_str()); check("void x() {\n" " f(unique_ptr(new int(42)), g());\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning, inconclusive) Unsafe allocation. If g() throws, memory could be leaked. Use make_unique() instead. [leakUnsafeArgAlloc]\n", errout_str()); check("void x() {\n" " f(g(), shared_ptr(new int(42)));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning, inconclusive) Unsafe allocation. If g() throws, memory could be leaked. Use make_shared() instead. [leakUnsafeArgAlloc]\n", errout_str()); check("void x() {\n" " f(g(), unique_ptr(new int(42)));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning, inconclusive) Unsafe allocation. If g() throws, memory could be leaked. Use make_unique() instead. [leakUnsafeArgAlloc]\n", errout_str()); check("void x() {\n" " f(shared_ptr(new char), make_unique(32));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning, inconclusive) Unsafe allocation. If make_unique() throws, memory could be leaked. Use make_shared() instead. [leakUnsafeArgAlloc]\n", errout_str()); check("void x() {\n" " f(g(124), h(\"test\", 234), shared_ptr(new char));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning, inconclusive) Unsafe allocation. If h() throws, memory could be leaked. Use make_shared() instead. [leakUnsafeArgAlloc]\n", errout_str()); check("void x() {\n" " f(shared_ptr(new std::string(\"\")), g());\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning, inconclusive) Unsafe allocation. If g() throws, memory could be leaked. Use make_shared() instead. [leakUnsafeArgAlloc]\n", errout_str()); check("void g(int x) throw() { }\n" "void x() {\n" " f(g(124), shared_ptr(new char));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void __declspec(nothrow) g(int x) { }\n" "void x() {\n" " f(g(124), shared_ptr(new char));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void resourceLeak() { @@ -2954,23 +2954,23 @@ class TestMemleakNoVar : public TestFixture { " if (result) return !result;\n" " fclose(fp);\n" " return result;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " fopen(\"file.txt\", \"r\");\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:3]: (error) Return value of allocation function 'fopen' is not stored. [leakReturnValNotUsed]\n", errout_str()); check("void foo() {\n" " FILE *f = fopen(\"file.txt\", \"r\");\n" " freopen(\"file.txt\", \"r\", f);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:3]: (error) Return value of allocation function 'freopen' is not stored. [leakReturnValNotUsed]\n", errout_str()); check("void foo() {\n" " freopen(\"file.txt\", \"r\", stdin);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct Holder {\n" @@ -2980,7 +2980,7 @@ class TestMemleakNoVar : public TestFixture { "};\n" "void foo() {\n" " Holder h ( fopen(\"file.txt\", \"r\"));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct Holder {\n" @@ -2990,7 +2990,7 @@ class TestMemleakNoVar : public TestFixture { "};\n" "void foo() {\n" " Holder ( fopen(\"file.txt\", \"r\"));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct Holder {\n" @@ -3000,7 +3000,7 @@ class TestMemleakNoVar : public TestFixture { "};\n" "void foo() {\n" " Holder h { fopen(\"file.txt\", \"r\")};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct Holder {\n" @@ -3010,7 +3010,7 @@ class TestMemleakNoVar : public TestFixture { "};\n" "void foo() {\n" " Holder h = fopen(\"file.txt\", \"r\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct Holder {\n" @@ -3020,7 +3020,7 @@ class TestMemleakNoVar : public TestFixture { "};\n" "void foo() {\n" " Holder { fopen(\"file.txt\", \"r\")};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct Holder {\n" @@ -3030,7 +3030,7 @@ class TestMemleakNoVar : public TestFixture { "};\n" "void foo() {\n" " Holder { 0, fopen(\"file.txt\", \"r\")};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3041,7 +3041,7 @@ class TestMemleakNoVar : public TestFixture { "\n" "void f() {\n" " makeThing();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #10631 @@ -3068,12 +3068,12 @@ class TestMemleakNoVar : public TestFixture { void crash1() { // #10729 check("void foo() {\n" " extern void *realloc (void *ptr, size_t size);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " extern void *malloc (size_t size);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index c1bf766b8bb..81c44d58811 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -228,7 +228,7 @@ class TestNullPointer : public TestFixture { "{\n" " while (tok);\n" " tok = tok->next();\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:3:12] -> [test.cpp:4:11]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok. [nullPointerRedundantCheck]\n", errout_str()); // #2681 @@ -253,7 +253,7 @@ class TestNullPointer : public TestFixture { " while (tok && tok->str() != \";\")\n" " tok = tok->next();\n" " }\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (warning) Either the condition 'while' is redundant or there is possible null pointer dereference: tok.\n", "", errout_str()); check("void foo(Token &tok)\n" @@ -263,7 +263,7 @@ class TestNullPointer : public TestFixture { " while (!tok)\n" " char c = tok.read();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" @@ -274,7 +274,7 @@ class TestNullPointer : public TestFixture { " tok = tok->next();\n" " if( !tok ) break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" @@ -284,7 +284,7 @@ class TestNullPointer : public TestFixture { " while (tok && tok->str() != \";\")\n" " tok = tok->next();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(A*a)\n" @@ -299,7 +299,7 @@ class TestNullPointer : public TestFixture { " a->b();\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // dereference in outer scope.. @@ -308,7 +308,7 @@ class TestNullPointer : public TestFixture { " while (tok) tok = tok->next();\n" " }\n" " tok->str();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:16] -> [test.cpp:5:5]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok. [nullPointerRedundantCheck]\n", errout_str()); check("int foo(const Token *tok)\n" @@ -333,7 +333,7 @@ class TestNullPointer : public TestFixture { " while (d && d->i == 0)\n" " d = d->c;\n" " if (!d) throw;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct b {\n" @@ -358,7 +358,7 @@ class TestNullPointer : public TestFixture { " }\n" " else if (a->x == 2) { }\n" " if (a) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // ticket #2134 - sizeof doesn't dereference @@ -368,7 +368,7 @@ class TestNullPointer : public TestFixture { " sizeof(*list);\n" " if (!list)\n" " ;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); // ticket #2245 - sizeof doesn't dereference @@ -376,7 +376,7 @@ class TestNullPointer : public TestFixture { " if (!p) {\n" " int sz = sizeof(p->x);\n" " }\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -388,7 +388,7 @@ class TestNullPointer : public TestFixture { " Fred fred;\n" " while (fred);\n" " fred.hello();\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -404,7 +404,7 @@ class TestNullPointer : public TestFixture { " int a = abc->a;\n" " if (!abc)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:13]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(struct ABC *abc) {\n" @@ -413,7 +413,7 @@ class TestNullPointer : public TestFixture { " bar(x, y, abc->a);\n" " if (!abc)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:2:9]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n" "[test.cpp:5:9] -> [test.cpp:3:12]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n" "[test.cpp:5:9] -> [test.cpp:4:15]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); @@ -423,7 +423,7 @@ class TestNullPointer : public TestFixture { " return;\n" " }\n" " if (abc) {}\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:5:9] -> [test.cpp:2:9]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); @@ -433,7 +433,7 @@ class TestNullPointer : public TestFixture { " return;\n" " }\n" " if (!abc);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:2:9]: (warning) Either the condition '!abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); // TODO: False negative if member of member is dereferenced @@ -441,14 +441,14 @@ class TestNullPointer : public TestFixture { " abc->next->a = 0;\n" " if (abc->next)\n" " ;\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Possible null pointer dereference: abc - otherwise it is redundant to check it against null.\n", "", errout_str()); check("void foo(ABC *abc) {\n" " abc->a = 0;\n" " if (abc && abc->b == 0)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:9] -> [test.cpp:2:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); @@ -459,13 +459,13 @@ class TestNullPointer : public TestFixture { " if (abc && abc->a);\n" " if (!abc)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(struct ABC *abc) {\n" " int x = abc && a(abc->x);\n" " if (abc) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // ok to use a linked list.. @@ -474,13 +474,13 @@ class TestNullPointer : public TestFixture { " abc = abc->next;\n" " if (!abc)\n" " ;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void f(struct ABC *abc) {\n" " abc = (ABC *)(abc->_next);\n" - " if (abc) { }" - "}", dinit(CheckOptions, $.inconclusive = true)); + " if (abc) { }\n" + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); // reassign struct.. @@ -490,7 +490,7 @@ class TestNullPointer : public TestFixture { " abc = abc->next;\n" " if (!abc)\n" " ;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void foo(struct ABC *abc)\n" @@ -499,7 +499,7 @@ class TestNullPointer : public TestFixture { " f(&abc);\n" " if (!abc)\n" " ;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); // goto.. @@ -513,7 +513,7 @@ class TestNullPointer : public TestFixture { "out:\n" " if (!abc)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // loops.. @@ -527,7 +527,7 @@ class TestNullPointer : public TestFixture { " --a;\n" " }\n" " while (a > 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" @@ -539,7 +539,7 @@ class TestNullPointer : public TestFixture { " if (!tok)\n" " return;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // dynamic_cast.. @@ -548,7 +548,7 @@ class TestNullPointer : public TestFixture { " int a = abc->a;\n" " if (!dynamic_cast(abc))\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #2641 - global pointer, function call @@ -557,14 +557,14 @@ class TestNullPointer : public TestFixture { " abc->a = 0;\n" " do_stuff();\n" " if (abc) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("",errout_str()); check("Fred *fred;\n" "void f() {\n" " fred->foo();\n" " if (fred) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("",errout_str()); // #2641 - local pointer, function call @@ -573,7 +573,7 @@ class TestNullPointer : public TestFixture { " abc->a = 0;\n" " do_stuff();\n" " if (abc) { }\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:5:9] -> [test.cpp:3:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); @@ -583,7 +583,7 @@ class TestNullPointer : public TestFixture { " abc->a = 0;\n" " do_stuff();\n" " if (abc) { }\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:9] -> [test.cpp:2:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); @@ -598,32 +598,32 @@ class TestNullPointer : public TestFixture { " if ( abc ) {}\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #3128 check("void f(ABC *abc) {\n" " x(!abc || y(abc->a));\n" " if (abc) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(ABC *abc) {\n" " x(def || !abc || y(def, abc->a));\n" " if (abc) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(ABC *abc) {\n" " x(abc && y(def, abc->a));\n" " if (abc) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(ABC *abc) {\n" " x(def && abc && y(def, abc->a));\n" " if (abc) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #3228 - calling function with null object @@ -631,7 +631,7 @@ class TestNullPointer : public TestFixture { const char code[] = "void f(Fred *fred) {\n" " fred->x();\n" " if (fred) { }\n" - "}"; + "}\n"; check(code); ASSERT_EQUALS( "[test.cpp:3:9] -> [test.cpp:2:5]: (warning) Either the condition 'fred' is redundant or there is possible null pointer dereference: fred. [nullPointerRedundantCheck]\n", @@ -643,7 +643,7 @@ class TestNullPointer : public TestFixture { "void f(struct FRED *fred) {\n" " fred->x = 0;\n" " IF(!fred){}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -651,7 +651,7 @@ class TestNullPointer : public TestFixture { " if (!buffer)\n" " uv_fatal_error();\n" " buffer->x = 11;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -665,14 +665,14 @@ class TestNullPointer : public TestFixture { " *p = 0;\n" " if (!p)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(int *p)\n" "{\n" " *p = 0;\n" " if (p) { }\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:9] -> [test.cpp:3:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); @@ -681,7 +681,7 @@ class TestNullPointer : public TestFixture { "{\n" " *p = 0;\n" " if (p || q) { }\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:9] -> [test.cpp:3:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); @@ -691,7 +691,7 @@ class TestNullPointer : public TestFixture { " bar(*p);\n" " if (!p)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:10]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(char *p)\n" @@ -699,14 +699,14 @@ class TestNullPointer : public TestFixture { " strcpy(p, \"abc\");\n" " if (!p)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:12]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(char *p)\n" "{\n" " if (*p == 0) { }\n" " if (!p) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:10]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // no error @@ -716,7 +716,7 @@ class TestNullPointer : public TestFixture { " f(&p);\n" " if (!p)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" @@ -724,7 +724,7 @@ class TestNullPointer : public TestFixture { " int **p = f();\n" " if (!p)\n" " ;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void foo(int *p)\n" @@ -735,7 +735,7 @@ class TestNullPointer : public TestFixture { " *p = 0;\n" " if (!p)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int x)\n" @@ -743,7 +743,7 @@ class TestNullPointer : public TestFixture { " int a = 2 * x;" " if (x == 0)\n" " ;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void foo(int *p)\n" @@ -751,7 +751,7 @@ class TestNullPointer : public TestFixture { " int var1 = p ? *p : 0;\n" " if (!p)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int *p, bool x)\n" @@ -759,7 +759,7 @@ class TestNullPointer : public TestFixture { " int var1 = x ? *p : 5;\n" " if (!p)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:9] -> [test.cpp:3:21]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); @@ -768,13 +768,13 @@ class TestNullPointer : public TestFixture { check("void f(int *p) {\n" " *p = 0;\n" " while (p) { p = 0; }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int *p) {\n" " *p = 0;\n" " while (p) { }\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:12] -> [test.cpp:2:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); @@ -785,7 +785,7 @@ class TestNullPointer : public TestFixture { " int var1 = p ? (p->a) : 0;\n" " if (!p)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(ABC *p)\n" @@ -793,7 +793,7 @@ class TestNullPointer : public TestFixture { " int var1 = p ? (1 + p->a) : 0;\n" " if (!p)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -825,7 +825,7 @@ class TestNullPointer : public TestFixture { " break;\n" " else\n" " p = p->next();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(Document *doc) {\n" @@ -833,27 +833,27 @@ class TestNullPointer : public TestFixture { " if (!doc) {\n" " return;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #3128 - false positive check("void f(int *p) {\n" " assert(!p || (*p<=6));\n" " if (p) { *p = 0; }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int *p) {\n" " assert(p && (*p<=6));\n" " if (p) { *p = 0; }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int *p) {\n" " *p = 12;\n" " assert(p && (*p<=6));\n" " if (p) { *p = 0; }\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:12] -> [test.cpp:2:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); @@ -863,7 +863,7 @@ class TestNullPointer : public TestFixture { " p = p->next;\n" " if (!p)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(x *p)\n" @@ -871,7 +871,7 @@ class TestNullPointer : public TestFixture { " p = bar(p->next);\n" " if (!p)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(x *p)\n" @@ -879,7 +879,7 @@ class TestNullPointer : public TestFixture { " p = aa->bar(p->next);\n" " if (!p)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(x *p)\n" @@ -887,7 +887,7 @@ class TestNullPointer : public TestFixture { " p = *p2 = p->next;\n" " if (!p)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(struct ABC *abc)\n" @@ -895,32 +895,32 @@ class TestNullPointer : public TestFixture { " abc = abc ? abc->next : 0;\n" " if (!abc)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(struct ABC *abc) {\n" // #4523 " abc = (*abc).next;\n" " if (abc) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(struct ABC *abc) {\n" // #4523 " abc = (*abc->ptr);\n" " if (abc) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(Item *item) {\n" " x = item ? ab(item->x) : 0;\n" " if (item) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(Item *item) {\n" " item->x = 0;\n" " a = b ? c : d;\n" " if (item) { }\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:9] -> [test.cpp:2:5]: (warning) Either the condition 'item' is redundant or there is possible null pointer dereference: item. [nullPointerRedundantCheck]\n", errout_str()); @@ -934,7 +934,7 @@ class TestNullPointer : public TestFixture { "\n" " if( !pFrm )\n" " return FALSE;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Ticket #2463 @@ -954,7 +954,7 @@ class TestNullPointer : public TestFixture { " break;\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #2525 - sizeof @@ -963,26 +963,26 @@ class TestNullPointer : public TestFixture { " int c = sizeof(test[0]);\n" " if (!test)\n" " ;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void f(type* p) {\n" // #4983 " x(sizeof p[0]);\n" " if (!p)\n" " ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #3023 - checked deref check("void f(struct ABC *abc) {\n" " WARN_ON(!abc || abc->x == 0);\n" " if (!abc) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(struct ABC *abc) {\n" " WARN_ON(!abc || abc->x == 7);\n" " if (!abc) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #3425 - false positives when there are macros @@ -990,14 +990,14 @@ class TestNullPointer : public TestFixture { "void f(int *p) {\n" " *p = 0;\n" " IF(!p){}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" // #3914 - false positive " int *p;\n" " ((p=ret()) && (x=*p));\n" " if (p);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct S { struct T { char c; } *p; };\n" // #6541 @@ -1021,7 +1021,7 @@ class TestNullPointer : public TestFixture { " char c = a.c();\n" " if (!a)\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1036,18 +1036,18 @@ class TestNullPointer : public TestFixture { " } else { if (a == 2) {\n" " p = new FooCar; } }\n" " p->abcd();\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:8]: (error) Possible null pointer dereference: p\n", "", errout_str()); check("static void foo() {\n" " int &r = *(int*)0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); check("static void foo(int x) {\n" " int y = 5 + *(int*)0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:18]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); { @@ -1062,7 +1062,7 @@ class TestNullPointer : public TestFixture { check("static void foo() {\n" " std::cout << *(int*)0;" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:19]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); check("void f()\n" @@ -1072,12 +1072,12 @@ class TestNullPointer : public TestFixture { " delete c;\n" " }\n" " c[0] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:5]: (error) Null pointer dereference: c [nullPointer]\n", errout_str()); check("static void foo() {\n" " if (3 > *(int*)0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (error) Null pointer dereference: (int*)0 [nullPointer]\n", errout_str()); // no false positive.. @@ -1086,20 +1086,20 @@ class TestNullPointer : public TestFixture { " Foo *p = 0;\n" " p = new Foo;\n" " p->abcd();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" " int sz = sizeof((*(struct dummy *)0).x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void get_offset(long &offset)\n" "{\n" " mystruct * temp; temp = 0;\n" " offset = (long)(&(temp->z));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Ticket #1893 - try/catch inside else @@ -1118,7 +1118,7 @@ class TestNullPointer : public TestFixture { " }\n" " *Q=1;\n" " return Q;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int *test(int *Z)\n" @@ -1134,7 +1134,7 @@ class TestNullPointer : public TestFixture { " }\n" " *Q=1;\n" " return Q;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:12:6]: (warning) Possible null pointer dereference: Q [nullPointer]\n", errout_str()); // Ticket #2052 (false positive for 'else continue;') @@ -1145,7 +1145,7 @@ class TestNullPointer : public TestFixture { " else continue;\n" " *p = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // function pointer.. @@ -1154,7 +1154,7 @@ class TestNullPointer : public TestFixture { " void (*f)();\n" " f = 0;\n" " f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5]: (error) Null pointer dereference: f [nullPointer]\n", errout_str()); check("int* g();\n" // #11007 @@ -1172,7 +1172,7 @@ class TestNullPointer : public TestFixture { " for (int i = 0; i < 10; ++i) {\n" " int x = *p + 1;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:18]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("void f(int a) {\n" @@ -1183,21 +1183,21 @@ class TestNullPointer : public TestFixture { " for (int i = 0; i < 3; i++) {\n" " if (a && (p[i] == '1'));\n" " }\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); // ticket #2251: taking the address of member check("void f() {\n" " Fred *fred = 0;\n" " int x = &fred->x;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); // ticket #3220: dereferencing a null pointer is UB check("void f() {\n" " Fred *fred = NULL;\n" " fred->do_something();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Null pointer dereference: fred [nullPointer]\n", errout_str()); // ticket #3570 - parsing of conditions @@ -1207,21 +1207,21 @@ class TestNullPointer : public TestFixture { " if (x)\n" " p = q;\n" " if (p && *p) { }\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int *p = NULL;\n" " if (x)\n" " p = q;\n" " if (!p || *p) { }\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int *p = NULL;\n" " if (x)\n" " p = q;\n" " if (p || *p) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:15]: (warning) Possible null pointer dereference: p [nullPointer]\n", errout_str()); } @@ -1237,7 +1237,7 @@ class TestNullPointer : public TestFixture { "\n" "void g() {\n" " f(NULL, NULL);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -1262,7 +1262,7 @@ class TestNullPointer : public TestFixture { " for (int i = 0; i < n; i++) {\n" " argv32[i] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // No false negative: @@ -1277,7 +1277,7 @@ class TestNullPointer : public TestFixture { " for (int i = 0; i < n; i++) {\n" " argv32[i] = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:9]: (warning) Possible null pointer dereference: argv32 [nullPointer]\n", errout_str()); // #2231 - error if assignment in loop is not used @@ -1293,7 +1293,7 @@ class TestNullPointer : public TestFixture { " }\n" "\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:11:6]: (warning) Possible null pointer dereference: p [nullPointer]\n", errout_str()); } @@ -1302,7 +1302,7 @@ class TestNullPointer : public TestFixture { "{\n" " wxLongLong x = 0;\n" " int y = x.GetValue();\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -1311,7 +1311,7 @@ class TestNullPointer : public TestFixture { "{\n" " std::string * x = 0;\n" " *x = \"test\";\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:4]: (error) Null pointer dereference: x [nullPointer]\n", errout_str()); } @@ -1321,7 +1321,7 @@ class TestNullPointer : public TestFixture { "{\n" " struct my_type* p = 0;\n" " p->x = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:3]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); } @@ -1333,7 +1333,7 @@ class TestNullPointer : public TestFixture { " struct my_type* p;\n" " p = 0;\n" " return p->x;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:10]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); } @@ -1360,7 +1360,7 @@ class TestNullPointer : public TestFixture { " char *p = 0;\n" " if (x) p = \"abcd\";\n" " return p ? f(*p) : f(0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1369,7 +1369,7 @@ class TestNullPointer : public TestFixture { " int *p = 0;\n" " bar(&p);\n" " *p = 0;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -1378,14 +1378,14 @@ class TestNullPointer : public TestFixture { " int *p = 0;\n" " if (x) { return 0; }\n" " return !p || *p;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("int foo() {\n" " int *p = 0;\n" " if (x) { return 0; }\n" " return p && *p;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -1398,14 +1398,14 @@ class TestNullPointer : public TestFixture { " {\n" " i++;\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:10]: (error) Null pointer dereference: str [nullPointer]\n", errout_str()); } void nullpointer19() { // #3811 check("int foo() {\n" " perror(0);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -1414,14 +1414,14 @@ class TestNullPointer : public TestFixture { " struct xy *p = 0;\n" " if (x) p = q;\n" " if (p ? p->x || p->y : 0) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" // false negative " struct xy *p = 0;\n" " if (x) p = q;\n" " if (y ? p->x : p->y) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:13]: (warning) Possible null pointer dereference: p [nullPointer]\n" "[test.cpp:4:20]: (warning) Possible null pointer dereference: p [nullPointer]\n", errout_str()); @@ -1433,7 +1433,7 @@ class TestNullPointer : public TestFixture { " if (x) p = q;\n" " else return;\n" " *p = 0;\n" // <- p is not NULL - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1442,7 +1442,7 @@ class TestNullPointer : public TestFixture { " char *c = NULL;\n" " char cBuf[10];\n" " sprintf(cBuf, \"%s\", c ? c : \"0\" );\n" - "}"); + "}\n"); ASSERT_EQUALS("",errout_str()); } @@ -1451,7 +1451,7 @@ class TestNullPointer : public TestFixture { " char *c = NULL;\n" " x = c = new char[10];\n" " *c = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1461,7 +1461,7 @@ class TestNullPointer : public TestFixture { " int *array = NULL;\n" " if (data == 1 && array[i] == 0)\n" " std::cout << \"test\";\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:22]: (error) Null pointer dereference: array [nullPointer]\n", errout_str()); } @@ -1478,7 +1478,7 @@ class TestNullPointer : public TestFixture { " if (t2 && (!t1))\n" " return 0.0;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1492,7 +1492,7 @@ class TestNullPointer : public TestFixture { " pointer_=NULL;\n" " *pointer_=0;\n" " return *this;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:6]: (error) Null pointer dereference: pointer_ [nullPointer]\n", errout_str()); } @@ -1502,7 +1502,7 @@ class TestNullPointer : public TestFixture { " int i = s ? s->value + 1\n" " : s->value - 1; // <-- null ptr dereference\n" " return i;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:11] -> [test.cpp:4:15]: (warning) Either the condition 's' is redundant or there is possible null pointer dereference: s. [nullPointerRedundantCheck]\n", errout_str()); @@ -1553,7 +1553,7 @@ class TestNullPointer : public TestFixture { " }\n" "\n" " (void)f->x;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -1665,7 +1665,7 @@ class TestNullPointer : public TestFixture { "void f(struct A *a) {\n" " if (a->x == NULL) {}\n" " *(a->x);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:14] -> [test.cpp:4:8]: (warning) Either the condition 'a->x==NULL' is redundant or there is possible null pointer dereference: a->x. [nullPointerRedundantCheck]\n", errout_str()); @@ -1676,7 +1676,7 @@ class TestNullPointer : public TestFixture { "void f(struct A *a) {\n" " if (a->x == nullptr) {}\n" " *(a->x);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:14] -> [test.cpp:4:8]: (warning) Either the condition 'a->x==nullptr' is redundant or there is possible null pointer dereference: a->x. [nullPointerRedundantCheck]\n", errout_str()); @@ -1687,7 +1687,7 @@ class TestNullPointer : public TestFixture { "void f(struct A *a) {\n" " if (a->g() == nullptr) {}\n" " *(a->g());\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:16] -> [test.cpp:4:11]: (warning) Either the condition 'a->g()==nullptr' is redundant or there is possible null pointer dereference: a->g(). [nullPointerRedundantCheck]\n", errout_str()); @@ -1696,7 +1696,7 @@ class TestNullPointer : public TestFixture { "void f(struct A *a) {\n" " if (a->g() == nullptr) {}\n" " *(a->g());\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1705,7 +1705,7 @@ class TestNullPointer : public TestFixture { "void f(struct A *a) {\n" " if (a->g() == nullptr) {}\n" " *(a->g());\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:16] -> [test.cpp:4:11]: (warning) Either the condition 'a->g()==nullptr' is redundant or there is possible null pointer dereference: a->g(). [nullPointerRedundantCheck]\n", errout_str()); @@ -1718,7 +1718,7 @@ class TestNullPointer : public TestFixture { " if (x) {\n" " (void)*a->x;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1730,7 +1730,7 @@ class TestNullPointer : public TestFixture { " if ( w == 0.0 )\n" " return 0;\n" " return b->get();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9423 check("extern F* GetF();\n" @@ -1747,7 +1747,7 @@ class TestNullPointer : public TestFixture { " if (!lPtrOk)\n" " return;\n" " lPtr->Clear();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1764,7 +1764,7 @@ class TestNullPointer : public TestFixture { " g();\n" " a d = *c->b();\n" " return d;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct a {\n" @@ -1780,7 +1780,7 @@ class TestNullPointer : public TestFixture { " e();\n" " a d = *c->b();\n" " return d;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1788,7 +1788,7 @@ class TestNullPointer : public TestFixture { check("void f() {\n" " char* p = new(std::nothrow) char[1];\n" " if( p ) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1797,7 +1797,7 @@ class TestNullPointer : public TestFixture { " if(!p[0]) {}\n" " const int *const a = p;\n" " if(!a){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7] -> [test.cpp:2:8]: (warning) Either the condition '!a' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); } @@ -1806,7 +1806,7 @@ class TestNullPointer : public TestFixture { "auto f(T& x) -> decltype(x);\n" "int& g(int* x) {\n" " return f(*x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1816,7 +1816,7 @@ class TestNullPointer : public TestFixture { " if(n > 10) q = p;\n" " *p +=2;\n" " if(n < 120) *q+=12;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:18]: (warning) Possible null pointer dereference: q [nullPointer]\n", errout_str()); check("void f(int *p, int n) {\n" @@ -1824,7 +1824,7 @@ class TestNullPointer : public TestFixture { " if(n > 10) q = p;\n" " *p +=2;\n" " if(n > 10) *q+=12;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1838,7 +1838,7 @@ class TestNullPointer : public TestFixture { " }\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:8] -> [test.cpp:6:18]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); @@ -1854,7 +1854,7 @@ class TestNullPointer : public TestFixture { " if (c(e, \"\"))\n" " return nullptr;\n" " return e->b();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1864,7 +1864,7 @@ class TestNullPointer : public TestFixture { " if(b) c = b;\n" " if (!c) c = &a;\n" " return *c;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(int a, int* b) {\n" @@ -1873,7 +1873,7 @@ class TestNullPointer : public TestFixture { " bool d = !c;\n" " if (d) c = &a;\n" " return *c;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { int* x; };\n" @@ -1883,7 +1883,7 @@ class TestNullPointer : public TestFixture { " if(b) c.x = b;\n" " if (!c.x) c.x = &a;\n" " return *c.x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { int* x; };\n" @@ -1894,7 +1894,7 @@ class TestNullPointer : public TestFixture { " bool d = !c.x;\n" " if (d) c.x = &a;\n" " return *c.x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { int* x; };\n" @@ -1917,7 +1917,7 @@ class TestNullPointer : public TestFixture { "}\n" "void bar() {\n" " f(0, 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning) Possible null pointer dereference: params [nullPointer]\n", errout_str()); } @@ -1933,7 +1933,7 @@ class TestNullPointer : public TestFixture { "int bar() {\n" " int **array = NULL;\n" " foo (array, 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1943,7 +1943,7 @@ class TestNullPointer : public TestFixture { " while (tok3->astParent() && tok3->str() == \",\")\n" " tok3 = tok3->astParent();\n" " if (tok3 && tok3->str() == \"(\") {}\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:5:9] -> [test.cpp:3:12]: (warning) Either the condition 'tok3' is redundant or there is possible null pointer dereference: tok3. [nullPointerRedundantCheck]\n", errout_str()); @@ -1956,7 +1956,7 @@ class TestNullPointer : public TestFixture { " }\n" " if (!t1 || !t2)\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(int* i);\n" @@ -1964,7 +1964,7 @@ class TestNullPointer : public TestFixture { " while(f(i) && *i == 0)\n" " i++;\n" " if (!i) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1976,7 +1976,7 @@ class TestNullPointer : public TestFixture { " ListEntry *prev = NULL;\n" " for (ListEntry *cursor = listHead; cursor != NULL; prev = cursor, cursor = cursor->next) {}\n" " if (prev) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2499,7 +2499,7 @@ class TestNullPointer : public TestFixture { " int *p = 0;\n" " pp = &p;\n" " **pp = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:6]: (error) Null pointer dereference: *pp [nullPointer]\n", errout_str()); } @@ -2735,7 +2735,7 @@ class TestNullPointer : public TestFixture { " }\n" " }\n" " return \"unknown\";\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:7:12] -> [test.cpp:3:7]: (warning) Either the condition 'ctx' is redundant or there is possible null pointer dereference: ctx. [nullPointerRedundantCheck]\n", errout_str()); @@ -2777,7 +2777,7 @@ class TestNullPointer : public TestFixture { " int* myNull = GetThing();\n" " *myNull=42;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: (error) Null pointer dereference: myNull [nullPointer]\n", errout_str()); check("struct foo {\n" @@ -2788,7 +2788,7 @@ class TestNullPointer : public TestFixture { " int* myNull = myFoo.GetThing();\n" " *myNull=42;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:10]: (error) Null pointer dereference: myNull [nullPointer]\n", errout_str()); check("struct T { bool g() const; };\n" @@ -2885,7 +2885,7 @@ class TestNullPointer : public TestFixture { " int * buf = foo(true);\n" " buf[2] = 0;" // << " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:14:9]: (error) Null pointer dereference: buf [nullPointer]\n", errout_str()); } @@ -3113,7 +3113,7 @@ class TestNullPointer : public TestFixture { " int *p{};\n" " int *&r{p};\n" " if (*r) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: (error) Null pointer dereference: r [nullPointer]\n", errout_str()); } @@ -3142,7 +3142,7 @@ class TestNullPointer : public TestFixture { " if (!p)\n" " thunk().g(0);\n" " *p = 1;\n" - "}", + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -3151,13 +3151,13 @@ class TestNullPointer : public TestFixture { check("void f() {\n" " struct X *x = 0;\n" " if (addr == &x->y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " struct X *x = 0;\n" " if (addr == &x->y.z[0]) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkP("typedef int Count;\n" // #10018 @@ -3183,7 +3183,7 @@ class TestNullPointer : public TestFixture { " break;\n" " }\n" " return p;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:7:10]: (warning) Possible null pointer dereference: p [nullPointer]\n", errout_str()); } @@ -3193,7 +3193,7 @@ class TestNullPointer : public TestFixture { " while (*p && nasm_isspace(*p))\n" " p++;\n" " return p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(char* origin) {\n" // #11449 @@ -3208,7 +3208,7 @@ class TestNullPointer : public TestFixture { check("void f () {\n" " int *buf; buf = NULL;\n" " buf;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -3230,27 +3230,27 @@ class TestNullPointer : public TestFixture { " if (!p) {\n" " }\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(char *p) {\n" " if (p && *p == 0) {\n" " }\n" " printf(\"%c\", *p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:19]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(char *p) {\n" " if (p && *p == 0) {\n" " } else { *p = 0; }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:15]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(char *p) {\n" " if (p) {\n" " }\n" " strcpy(p, \"abc\");\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:4:12]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(char *p) {\n" @@ -3258,7 +3258,7 @@ class TestNullPointer : public TestFixture { " }\n" " bar();\n" " strcpy(p, \"abc\");\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:5:12]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("void foo(abc *p) {\n" @@ -3266,7 +3266,7 @@ class TestNullPointer : public TestFixture { " }\n" " else { if (!p->x) {\n" " } }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); { @@ -3276,7 +3276,7 @@ class TestNullPointer : public TestFixture { " abort();\n" " }\n" " *p = 0;\n" - "}"; + "}\n"; check(code); ASSERT_EQUALS("", errout_str()); @@ -3289,7 +3289,7 @@ class TestNullPointer : public TestFixture { " (*bail)();\n" " }\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char *p) {\n" @@ -3297,7 +3297,7 @@ class TestNullPointer : public TestFixture { " throw x;\n" " }\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char *p) {\n" @@ -3305,21 +3305,21 @@ class TestNullPointer : public TestFixture { " ab.abort();\n" " }\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char *p) {\n" " if (!p) {\n" " switch (x) { }\n" " }\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void foo(char *p) {\n" " if (!p) {\n" " }\n" " return *x;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("int foo(int *p) {\n" @@ -3327,7 +3327,7 @@ class TestNullPointer : public TestFixture { " x = *p;\n" " return 5+*p;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:14]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n" "[test.cpp:2:9] -> [test.cpp:4:19]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); @@ -3337,7 +3337,7 @@ class TestNullPointer : public TestFixture { " if (!a) {\n" " a.x();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // This is why this check can't be used on the simplified token list @@ -3345,7 +3345,7 @@ class TestNullPointer : public TestFixture { " if (!dynamic_cast(foo)) {\n" " *foo = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // ticket: #2300 - calling unknown function that may initialize the pointer @@ -3355,7 +3355,7 @@ class TestNullPointer : public TestFixture { " initfred();\n" " fred->x = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // ticket #1219 @@ -3364,7 +3364,7 @@ class TestNullPointer : public TestFixture { " return;\n" " }\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:5:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // #2467 - unknown macro may terminate the application @@ -3373,7 +3373,7 @@ class TestNullPointer : public TestFixture { " MACRO;\n" " }\n" " fred->a();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #2493 - switch @@ -3386,7 +3386,7 @@ class TestNullPointer : public TestFixture { " fred->a();\n" " break;\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #4118 - second if @@ -3394,7 +3394,7 @@ class TestNullPointer : public TestFixture { " int x = 1;\n" " if (!p) x = 0;\n" " if (x) *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #2674 - different functions @@ -3411,7 +3411,7 @@ class TestNullPointer : public TestFixture { "\n" "void Fred::b() {\n" " wilma->Reload();\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void test(int *i) {\n" @@ -3419,7 +3419,7 @@ class TestNullPointer : public TestFixture { " else {\n" " int b = *i;\n" " }\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); // #2696 - false positives nr 1 @@ -3432,7 +3432,7 @@ class TestNullPointer : public TestFixture { "\n" " if (pFoo)\n" " bar();\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); // #2696 - false positives nr 2 @@ -3445,7 +3445,7 @@ class TestNullPointer : public TestFixture { " pFoo = pFoo->next;\n" "\n" " len = sizeof(pFoo->data);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); // #2696 - false positives nr 3 @@ -3458,13 +3458,13 @@ class TestNullPointer : public TestFixture { " pFoo = pFoo->next;\n" "\n" " len = decltype(*pFoo);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("int foo(struct Fred *fred) {\n" " if (fred) { }\n" " return fred->a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:12]: (warning) Either the condition 'fred' is redundant or there is possible null pointer dereference: fred. [nullPointerRedundantCheck]\n", errout_str()); // #2789 - assign and check pointer @@ -3472,7 +3472,7 @@ class TestNullPointer : public TestFixture { " char *p; p = x();\n" " if (!p) { }\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:4:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // check, assign and use @@ -3481,7 +3481,7 @@ class TestNullPointer : public TestFixture { " if (p == 0 && (p = malloc(10)) != 0) {\n" " *p = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // check, assign and use @@ -3490,7 +3490,7 @@ class TestNullPointer : public TestFixture { " if (p == 0 && (p = malloc(10)) != a && (*p = a)) {\n" " *p = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // check, and use @@ -3499,7 +3499,7 @@ class TestNullPointer : public TestFixture { " if (p == 0 && (*p = 0)) {\n" " return;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:3:21]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // check, and use @@ -3508,7 +3508,7 @@ class TestNullPointer : public TestFixture { " if (p == 0 && p->x == 10) {\n" " return;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:3:19]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // check, and use @@ -3517,7 +3517,7 @@ class TestNullPointer : public TestFixture { " if (p == 0 || p->x == 10) {\n" " return;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // check, and use @@ -3526,7 +3526,7 @@ class TestNullPointer : public TestFixture { " if (p == NULL && (*p = a)) {\n" " return;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11] -> [test.cpp:3:24]: (warning) Either the condition 'p==NULL' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // check, and use @@ -3534,14 +3534,14 @@ class TestNullPointer : public TestFixture { " if (!p && x==1 || p && p->x==0) {\n" " return;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); { const char code[] = "void f(Fred *fred) {\n" " if (fred == NULL) { }\n" " fred->x();\n" - "}"; + "}\n"; check(code); // inconclusive ASSERT_EQUALS("[test.cpp:2:14] -> [test.cpp:3:5]: (warning) Either the condition 'fred==NULL' is redundant or there is possible null pointer dereference: fred. [nullPointerRedundantCheck]\n", errout_str()); @@ -3550,52 +3550,52 @@ class TestNullPointer : public TestFixture { check("void f(char *s) {\n" // #3358 " if (s==0);\n" " strcpy(a, s?b:c);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // sizeof check("void f(struct fred_t *fred) {\n" " if (!fred)\n" " int sz = sizeof(fred->x);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); // check in macro check("void f(int *x) {\n" " $if (!x) {}\n" " *x = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // return ?: check("int f(ABC *p) {\n" // FP : return ?: " if (!p) {}\n" " return p ? p->x : 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(ABC *p) {\n" // no fn " if (!p) {}\n" " return q ? p->x : 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9] -> [test.cpp:3:16]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("int f(ABC *p) {\n" // FP : return && " if (!p) {}\n" " return p && p->x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x, int *p) {\n" " if (x || !p) {}\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14] -> [test.cpp:3:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); // sizeof check("void f() {\n" " int *pointer = NULL;\n" " pointer = func(sizeof pointer[0]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct T {\n" // #14164 @@ -3618,12 +3618,12 @@ class TestNullPointer : public TestFixture { check("int f() {\n" " int* p = 0;\n" " return p[4];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:12]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("void f() {\n" " typeof(*NULL) y;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("int * f() {\n" @@ -3631,7 +3631,7 @@ class TestNullPointer : public TestFixture { "}\n" "int main() {\n" " return *f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:12]: (error) Null pointer dereference: f() [nullPointer]\n", errout_str()); } @@ -3639,7 +3639,7 @@ class TestNullPointer : public TestFixture { // Ticket #2621 check("void f(struct ABC *abc) {\n" " ({ if (abc) dbg(); })\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -3647,7 +3647,7 @@ class TestNullPointer : public TestFixture { // Ticket #2840 check("void f() {\n" " int bytes = snprintf(0, 0, \"%u\", 1);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -3655,25 +3655,25 @@ class TestNullPointer : public TestFixture { // Ticket #2840 check("void f() {\n" " int bytes = snprintf(0, 10, \"%u\", 1);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:26]: (error) Null pointer dereference [nullPointer]\n", errout_str()); } void printf_with_invalid_va_argument() { check("void f() {\n" " printf(\"%s\", 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:18]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("void f(char* s) {\n" " printf(\"%s\", s);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " char* s = 0;\n" " printf(\"%s\", s);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:18]: (error) Null pointer dereference: s [nullPointer]\n", errout_str()); @@ -3681,23 +3681,23 @@ class TestNullPointer : public TestFixture { check("void f() {\n" " char *s = 0;\n" " printf(\"%s\", s == 0 ? a : s);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " printf(\"%u%s\", 0, 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:23]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("void f(char* s) {\n" " printf(\"%u%s\", 0, s);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " char* s = 0;\n" " printf(\"%u%s\", 123, s);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:25]: (error) Null pointer dereference: s [nullPointer]\n", errout_str()); @@ -3705,51 +3705,51 @@ class TestNullPointer : public TestFixture { check("void f() {\n" " printf(\"%%%s%%\", 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:22]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("void f(char* s) {\n" " printf(\"text: %s, %s\", s, 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:31]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("void f() {\n" " char* s = \"blabla\";\n" " printf(\"%s\", s);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(char* s) {\n" " printf(\"text: %m%s, %s\", s, 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:33]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("void f(char* s) {\n" " printf(\"text: %*s, %s\", s, 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:32]: (error) Null pointer dereference [nullPointer]\n", errout_str()); // Ticket #3364 check("void f() {\n" " printf(\"%-*.*s\", s, 0);\n" " sprintf(\"%*\", s);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void scanf_with_invalid_va_argument() { check("void f(char* s) {\n" " sscanf(s, \"%s\", 0);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:21]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("void f() {\n" " scanf(\"%d\", 0);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:17]: (error) Null pointer dereference [nullPointer]\n", errout_str()); @@ -3758,19 +3758,19 @@ class TestNullPointer : public TestFixture { " char location[200];\n" " int width, height;\n" " sscanf(imgInfo, \"%s %d %d\", location, &width, &height);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // ticket #3207 check("void f(char *dummy) {\n" " int iVal;\n" " sscanf(dummy, \"%d%c\", &iVal);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // ticket #3211 check("void f(char *dummy) {\n" " int* iVal = 0;\n" " sscanf(dummy, \"%d\", iVal);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:25]: (error) Null pointer dereference: iVal [nullPointer]\n", errout_str()); @@ -3778,18 +3778,18 @@ class TestNullPointer : public TestFixture { check("void f(char *dummy) {\n" " int* iVal;\n" " sscanf(dummy, \"%d\", foo(iVal));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(char *dummy) {\n" " int* iVal = 0;\n" " sscanf(dummy, \"%d%d\", foo(iVal), iVal);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(char* dummy) {\n" " sscanf(dummy, \"%*d%u\", 0);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:28]: (error) Null pointer dereference [nullPointer]\n", errout_str()); @@ -3801,12 +3801,12 @@ class TestNullPointer : public TestFixture { " int* iVal = 0;\n" " if(maybe()) iVal = g();\n" " return iVal[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:12]: (warning) Possible null pointer dereference: iVal [nullPointer]\n", errout_str()); check("int foo(int* iVal) {\n" " return iVal[0];\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -3816,20 +3816,20 @@ class TestNullPointer : public TestFixture { "bool foo() {\n" " PolymorphicA* a = 0;\n" " return typeid(*a) == typeid(*a);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("struct NonPolymorphicA { ~A() {} };\n" "bool foo() {\n" " NonPolymorphicA* a = 0;\n" " return typeid(*a) == typeid(*a);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("bool foo() {\n" " char* c = 0;\n" " return typeid(*c) == typeid(*c);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -3838,40 +3838,40 @@ class TestNullPointer : public TestFixture { check("size_t foo() {\n" " char* c = 0;\n" " return alignof(*c);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("size_t foo() {\n" " return alignof(*0);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void foo(int *p) {\n" " f(alignof(*p));\n" " if (p) {}\n" " return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("size_t foo() {\n" " char* c = 0;\n" " return _Alignof(*c);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("size_t foo() {\n" " return _alignof(*0);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("size_t foo() {\n" " return __alignof(*0);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("size_t foo() {\n" " return __alignof__(*0);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); } @@ -3882,7 +3882,7 @@ class TestNullPointer : public TestFixture { " cnt = 0;\n" " for (int i = 0; i < cnt; ++i)\n" " *ptr++ = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #11635 @@ -3992,7 +3992,7 @@ class TestNullPointer : public TestFixture { "void f(int* x) {\n" " if (x)\n" " g(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct T {\n" // #14308 @@ -4034,7 +4034,7 @@ class TestNullPointer : public TestFixture { " std::string s4 = p;\n" " std::string s5(p);\n" " foo(std::string(p));\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:9:10]: (error) Null pointer dereference: p [nullPointer]\n" "[test.cpp:10:22]: (error) Null pointer dereference: p [nullPointer]\n" "[test.cpp:11:20]: (error) Null pointer dereference: p [nullPointer]\n" @@ -4050,7 +4050,7 @@ class TestNullPointer : public TestFixture { " std::string s2 = nullptr;\n" " std::string s3(nullptr);\n" " foo(std::string(nullptr));\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2:10]: (error) Null pointer dereference [nullPointer]\n" "[test.cpp:3:22]: (error) Null pointer dereference [nullPointer]\n" "[test.cpp:4:17]: (error) Null pointer dereference [nullPointer]\n" @@ -4062,7 +4062,7 @@ class TestNullPointer : public TestFixture { " std::string s2 = NULL;\n" " std::string s3(NULL);\n" " foo(std::string(NULL));\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2:10]: (error) Null pointer dereference [nullPointer]\n" "[test.cpp:3:22]: (error) Null pointer dereference [nullPointer]\n" "[test.cpp:4:17]: (error) Null pointer dereference [nullPointer]\n" @@ -4078,7 +4078,7 @@ class TestNullPointer : public TestFixture { " foo(p == s1);\n" " foo(p == s2);\n" " foo(p == s3);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:4:15]: (error) Null pointer dereference: p [nullPointer]\n" "[test.cpp:5:15]: (error) Null pointer dereference: p [nullPointer]\n" "[test.cpp:7:9]: (error) Null pointer dereference: p [nullPointer]\n" @@ -4093,7 +4093,7 @@ class TestNullPointer : public TestFixture { " foo(s1.size() == 0);\n" " foo(s2.size() == 0);\n" " foo(s3->size() == 0);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void f(std::string s1, const std::string& s2) {\n" @@ -4102,7 +4102,7 @@ class TestNullPointer : public TestFixture { " foo(0 == s2[0]);\n" " foo(s1[0] == 0);\n" " foo(s2[0] == 0);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void f(std::string s1, const std::string& s2) {\n" @@ -4111,7 +4111,7 @@ class TestNullPointer : public TestFixture { " foo(s2 == '\\0');\n" " foo('\\0' == s1);\n" " foo('\\0' == s2);\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("class Bar {\n" @@ -4122,19 +4122,19 @@ class TestNullPointer : public TestFixture { " std::string s;\n" " Foo();\n" "};\n" - "Foo::Foo() : s(0) {}"); + "Foo::Foo() : s(0) {}\n"); ASSERT_EQUALS("[test.cpp:3:13]: (error) Null pointer dereference [nullPointer]\n" "[test.cpp:9:14]: (error) Null pointer dereference [nullPointer]\n", errout_str()); check("void f() {\n" " std::string s = 0 == x ? \"a\" : \"b\";\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " const std::string s = g();\n" " ASSERT_MESSAGE(\"Error on s\", 0 == s.compare(\"Some text\"));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int i, std::string s);\n" @@ -4145,7 +4145,7 @@ class TestNullPointer : public TestFixture { " foo(var, NULL);\n" " foo(var, nullptr);\n" " foo(0, var);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: (error) Null pointer dereference [nullPointer]\n" "[test.cpp:5:12]: (error) Null pointer dereference [nullPointer]\n" "[test.cpp:6:12]: (error) Null pointer dereference [nullPointer]\n" @@ -4190,7 +4190,7 @@ class TestNullPointer : public TestFixture { check("void f(std::ifstream& is) {\n" " char* p = 0;\n" " is >> p;\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: p\n", "", errout_str()); check("void f(const std::ostringstream& oss, char* q) {\n" @@ -4199,7 +4199,7 @@ class TestNullPointer : public TestFixture { " oss << foo << p;\n" " if(q == 0)\n" " oss << foo << q;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:12]: (error) Null pointer dereference: p [nullPointer]\n" "[test.cpp:4:19]: (error) Null pointer dereference: p [nullPointer]\n" "[test.cpp:5:10] -> [test.cpp:6:23]: (warning) Either the condition 'q==0' is redundant or there is possible null pointer dereference: q. [nullPointerRedundantCheck]\n", errout_str()); @@ -4211,7 +4211,7 @@ class TestNullPointer : public TestFixture { " std::cin >> p;\n" " std::cout << abc << p;\n" " }\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:2:10] -> [test.cpp:3:22]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n" "[test.cpp:2:10] -> [test.cpp:4:22]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n" "[test.cpp:2:10] -> [test.cpp:5]: (warning) Either the condition 'p==0' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n" @@ -4226,7 +4226,7 @@ class TestNullPointer : public TestFixture { " char* p2 = 0;\n" " std::cin >> (int)p;\n" // result casted " std::cout << (int)p;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void f(const std::string& str) {\n" @@ -4234,13 +4234,13 @@ class TestNullPointer : public TestFixture { " std::istringstream istr(str);\n" " istr >> std::hex >> ret;\n" // Read integer " return ret;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); check("void f(int* i) {\n" " if(i) return;\n" " std::cout << i;\n" // Its no char* (#4240) - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); // #5811 false positive: (error) Null pointer dereference @@ -4249,7 +4249,7 @@ class TestNullPointer : public TestFixture { " stringstream out;\n" " out << ((ip >> 0) & 0xFF);\n" " return out.str();\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); // avoid regression from first fix attempt for #5811... check("void deserialize(const std::string &data) {\n" @@ -4269,42 +4269,42 @@ class TestNullPointer : public TestFixture { "void f(std::shared_ptr p) {\n" " if (p) {}\n" " dostuff(p->x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:7] -> [test.cpp:4:11]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("struct Fred { int x; };\n" "void f(std::shared_ptr p) {\n" " p = nullptr;\n" " dostuff(p->x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("struct Fred { int x; };\n" "void f(std::unique_ptr p) {\n" " if (p) {}\n" " dostuff(p->x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:7] -> [test.cpp:4:11]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); check("struct Fred { int x; };\n" "void f(std::unique_ptr p) {\n" " p = nullptr;\n" " dostuff(p->x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("struct Fred { int x; };\n" "void f() {\n" " std::shared_ptr p;\n" " dostuff(p->x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("struct Fred { int x; };\n" "void f(std::shared_ptr p) {\n" " p.reset();\n" " dostuff(p->x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("struct Fred { int x; };\n" @@ -4312,7 +4312,7 @@ class TestNullPointer : public TestFixture { " Fred * pp = nullptr;\n" " p.reset(pp);\n" " dostuff(p->x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:11]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("struct Fred { int x; };\n" @@ -4320,28 +4320,28 @@ class TestNullPointer : public TestFixture { " std::shared_ptr p;\n" " p.reset(&f);\n" " dostuff(p->x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct Fred { int x; };\n" "void f(std::shared_ptr p) {\n" " p.reset();\n" " dostuff(p->x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("struct Fred { int x; };\n" "void f() {\n" " std::shared_ptr p(nullptr);\n" " dostuff(p->x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:11]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); check("struct A {};\n" "void f(int n) {\n" " std::unique_ptr p;\n" " p.reset(new const A*[n]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9216 @@ -4352,7 +4352,7 @@ class TestNullPointer : public TestFixture { "void g(std::unique_ptr var) {\n" " var->reset();\n" " var->f();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9439 @@ -4380,21 +4380,21 @@ class TestNullPointer : public TestFixture { " int *p = malloc(10);\n" " *p = 0;\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:6]: (warning) If memory allocation fails, then there is a possible null pointer dereference: p [nullPointerOutOfMemory]\n", errout_str()); check("void f() {\n" " int *p = malloc(10);\n" " *(p+2) = 0;\n" " free(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8]: (error) If memory allocation fails: pointer addition with NULL pointer. [nullPointerArithmeticOutOfMemory]\n", errout_str()); check("void f() {\n" // #13676 " int* q = static_cast(std::malloc(4));\n" " *q = 0;\n" " std::free(q);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:6]: (warning) If memory allocation fails, then there is a possible null pointer dereference: q [nullPointerOutOfMemory]\n", errout_str()); } @@ -4406,7 +4406,7 @@ class TestNullPointer : public TestFixture { " *p = 0;\n" " foo(p);\n" " if (p) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // function seen (taking pointer parameter) @@ -4416,7 +4416,7 @@ class TestNullPointer : public TestFixture { " *p = 0;\n" " foo(p);\n" " if (p) { }\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:6:9] -> [test.cpp:4:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); @@ -4428,7 +4428,7 @@ class TestNullPointer : public TestFixture { " *p = 0;\n" " foo(p);\n" " if (p) { }\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("", errout_str()); // function implementation not seen @@ -4438,7 +4438,7 @@ class TestNullPointer : public TestFixture { " *p = 0;\n" " foo(p);\n" " if (p) { }\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:6:9] -> [test.cpp:4:6]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); @@ -4448,7 +4448,7 @@ class TestNullPointer : public TestFixture { " *p = 0;\n" " foo(p);\n" " if (p) { }\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( "[test.cpp:4:9] -> [test.cpp:2:6]: (warning, inconclusive) Either the condition 'p' is redundant or there is possible null pointer dereference: p. [nullPointerRedundantCheck]\n", errout_str()); @@ -4461,7 +4461,7 @@ class TestNullPointer : public TestFixture { " abc->a = 0;\n" " foo(abc);\n" " if (abc) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // function seen (taking pointer parameter) @@ -4471,7 +4471,7 @@ class TestNullPointer : public TestFixture { " abc->a = 0;\n" " foo(abc);\n" " if (abc) { }\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:6:9] -> [test.cpp:4:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); @@ -4483,7 +4483,7 @@ class TestNullPointer : public TestFixture { " abc->a = 0;\n" " foo(abc);\n" " if (abc) { }\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:6:9] -> [test.cpp:4:5]: (warning) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); @@ -4493,7 +4493,7 @@ class TestNullPointer : public TestFixture { " abc->a = 0;\n" " foo(abc);\n" " if (abc) { }\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( "[test.cpp:4:9] -> [test.cpp:2:5]: (warning, inconclusive) Either the condition 'abc' is redundant or there is possible null pointer dereference: abc. [nullPointerRedundantCheck]\n", errout_str()); @@ -4567,7 +4567,7 @@ class TestNullPointer : public TestFixture { void functioncalllibrary() { SimpleTokenizer tokenizer(settingsDefault,*this,false); - const char code[] = "void f() { int a,b,c; x(a,b,c); }"; + const char code[] = "void f() { int a,b,c; x(a,b,c); }\n"; ASSERT_EQUALS(true, tokenizer.tokenize(code)); const Token *xtok = Token::findsimplematch(tokenizer.tokens(), "x"); @@ -4613,51 +4613,51 @@ class TestNullPointer : public TestFixture { check("void f(int *p = 0) {\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:6]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); check("void f(int *p = 0) {\n" " if (!p)\n" " return;\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(char a, int *p = 0) {\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:6]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); check("void f(int *p = 0) {\n" " printf(\"p = %d\", *p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:23]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); check("void f(int *p = 0) {\n" " printf(\"p[1] = %d\", p[1]);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:25]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); check("void f(int *p = 0) {\n" " buf[p] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int *p = 0) {\n" " if (p != 0 && bar())\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int *p) {\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int *p = 0) {\n" " if (p != 0)\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int *p = 0) {\n" @@ -4665,13 +4665,13 @@ class TestNullPointer : public TestFixture { " if (p == 0)\n" " p = &y;\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int a, int *p = 0) {\n" " if (a != 0)\n" " *p = 0;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS( "[test.cpp:3:8]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); @@ -4679,13 +4679,13 @@ class TestNullPointer : public TestFixture { check("void f(int *p = 0) {\n" " p = a;\n" " *p = 0;\n" // <- don't simplify and verify - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int *p = 0) {\n" " p += a;\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(int *p = 0) {\n" @@ -4693,17 +4693,17 @@ class TestNullPointer : public TestFixture { " return 0;\n" " }\n" " return *p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int *p = 0) {\n" " std::cout << p ? *p : 0;\n" // Due to operator precedence, this is equivalent to: (std::cout << p) ? *p : 0; - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:23]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); // Check the first branch of ternary check("void f(char *p = 0) {\n" " std::cout << p ? *p : 0;\n" // Due to operator precedence, this is equivalent to: (std::cout << p) ? *p : 0; - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:18]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n" "[test.cpp:2:23]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", // duplicate @@ -4711,27 +4711,27 @@ class TestNullPointer : public TestFixture { check("void f(int *p = 0) {\n" " std::cout << (p ? *p : 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int *p = 0) {\n" " std::cout << p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int *p = 0) {\n" " std::cout << (p && p[0] ? *p : 42);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void isEmpty(int *p = 0) {\n" " return p && *p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void g(int *p = 0) {\n" " return !p || *p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); @@ -4740,13 +4740,13 @@ class TestNullPointer : public TestFixture { check("void f(int *p = 0) {\n" " bar(p);\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int *p = 0) {\n" " printf(\"%p\", p);\n" " *p = 0;\n" - "}", dinit(CheckOptions, $.inconclusive = true)); + "}\n", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:3:6]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); // The init() function may or may not initialize p, but since the address @@ -4755,14 +4755,14 @@ class TestNullPointer : public TestFixture { check("void f(int *p = 0) {\n" " init(&p);\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void init(int* &g);\n" "void f(int *p = 0) {\n" " init(p);\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int *p = 0) {\n" @@ -4770,7 +4770,7 @@ class TestNullPointer : public TestFixture { " init(&p);\n" " }\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int *p = 0) {\n" @@ -4778,12 +4778,12 @@ class TestNullPointer : public TestFixture { " throw SomeException;\n" " }\n" " *p = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int x, int *p = 0) {\n" " int var1 = x ? *p : 5;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:21]: (warning) Possible null pointer dereference if the default parameter value is used: p [nullPointerDefaultArg]\n", errout_str()); check("void f(int* i = nullptr) { *i = 0; }\n" // #11567 @@ -4798,7 +4798,7 @@ class TestNullPointer : public TestFixture { " unsigned int j;\n" " for (j = 0; j < b[0].a->size; ++j) {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -4822,33 +4822,33 @@ class TestNullPointer : public TestFixture { check("void foo(char *s) {\n" " char *p = s - 20;\n" "}\n" - "void bar() { foo(0); }"); + "void bar() { foo(0); }\n"); ASSERT_EQUALS("[test.cpp:2:15]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\n", errout_str()); check("void foo(char *s) {\n" " if (!s) {}\n" " char *p = s - 20;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:7] -> [test.cpp:3:15]: (warning) Either the condition '!s' is redundant or there is overflow in pointer subtraction. [nullPointerArithmeticRedundantCheck]\n", errout_str()); check("void foo(char *s) {\n" " s -= 20;\n" "}\n" - "void bar() { foo(0); }"); + "void bar() { foo(0); }\n"); ASSERT_EQUALS("[test.cpp:2:5]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\n", errout_str()); check("void foo(char *s) {\n" " if (!s) {}\n" " s -= 20;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:7] -> [test.cpp:3:5]: (warning) Either the condition '!s' is redundant or there is overflow in pointer subtraction. [nullPointerArithmeticRedundantCheck]\n", errout_str()); - check("int* f8() { int *x = NULL; return --x; }"); + check("int* f8() { int *x = NULL; return --x; }\n"); ASSERT_EQUALS("[test.cpp:1:35]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\n", errout_str()); - check("int* f9() { int *x = NULL; return x--; }"); + check("int* f9() { int *x = NULL; return x--; }\n"); ASSERT_EQUALS("[test.cpp:1:36]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted. [nullPointerArithmetic]\n", errout_str()); } @@ -4856,48 +4856,48 @@ class TestNullPointer : public TestFixture { check("void foo(char *s) {\n" " char * p = s + 20;\n" "}\n" - "void bar() { foo(0); }"); + "void bar() { foo(0); }\n"); ASSERT_EQUALS("[test.cpp:2:16]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\n", errout_str()); check("void foo(char *s) {\n" " if (!s) {}\n" " char * p = s + 20;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:7] -> [test.cpp:3:16]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck]\n", errout_str()); check("void foo(char *s) {\n" " char * p = 20 + s;\n" "}\n" - "void bar() { foo(0); }"); + "void bar() { foo(0); }\n"); ASSERT_EQUALS("[test.cpp:2:17]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\n", errout_str()); check("void foo(char *s) {\n" " if (!s) {}\n" " char * p = 20 + s;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:7] -> [test.cpp:3:17]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck]\n", errout_str()); check("void foo(char *s) {\n" " s += 20;\n" "}\n" - "void bar() { foo(0); }"); + "void bar() { foo(0); }\n"); ASSERT_EQUALS("[test.cpp:2:5]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\n", errout_str()); check("void foo(char *s) {\n" " if (!s) {}\n" " s += 20;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:7] -> [test.cpp:3:5]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck]\n", errout_str()); - check("int* f7() { int *x = NULL; return ++x; }"); + check("int* f7() { int *x = NULL; return ++x; }\n"); ASSERT_EQUALS("[test.cpp:1:35]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\n", errout_str()); - check("int* f10() { int *x = NULL; return x++; }"); + check("int* f10() { int *x = NULL; return x++; }\n"); ASSERT_EQUALS("[test.cpp:1:37]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\n", errout_str()); check("class foo {};\n" "const char* get() const { return 0; }\n" - "void f(foo x) { if (get()) x += get(); }"); + "void f(foo x) { if (get()) x += get(); }\n"); ASSERT_EQUALS("", errout_str()); check("typedef struct { uint8_t* buf, *buf_end; } S;\n" // #11117 @@ -4913,7 +4913,7 @@ class TestNullPointer : public TestFixture { } void isPointerDeRefFunctionDecl() { - check("const char** get() { return 0; }"); + check("const char** get() { return 0; }\n"); ASSERT_EQUALS("", errout_str()); } @@ -4947,7 +4947,7 @@ class TestNullPointer : public TestFixture { "int main() {\n" " int *p = 0;\n" " f(p);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: error: Null pointer dereference: fp [ctunullpointer]\n" "[test.cpp:5:12]: note: Assignment 'p=0', assigned value is 0\n" "[test.cpp:6:4]: note: Calling function f, 1st argument is null\n" @@ -4957,7 +4957,7 @@ class TestNullPointer : public TestFixture { "void call(int x, int *p) { x++; use(p); }\n" "int main() {\n" " call(4,0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:25]: error: Null pointer dereference: p [ctunullpointer]\n" "[test.cpp:4:7]: note: Calling function call, 2nd argument is null\n" "[test.cpp:2:33]: note: Calling function use, 1st argument is null\n" @@ -4971,7 +4971,7 @@ class TestNullPointer : public TestFixture { "\n" "void f() {\n" " dostuff(a, 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); ctu("void dostuff(int *x, int *y) {\n" @@ -4982,7 +4982,7 @@ class TestNullPointer : public TestFixture { "\n" "void f() {\n" " dostuff(a, 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // else @@ -4993,7 +4993,7 @@ class TestNullPointer : public TestFixture { "\n" "void f() {\n" " dostuff(0, 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // ?, &&, || @@ -5003,14 +5003,14 @@ class TestNullPointer : public TestFixture { "\n" "void f() {\n" " dostuff(0, 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); ctu("void g(int* x) { *x; }\n" "void f(int* x) {\n" " if (x)\n" " g(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); ctu("size_t f(int* p) {\n" diff --git a/test/testother.cpp b/test/testother.cpp index b12e26e1ffa..3c301a3fc3c 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -398,7 +398,7 @@ class TestOther : public TestFixture { void emptyBrackets() { check("{\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -406,22 +406,22 @@ class TestOther : public TestFixture { void zeroDiv1() { // floating point division by zero => no error check("void foo() {\n" " cout << 1. / 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " cout << 42 / (double)0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " cout << 42 / (float)0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " cout << 42 / (int)0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (error) Division by zero. [zerodiv]\n", errout_str()); } @@ -434,34 +434,34 @@ class TestOther : public TestFixture { " sum += i;\n" " }\n" " cout<(fStepMain / fStepHelp);\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -592,7 +592,7 @@ class TestOther : public TestFixture { " << boost::format(\" %d :: %s <> %s\") % 0 % \"a\" % \"b\"\n" " << std::endl;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -600,13 +600,13 @@ class TestOther : public TestFixture { check("void f(int a) {\n" " int res = (a+2)/0;\n" " int res = (a*2)/0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:18]: (error) Division by zero. [zerodiv]\n" "[test.cpp:3:18]: (error) Division by zero. [zerodiv]\n", errout_str()); check("void f() {\n" " int res = (a+2)/0;\n" " int res = (a*2)/0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -614,7 +614,7 @@ class TestOther : public TestFixture { // #8141 check("intmax_t f() {\n" " return 1 / imaxabs(0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (error) Division by zero. [zerodiv]\n", errout_str()); } void zeroDiv13() { @@ -709,7 +709,7 @@ class TestOther : public TestFixture { "{\n" " uint16_t x = 0xFFFFU;\n" // UINT16_MAX=0xFFFF " return 42/(++x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:14]: (error) Division by zero. [zerodiv]\n", errout_str()); } @@ -736,25 +736,25 @@ class TestOther : public TestFixture { check("void f(unsigned int x) {\n" " int y = 17 / x;\n" " if (x > 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>0' is redundant or there is division by zero at line 2. [zerodivcond]\n", errout_str()); check("void f(unsigned int x) {\n" " int y = 17 / x;\n" " if (x >= 1) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x>=1' is redundant or there is division by zero at line 2. [zerodivcond]\n", errout_str()); check("void f(int x) {\n" " int y = 17 / x;\n" " if (x == 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x==0' is redundant or there is division by zero at line 2. [zerodivcond]\n", errout_str()); check("void f(unsigned int x) {\n" " int y = 17 / x;\n" " if (x != 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:2:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 2. [zerodivcond]\n", errout_str()); // function call @@ -762,7 +762,7 @@ class TestOther : public TestFixture { "void f2(unsigned int y) {\n" " f1(123,y);\n" " if (y>0){}\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:10] -> [test.cpp:1:28]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1. [zerodivcond]\n", errout_str()); @@ -773,7 +773,7 @@ class TestOther : public TestFixture { " int y = 17 / x;\n" " x = some+calculation;\n" " if (x != 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); { @@ -784,7 +784,7 @@ class TestOther : public TestFixture { " int y = 17 / x;\n" " do_something();\n" " if (x != 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // function is called. but don't care, variable is local @@ -794,7 +794,7 @@ class TestOther : public TestFixture { " int y = 17 / x;\n" " do_something();\n" " if (x != 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:9] -> [test.cpp:4:14]: (warning) Either the condition 'x!=0' is redundant or there is division by zero at line 4. [zerodivcond]\n", errout_str()); } @@ -802,14 +802,14 @@ class TestOther : public TestFixture { "void f(int x) {\n" " int y = 17 / x;\n" " do_something(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int x;\n" "void f() {\n" " int y = 17 / x;\n" " while (y || x == 0) { x--; }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // ticket 5033 segmentation fault (valid code) in CheckOther::checkZeroDivisionOrUselessCondition @@ -818,33 +818,33 @@ class TestOther : public TestFixture { "double* p2= new double[1];\n" "double* p3= new double[1];\n" "double* pp[3] = {p1,p2,p3};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #5105 - FP check("int f(int a, int b) {\n" " int r = a / b;\n" " if (func(b)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Unknown types for b and c --> do not warn check("int f(int d) {\n" " int r = (a?b:c) / d;\n" " if (d == 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(int a) {\n" " int r = a ? 1 / a : 0;\n" " if (a == 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(int a) {\n" " int r = (a == 0) ? 0 : 1 / a;\n" " if (a == 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int g();\n" @@ -854,7 +854,7 @@ class TestOther : public TestFixture { " else if (x > 0) {}\n" " else\n" " a = b / -x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" @@ -901,35 +901,35 @@ class TestOther : public TestFixture { "{\n" " double x = 3.0 / 0.0 + 1.0;\n" " printf(\"%f\", x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\n", errout_str()); check("void f()\n" "{\n" " double x = 3.0 / 0.0 - 1.0;\n" " printf(\"%f\", x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:19]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\n", errout_str()); check("void f()\n" "{\n" " double x = 1.0 + 3.0 / 0.0;\n" " printf(\"%f\", x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\n", errout_str()); check("void f()\n" "{\n" " double x = 1.0 - 3.0 / 0.0;\n" " printf(\"%f\", x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:25]: (style) Using NaN/Inf in a computation. [nanInArithmeticExpression]\n", errout_str()); check("void f()\n" "{\n" " double x = 3.0 / 0.0;\n" " printf(\"%f\", x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -960,7 +960,7 @@ class TestOther : public TestFixture { " }\n" "\n" " return 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -970,7 +970,7 @@ class TestOther : public TestFixture { " Error e;\n" " e.SetValue(12);\n" " throw e;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -984,7 +984,7 @@ class TestOther : public TestFixture { " p = &i;\n" " }\n" " *p = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -992,7 +992,7 @@ class TestOther : public TestFixture { check("void foo()\n" "{\n" " int i;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1003,7 +1003,7 @@ class TestOther : public TestFixture { " if (x) {\n" " for ( ; i < 10; ++i) ;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\n", errout_str()); check("void f(int x) {\n" @@ -1011,7 +1011,7 @@ class TestOther : public TestFixture { " if (x) {\n" " for ( ; i < 10; ++i) ;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x)\n" @@ -1021,7 +1021,7 @@ class TestOther : public TestFixture { " else {\n" " for ( ; i < 10; ++i) ;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\n", errout_str()); } @@ -1035,7 +1035,7 @@ class TestOther : public TestFixture { " if (b) {\n" " c(i);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" // #5398 @@ -1044,14 +1044,14 @@ class TestOther : public TestFixture { " if (success) {\n" " foo(notReducable);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(Test &test) {\n" " int& x = test.getData();\n" " if (test.process())\n" " x = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f()\n" @@ -1066,7 +1066,7 @@ class TestOther : public TestFixture { " return 0;\n" " }\n" "}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int &x)\n" @@ -1077,7 +1077,7 @@ class TestOther : public TestFixture { " ++n;\n" " ++x;\n" " } while (x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1089,7 +1089,7 @@ class TestOther : public TestFixture { " if (x) {\n" " y++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1100,7 +1100,7 @@ class TestOther : public TestFixture { " BOOST_FOREACH(int edge, edges) {\n" " edgeResistance = (edge+1) / 2.0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) The scope of the variable 'edgeResistance' can be reduced. [variableScope]\n", errout_str()); } @@ -1116,7 +1116,7 @@ class TestOther : public TestFixture { " if (a == 2) {\n" " f.x();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class fred {\n" // #2062 @@ -1128,7 +1128,7 @@ class TestOther : public TestFixture { " if (a == 2) {\n" " f.x();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:10]: (style) The scope of the variable 'f' can be reduced. [variableScope]\n", errout_str()); check("struct S { int a, b; };\n" @@ -1149,7 +1149,7 @@ class TestOther : public TestFixture { " FOR {\n" " foo(x++);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1157,21 +1157,21 @@ class TestOther : public TestFixture { check("int f() {\n" " int x = 0;\n" " AB ab = { x, 0 };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f() {\n" " int x = 0;\n" " if (a == 0) { ++x; }\n" " AB ab = { x, 0 };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f() {\n" " int x = 0;\n" " if (a == 0) { ++x; }\n" " if (a == 1) { AB ab = { x, 0 }; }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1182,7 +1182,7 @@ class TestOther : public TestFixture { " if (x)\n" " foo(i);\n" " foo(j);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) The scope of the variable 'i' can be reduced. [variableScope]\n", errout_str()); check("void f(int x) {\n" @@ -1191,7 +1191,7 @@ class TestOther : public TestFixture { " if (x)\n" " j = i;\n" " foo(j);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" @@ -1199,7 +1199,7 @@ class TestOther : public TestFixture { " x++;\n" " if (x == 5)\n" " foo(b);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" @@ -1207,7 +1207,7 @@ class TestOther : public TestFixture { " x++;\n" " if (x == 5)\n" " foo(b);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1218,7 +1218,7 @@ class TestOther : public TestFixture { " forever {\n" " if (i++ == 42) { break; }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1229,7 +1229,7 @@ class TestOther : public TestFixture { " if(a) {\n" " for ( ; i < 10; ++i) ;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1241,7 +1241,7 @@ class TestOther : public TestFixture { " else if(b);\n" " else if(c);\n" " else;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); } @@ -1251,7 +1251,7 @@ class TestOther : public TestFixture { " while((++a) < 56) {\n" " foo();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -1259,7 +1259,7 @@ class TestOther : public TestFixture { " do {\n" " foo();\n" " } while((++a) < 56);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -1268,7 +1268,7 @@ class TestOther : public TestFixture { " a = 64;\n" " foo(a);\n" " } while((++a) < 56);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -1277,7 +1277,7 @@ class TestOther : public TestFixture { " a = 64;\n" " foo(a);\n" " } while(z());\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) The scope of the variable 'a' can be reduced. [variableScope]\n", errout_str()); } @@ -1288,7 +1288,7 @@ class TestOther : public TestFixture { " x = stuff(x);\n" " morestuff(x);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\n", errout_str()); check("void f() {\n" @@ -1298,7 +1298,7 @@ class TestOther : public TestFixture { " morestuff(x);\n" " }\n" " if (b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) The scope of the variable 'x' can be reduced. [variableScope]\n", errout_str()); } @@ -1318,7 +1318,7 @@ class TestOther : public TestFixture { " x = foo();\n" " do_something(x);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\n", errout_str()); check("void f() {\n" @@ -1337,7 +1337,7 @@ class TestOther : public TestFixture { " x = foo();\n" " do_something(x);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -1352,7 +1352,7 @@ class TestOther : public TestFixture { " default:\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) The scope of the variable 'x' can be reduced. [variableScope]\n", errout_str()); check("void f() {\n" @@ -1369,7 +1369,7 @@ class TestOther : public TestFixture { " do_something(x);\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1379,7 +1379,7 @@ class TestOther : public TestFixture { " int b = a;\n" " if (b > 32) b = x;\n" " return b;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1388,7 +1388,7 @@ class TestOther : public TestFixture { " int test_value = 3;\n" " int test_array[1][1] = { { test_value } };\n" " return sizeof(test_array);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1401,7 +1401,7 @@ class TestOther : public TestFixture { " ++p;\n" " ++i;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // try to avoid an obvious false negative after applying the fix for the example above: check("void foo() {\n" @@ -1414,7 +1414,7 @@ class TestOther : public TestFixture { " ++p;\n" " ++i;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) The scope of the variable 'p' can be reduced. [variableScope]\n", errout_str()); } @@ -1424,7 +1424,7 @@ class TestOther : public TestFixture { " Test myTest([&](size_t aX){\n" " std::cout << myCounter += aX << std::endl;\n" " });\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1434,7 +1434,7 @@ class TestOther : public TestFixture { " if (cond) {\n" " r.dostuff();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) The scope of the variable 'r' can be reduced. [variableScope]\n", errout_str()); check("void f(Foo x) {\n" @@ -1442,7 +1442,7 @@ class TestOther : public TestFixture { " if (cond) {\n" " foo.dostuff();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1453,7 +1453,7 @@ class TestOther : public TestFixture { " currtime = time(&dummy);\n" " if (currtime > t) {}\n" " }\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\n", errout_str()); } @@ -1465,7 +1465,7 @@ class TestOther : public TestFixture { " if (cond2) { dostuff(key); }\n" " }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -1475,7 +1475,7 @@ class TestOther : public TestFixture { "#ifdef X\n" "#endif\n" " if (id == ABC) { return x; }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkP("void f() {\n" @@ -1483,7 +1483,7 @@ class TestOther : public TestFixture { "#endif\n" " int x = 0;\n" " if (id == ABC) { return x; }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7]: (style) The scope of the variable 'x' can be reduced. [variableScope]\n", errout_str()); } @@ -1517,7 +1517,7 @@ class TestOther : public TestFixture { " s = \"abc\";\n" " g(s);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (style) The scope of the variable 's' can be reduced. [variableScope]\n", errout_str()); check("auto foo(std::vector& vec, bool flag) {\n" @@ -1530,7 +1530,7 @@ class TestOther : public TestFixture { " iter = dummy.begin();\n" " }\n" " return *iter;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:28]: (style) Parameter 'vec' can be declared as reference to const [constParameterReference]\n", errout_str()); check("auto& foo(std::vector& vec, bool flag) {\n" @@ -1543,7 +1543,7 @@ class TestOther : public TestFixture { " iter = dummy.begin();\n" " }\n" " return *iter;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -2067,7 +2067,7 @@ class TestOther : public TestFixture { "void foo(Base* base)\n" "{\n" " Derived * d = (Derived *) base;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\n", errout_str()); checkOldStylePointerCast("class Base{};\n" @@ -2075,13 +2075,13 @@ class TestOther : public TestFixture { "void foo(Derived* derived)\n" "{\n" " Base * b = (Base *) derived;\n" // <- cast from derived to base is safe => cstyleCast - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:16]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("void foo(Base* base)\n" "{\n" " Derived * d = (Derived *) base;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\n", errout_str()); checkOldStylePointerCast("class Base{};\n" @@ -2089,7 +2089,7 @@ class TestOther : public TestFixture { "void foo(Base* base)\n" "{\n" " Derived * d = (const Derived *) base;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\n", errout_str()); checkOldStylePointerCast("class Base{};\n" @@ -2097,7 +2097,7 @@ class TestOther : public TestFixture { "void foo()\n" "{\n" " Derived * d = (const Derived *) ( new Base() );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\n", errout_str()); checkOldStylePointerCast("class Base{};\n" @@ -2105,102 +2105,102 @@ class TestOther : public TestFixture { "void foo()\n" "{\n" " Derived * d = (const Derived *) new Base();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:19]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\n", errout_str()); checkOldStylePointerCast("class Base{};\n" "void foo()\n" "{\n" " Base * b = (Base *) new short[10];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (volatile Base *) derived;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (volatile Base * const) derived;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (const volatile Base *) derived;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (const volatile Base * const) derived;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (const Base *) ( new Derived() );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (const Base *) new Derived();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:16]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" " Base * b = (const Base *) new short[10];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:16]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\n", errout_str()); checkOldStylePointerCast("class B;\n" "class A\n" "{\n" " virtual void abc(B *) const = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkOldStylePointerCast("class B;\n" "class A\n" "{\n" " virtual void abc(const B *) const = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #3630 checkOldStylePointerCast("class SomeType{};\n" "class X : public Base {\n" " X() : Base((SomeType*)7) {}\n" // <- intToPointerCast - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOldStylePointerCast("class SomeType{};\n" "class X : public Base {\n" " X() : Base((SomeType*)0x7000) {}\n" // <- it's common in embedded code to cast address - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); checkOldStylePointerCast("class SomeType;\n" "class X : public Base {\n" " X() : Base((SomeType*)var) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:3:16]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); checkOldStylePointerCast("class SomeType;\n" "class X : public Base {\n" " X() : Base((SomeType*)0) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); // #5560 @@ -2210,7 +2210,7 @@ class TestOther : public TestFixture { "{ virtual G* createGui(S*, C*) const = 0; };\n" "\n" "class MS : public M\n" - "{ virtual void addController(C*) override {} };", Standards::CPP03); + "{ virtual void addController(C*) override {} };\n", Standards::CPP03); ASSERT_EQUALS("", errout_str()); // #6164 @@ -2219,7 +2219,7 @@ class TestOther : public TestFixture { "void testCC() {\n" " std::vector v;\n" " v.push_back((Base*)new Derived);\n" - "}"); + "}\n"); // FIXME write a dangerousTypeCast warning instead ASSERT_EQUALS("[test.cpp:5:15]: (style) C-style pointer casting [cstyleCast]\n", errout_str()); @@ -2348,23 +2348,23 @@ class TestOther : public TestFixture { void intToPointerCast() { // #3630 - checkIntToPointerCast("uint8_t* ptr = (uint8_t*)7;"); + checkIntToPointerCast("uint8_t* ptr = (uint8_t*)7;\n"); ASSERT_EQUALS("[test.cpp:1:16]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\n", errout_str()); - checkIntToPointerCast("void* ptr = (void*)7;"); + checkIntToPointerCast("void* ptr = (void*)7;\n"); ASSERT_EQUALS("[test.cpp:1:13]: (portability) Casting non-zero decimal integer literal to pointer. [intToPointerCast]\n", errout_str()); - checkIntToPointerCast("uint8_t* ptr = (uint8_t*)0;"); + checkIntToPointerCast("uint8_t* ptr = (uint8_t*)0;\n"); ASSERT_EQUALS("", errout_str()); - checkIntToPointerCast("uint8_t* ptr = (uint8_t*)0x7000;"); // <- it's common in embedded code to cast address + checkIntToPointerCast("uint8_t* ptr = (uint8_t*)0x7000;\n"); // <- it's common in embedded code to cast address ASSERT_EQUALS("", errout_str()); checkIntToPointerCast("struct S { int i; };\n" // #13886, don't crash - "int f() { return sizeof(((struct S*)0)->i); }"); + "int f() { return sizeof(((struct S*)0)->i); }\n"); ASSERT_EQUALS("", errout_str()); - checkIntToPointerCast("auto p = (int*)0b10;"); // #14180 + checkIntToPointerCast("auto p = (int*)0b10;\n"); // #14180 ASSERT_EQUALS("[test.cpp:1:10]: (portability) Casting non-zero binary integer literal to pointer. [intToPointerCast]\n", errout_str()); } @@ -2394,19 +2394,19 @@ class TestOther : public TestFixture { " float *f = new float[10];\n" " delete [] (double*)f;\n" " delete [] (long double const*)(new float[10]);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:15]: (portability) Casting between float * and double * which have an incompatible binary data representation. [invalidPointerCast]\n" "[test.cpp:4:15]: (portability) Casting between float * and const long double * which have an incompatible binary data representation. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("void test(const float* f) {\n" " double *d = (double*)f;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (portability) Casting between const float * and double * which have an incompatible binary data representation. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("void test(double* d1) {\n" " long double *ld = (long double*)d1;\n" " double *d2 = (double*)ld;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:23]: (portability) Casting between double * and long double * which have an incompatible binary data representation. [invalidPointerCast]\n" "[test.cpp:3:18]: (portability) Casting between long double * and double * which have an incompatible binary data representation. [invalidPointerCast]\n", errout_str()); @@ -2414,148 +2414,148 @@ class TestOther : public TestFixture { " long double *d = (long double*)(i);\n" " double *d = (double*)(i);\n" " float *f = reinterpret_cast(i);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:22]: (portability) Casting between signed int * and long double * which have an incompatible binary data representation. [invalidPointerCast]\n" "[test.cpp:3:17]: (portability) Casting between signed int * and double * which have an incompatible binary data representation. [invalidPointerCast]\n" "[test.cpp:4:16]: (portability) Casting between signed int * and float * which have an incompatible binary data representation. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("float* test(unsigned int* i) {\n" " return (float*)i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (portability) Casting between unsigned int * and float * which have an incompatible binary data representation. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("float* test(unsigned int* i) {\n" " return (float*)i[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkInvalidPointerCast("float* test(double& d) {\n" " return (float*)&d;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (portability) Casting between double * and float * which have an incompatible binary data representation. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("void test(float* data) {\n" " f.write((char*)data,sizeof(float));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkInvalidPointerCast("void test(float* data) {\n" " f.write((char*)data,sizeof(float));\n" - "}", dinit(CheckInvalidPointerCastOptions, $.inconclusive = true)); // #3639 + "}\n", dinit(CheckInvalidPointerCastOptions, $.inconclusive = true)); // #3639 ASSERT_EQUALS("[test.cpp:2:13]: (portability, inconclusive) Casting from float * to char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("long long* test(float* f) {\n" " return (long long*)f;\n" - "}", dinit(CheckInvalidPointerCastOptions, $.portability = false)); + "}\n", dinit(CheckInvalidPointerCastOptions, $.portability = false)); ASSERT_EQUALS("", errout_str()); checkInvalidPointerCast("long long* test(float* f, char* c) {\n" " foo((long long*)f);\n" " return reinterpret_cast(c);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\n", errout_str()); - checkInvalidPointerCast("Q_DECLARE_METATYPE(int*)"); // #4135 - don't crash + checkInvalidPointerCast("Q_DECLARE_METATYPE(int*)\n"); // #4135 - don't crash } void passedByValue() { - check("void f(const std::string str) {}"); + check("void f(const std::string str) {}\n"); ASSERT_EQUALS("[test.cpp:1:26]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); - check("void f(std::unique_ptr ptr) {}"); + check("void f(std::unique_ptr ptr) {}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(const std::shared_ptr ptr) {}"); + check("void f(const std::shared_ptr ptr) {}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(const std::function ptr) {}"); + check("void f(const std::function ptr) {}\n"); ASSERT_EQUALS("", errout_str()); { - check("void f(const std::pair x) {}"); + check("void f(const std::pair x) {}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(const std::pair x) {}"); + check("void f(const std::pair x) {}\n"); TODO_ASSERT_EQUALS("error", "", errout_str()); } - check("void f(const std::string::size_type x) {}"); + check("void f(const std::string::size_type x) {}\n"); ASSERT_EQUALS("", errout_str()); - check("class Foo;\nvoid f(const Foo foo) {}"); // Unknown class + check("class Foo;\nvoid f(const Foo foo) {}\n"); // Unknown class ASSERT_EQUALS("[test.cpp:2:18]: (performance, inconclusive) Function parameter 'foo' should be passed by const reference. [passedByValue]\n", errout_str()); - check("class Foo { std::vector v; };\nvoid f(const Foo foo) {}"); // Large class (STL member) + check("class Foo { std::vector v; };\nvoid f(const Foo foo) {}\n"); // Large class (STL member) ASSERT_EQUALS("[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\n", errout_str()); - check("class Foo { int i; };\nvoid f(const Foo foo) {}"); // Small class + check("class Foo { int i; };\nvoid f(const Foo foo) {}\n"); // Small class ASSERT_EQUALS("", errout_str()); - check("class Foo { int i[6]; };\nvoid f(const Foo foo) {}"); // Large class (array) + check("class Foo { int i[6]; };\nvoid f(const Foo foo) {}\n"); // Large class (array) ASSERT_EQUALS("[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\n", errout_str()); - check("class Foo { std::string* s; };\nvoid f(const Foo foo) {}"); // Small class (pointer) + check("class Foo { std::string* s; };\nvoid f(const Foo foo) {}\n"); // Small class (pointer) ASSERT_EQUALS("", errout_str()); - check("class Foo { static std::string s; };\nvoid f(const Foo foo) {}"); // Small class (static member) + check("class Foo { static std::string s; };\nvoid f(const Foo foo) {}\n"); // Small class (static member) ASSERT_EQUALS("", errout_str()); - check("class X { std::string s; }; class Foo : X { };\nvoid f(const Foo foo) {}"); // Large class (inherited) + check("class X { std::string s; }; class Foo : X { };\nvoid f(const Foo foo) {}\n"); // Large class (inherited) ASSERT_EQUALS("[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\n", errout_str()); - check("class X { std::string s; }; class Foo { X x; };\nvoid f(const Foo foo) {}"); // Large class (inherited) + check("class X { std::string s; }; class Foo { X x; };\nvoid f(const Foo foo) {}\n"); // Large class (inherited) ASSERT_EQUALS("[test.cpp:2:18]: (performance) Function parameter 'foo' should be passed by const reference. [passedByValue]\n", errout_str()); - check("void f(const std::string &str) {}"); + check("void f(const std::string &str) {}\n"); ASSERT_EQUALS("", errout_str()); // The idiomatic way of passing a std::string_view is by value - check("void f(const std::string_view str) {}"); + check("void f(const std::string_view str) {}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(std::string_view str) {}"); + check("void f(std::string_view str) {}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(const std::string_view &str) {}"); + check("void f(const std::string_view &str) {}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(const std::vector v) {}"); + check("void f(const std::vector v) {}\n"); ASSERT_EQUALS("[test.cpp:1:31]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); - check("void f(const std::vector v) {}"); + check("void f(const std::vector v) {}\n"); ASSERT_EQUALS("[test.cpp:1:39]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); - check("void f(const std::vector::size_type s) {}"); + check("void f(const std::vector::size_type s) {}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(const std::vector &v) {}"); + check("void f(const std::vector &v) {}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(const std::map &v) {}"); + check("void f(const std::map &v) {}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(const std::map v) {}"); + check("void f(const std::map v) {}\n"); ASSERT_EQUALS("[test.cpp:1:32]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); - check("void f(const std::map v) {}"); + check("void f(const std::map v) {}\n"); ASSERT_EQUALS("[test.cpp:1:48]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); - check("void f(const std::map v) {}"); + check("void f(const std::map v) {}\n"); ASSERT_EQUALS("[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); - check("void f(const std::map v) {}"); + check("void f(const std::map v) {}\n"); ASSERT_EQUALS("[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); - check("void f(const std::streamoff pos) {}"); + check("void f(const std::streamoff pos) {}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(std::initializer_list i) {}"); + check("void f(std::initializer_list i) {}\n"); ASSERT_EQUALS("", errout_str()); // #5824 - check("void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}"); + check("void log(const std::string& file, int line, const std::string& function, const std::string str, ...) {}\n"); ASSERT_EQUALS("", errout_str()); // #5534 @@ -2564,12 +2564,12 @@ class TestOther : public TestFixture { "class Plane {\n" " vec Refract(vec &vec) const;\n" " bool IntersectLinePlane(const vec &planeNormal);\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class X {\n" " virtual void func(const std::string str) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:2:41]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("enum X;\n" @@ -2586,7 +2586,7 @@ class TestOther : public TestFixture { ASSERT_EQUALS("", errout_str()); check("enum X;\n" - "enum X { a, b, c };" + "enum X { a, b, c };\n" "void foo(X x4){}\n"); ASSERT_EQUALS("", errout_str()); @@ -2746,87 +2746,87 @@ class TestOther : public TestFixture { } void passedByValue_nonConst() { - check("void f(std::string str) {}"); + check("void f(std::string str) {}\n"); ASSERT_EQUALS("[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(std::string str) {\n" " return str + x;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(std::string str) {\n" " std::cout << str;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(std::string str) {\n" " std::cin >> str;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(std::string str) {\n" " std::string s2 = str;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (performance, inconclusive) Use const reference for 's2' to avoid unnecessary data copying. [redundantCopyLocalConst]\n" "[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(std::string str) {\n" " std::string& s2 = str;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n" "[test.cpp:2:18]: (style) Variable 's2' can be declared as reference to const [constVariableReference]\n", errout_str()); check("void f(std::string str) {\n" " const std::string& s2 = str;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("void f(std::string str) {\n" " str = \"\";\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(std::string str) {\n" " foo(str);\n" // It could be that foo takes str as non-const-reference - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(const std::string& str);\n" "void f(std::string str) {\n" " foo(str);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("void foo(std::string str);\n" "void f(std::string str) {\n" " foo(str);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("void foo(std::string& str);\n" "void f(std::string str) {\n" " foo(str);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(std::string* str);\n" "void f(std::string str) {\n" " foo(&str);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int& i1, const std::string& str, int& i2);\n" "void f(std::string str) {\n" " foo((a+b)*c, str, x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("std::string f(std::string str) {\n" " str += x;\n" " return str;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class X {\n" @@ -2835,7 +2835,7 @@ class TestOther : public TestFixture { "};\n" "Y f(X x) {\n" " x.func();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:7]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\n", errout_str()); check("class X {\n" @@ -2843,17 +2843,17 @@ class TestOther : public TestFixture { "};\n" "Y f(X x) {\n" " x.func();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class X {\n" " void func(std::string str) {}\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:2:27]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str()); check("class X {\n" " virtual void func(std::string str) {}\n" // Do not warn about virtual functions, if 'str' is not declared as const - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("class X {\n" @@ -2863,7 +2863,7 @@ class TestOther : public TestFixture { " char b;\n" "};\n" "void f(Y y) {\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:10]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\n", errout_str()); check("class X {\n" @@ -2876,7 +2876,7 @@ class TestOther : public TestFixture { " char c;\n" "};\n" "void f(X x, Y y) {\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:15]: (performance) Function parameter 'y' should be passed by const reference. [passedByValue]\n", errout_str()); { @@ -2885,7 +2885,7 @@ class TestOther : public TestFixture { " uint64_t a;\n" " uint64_t b;\n" "};\n" - "void f(X x) {}"; + "void f(X x) {}\n"; /*const*/ Settings s32 = settingsBuilder(settings1).platform(Platform::Type::Unix32).build(); check(code, dinit(CheckOptions, $.settings = &s32)); @@ -2900,30 +2900,30 @@ class TestOther : public TestFixture { "\n" "void foo(Buffer& buffer) {\n" " getWriter()->operator<<(buffer);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void passedByValue_externC() { - check("struct X { int a[5]; }; void f(X v) { }"); + check("struct X { int a[5]; }; void f(X v) { }\n"); ASSERT_EQUALS("[test.cpp:1:34]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); - check("extern \"C\" { struct X { int a[5]; }; void f(X v) { } }"); + check("extern \"C\" { struct X { int a[5]; }; void f(X v) { } }\n"); ASSERT_EQUALS("", errout_str()); - check("struct X { int a[5]; }; extern \"C\" void f(X v) { }"); + check("struct X { int a[5]; }; extern \"C\" void f(X v) { }\n"); ASSERT_EQUALS("", errout_str()); - check("struct X { int a[5]; }; void f(const X v);"); + check("struct X { int a[5]; }; void f(const X v);\n"); ASSERT_EQUALS("", errout_str()); - check("struct X { int a[5]; }; void f(const X v) { (void) v; }"); + check("struct X { int a[5]; }; void f(const X v) { (void) v; }\n"); ASSERT_EQUALS("[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); - check("extern \"C\" { struct X { int a[5]; }; void f(const X v); }"); + check("extern \"C\" { struct X { int a[5]; }; void f(const X v); }\n"); ASSERT_EQUALS("", errout_str()); - check("struct X { int a[5]; }; extern \"C\" void f(const X v) { }"); + check("struct X { int a[5]; }; extern \"C\" void f(const X v) { }\n"); ASSERT_EQUALS("", errout_str()); } @@ -2931,140 +2931,140 @@ class TestOther : public TestFixture { check("int f(std::vector x) {\n" " int& i = x[0];\n" " return i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\n" "[test.cpp:2:10]: (style) Variable 'i' can be declared as reference to const [constVariableReference]\n", errout_str()); check("int f(std::vector& x) {\n" " return x[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:25]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("int f(std::vector x) {\n" " const int& i = x[0];\n" " return i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\n", errout_str()); check("int f(std::vector x) {\n" " static int& i = x[0];\n" " return i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:24]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\n", errout_str()); check("int f(std::vector x) {\n" " int& i = x[0];\n" " i++;\n" " return i;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int& f(std::vector& x) {\n" " x.push_back(1);\n" " int& i = x[0];\n" " return i;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(const std::vector& x) {\n" " return x[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int& f(std::vector& x) {\n" " return x[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("const int& f(std::vector& x) {\n" " return x[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("int f(std::vector& x) {\n" " x[0]++;\n" " return x[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { int a; };\n" "A f(std::vector& x) {\n" " x[0].a = 1;\n" " return x[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { int a(); };\n" "A f(std::vector& x) {\n" " x[0].a();\n" " return x[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int g(int& x);\n" "int f(std::vector& x) {\n" " g(x[0]);\n" " return x[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("template\n" "T f(T& x) {\n" " return x[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("template\n" "T f(T&& x) {\n" " return x[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("template\n" "T f(T& x) {\n" " return x[0];\n" "}\n" - "void h() { std::vector v; h(v); }"); + "void h() { std::vector v; h(v); }\n"); ASSERT_EQUALS("", errout_str()); check("int f(int& x) {\n" " return std::move(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(std::ostream& os) {\n" " os << \"Hello\";\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void g(int*);\n" "void f(int& x) {\n" " g(&x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { A(int*); };\n" "A f(int& x) {\n" " return A(&x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { A(int*); };\n" "A f(int& x) {\n" " return A{&x};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int& x, int& y) {\n" " y++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct A {\n" " explicit A(int& y) : x(&y) {}\n" " int * x = nullptr;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" @@ -3072,7 +3072,7 @@ class TestOther : public TestFixture { " void swap(A& a) {\n" " v.swap(a.v);\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" @@ -3083,24 +3083,24 @@ class TestOther : public TestFixture { "};\n" "void g(A& a) {\n" " a.f();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(std::vector& v) {\n" " for(auto&& x:v)\n" " x = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(std::vector& v) {\n" " for(auto x:v)\n" " x = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\n", errout_str()); check("void f(std::vector& v) {\n" " for(auto& x:v) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (style) Variable 'x' can be declared as reference to const [constVariableReference]\n", errout_str()); @@ -3121,32 +3121,32 @@ class TestOther : public TestFixture { check("void f(std::vector& v) {\n" " for(const auto& x:v) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:26]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\n", errout_str()); check("void f(int& i) {\n" " int& j = i;\n" " j++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(std::vector& v) {\n" " int& i = v[0];\n" " i++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(std::map >& m, unsigned int i) {\n" " std::map& members = m[i];\n" " members.clear();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" " int& x;\n" " A(int& y) : x(y)\n" " {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" @@ -3155,14 +3155,14 @@ class TestOther : public TestFixture { "struct B : A {\n" " B(int& x) : A(x)\n" " {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool b, int& x, int& y) {\n" " auto& z = x;\n" " auto& w = b ? y : z;\n" " w = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" @@ -3170,7 +3170,7 @@ class TestOther : public TestFixture { "};\n" "int& f(S& s) {\n" " return s.i;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int* f(std::list& x, unsigned int y) {\n" @@ -3179,7 +3179,7 @@ class TestOther : public TestFixture { " return &m;\n" " }\n" " return nullptr;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int& f(std::list& x, int& y) {\n" @@ -3188,7 +3188,7 @@ class TestOther : public TestFixture { " return m;\n" " }\n" " return y;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool from_string(int& t, const std::string& s) {\n" @@ -3232,7 +3232,7 @@ class TestOther : public TestFixture { check("struct T { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" @@ -3240,86 +3240,86 @@ class TestOther : public TestFixture { " const T& z = x;\n" // Make sure we find all assignments " T& y = x;\n" " y.mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " const U& y = x\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " U& y = x;\n" " y.mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " my::type& y = x;\n" // we don't know if y is const or not " y.mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " const U& y = static_cast(x);\n" " y.mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " U& y = static_cast(x);\n" " y.mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " const U& y = dynamic_cast(x)\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " const U& y = dynamic_cast(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " const U& y = dynamic_cast(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " U& y = dynamic_cast(x);\n" " y.mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " const U& y = dynamic_cast(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " U& y = dynamic_cast(x);\n" " y.mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " U* y = dynamic_cast(&x);\n" " y->mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct T : public U { void dostuff() const {}};\n" @@ -3327,49 +3327,49 @@ class TestOther : public TestFixture { " x.dostuff();\n" " const U * y = dynamic_cast(&x);\n" " y->mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); TODO_ASSERT_EQUALS("can be const", errout_str(), ""); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " U const * y = dynamic_cast(&x);\n" " y->mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); TODO_ASSERT_EQUALS("can be const", errout_str(), ""); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " const U const * const * const * const y = dynamic_cast(&x);\n" " y->mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " const U const * const * const * const y = dynamic_cast(&x);\n" " y->mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); TODO_ASSERT_EQUALS("can be const", errout_str(), ""); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " const U const * const * * const y = dynamic_cast(&x);\n" " y->mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " my::fancy const * const * const y = dynamic_cast const * const * const>(&x);\n" " y->mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " const U& y = (const U&)(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\n" "[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); @@ -3378,13 +3378,13 @@ class TestOther : public TestFixture { " x.dostuff();\n" " U& y = (U&)(x);\n" " y.mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " const U& y = (typename const U&)(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:18]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\n" "[test.cpp:2:11]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); @@ -3393,14 +3393,14 @@ class TestOther : public TestFixture { " x.dostuff();\n" " U& y = (typename U&)(x);\n" " y.mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\n", errout_str()); check("struct T : public U { void dostuff() const {}};\n" "void a(T& x) {\n" " x.dostuff();\n" " U* y = (U*)(&x);\n" " y->mutate();\n" // to avoid warnings that y can be const - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:12]: (warning) Potentially invalid type conversion in old-style C cast, clarify/fix with C++ cast [dangerousTypeCast]\n", errout_str()); check("struct C { void f() const; };\n" // #9875 - crash @@ -3408,7 +3408,7 @@ class TestOther : public TestFixture { "void foo(C& x) {\n" " x.f();\n" " foo( static_cast(0) );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:13]: (style) Parameter 'x' can be declared as reference to const [constParameterReference]\n", errout_str()); check("class a {\n" @@ -3616,7 +3616,7 @@ class TestOther : public TestFixture { "void bh(const std::list &ak, const std::list &al);\n" "void ah();\n" "void an();\n" - "void h();"); + "void h();\n"); ASSERT_EQUALS("[test.cpp:131:12]: (style) Variable 'tm' can be declared as pointer to const [constVariablePointer]\n" "[test.cpp:136:19]: (style) Variable 'af' can be declared as pointer to const [constVariablePointer]\n" "[test.cpp:137:12]: (style) Variable 'ag' can be declared as pointer to const [constVariablePointer]\n", @@ -3640,7 +3640,7 @@ class TestOther : public TestFixture { "D::D(int& i)\n" " : c(i)\n" "{\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class C\n" @@ -3660,7 +3660,7 @@ class TestOther : public TestFixture { "\n" "D::D(int& i) noexcept\n" " : c(i)\n" - "{}"); + "{}\n"); ASSERT_EQUALS("", errout_str()); check("class C\n" @@ -3681,7 +3681,7 @@ class TestOther : public TestFixture { "D::D(int& i)\n" " : c(i)\n" "{\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\n", "", errout_str()); check("class C\n" @@ -3702,7 +3702,7 @@ class TestOther : public TestFixture { "D::D(int& i)\n" " : c(i)\n" "{\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\n", "", errout_str()); check("class C\n" @@ -3723,13 +3723,13 @@ class TestOther : public TestFixture { "D::D(int& i)\n" " : c(0, i)\n" "{\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:16]: (style) Parameter 'i' can be declared as reference to const\n", "", errout_str()); check("void f(std::map> &map) {\n" // #10266 " for (auto &[slave, panels] : map)\n" " panels.erase(it);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct S { void f(); int i; };\n" @@ -4080,7 +4080,7 @@ class TestOther : public TestFixture { "[test.cpp:10:25]: (style) Parameter 'v' can be declared as reference to const [constParameterReference]\n", errout_str()); - check("void push(V& v) { v.push_back({ .x = 1 }); }"); // #14010 + check("void push(V& v) { v.push_back({ .x = 1 }); }\n"); // #14010 ASSERT_EQUALS("", errout_str()); check("size_t* f(std::array& a) { return reinterpret_cast(a.data()); }\n"); // #14074 @@ -4170,7 +4170,7 @@ class TestOther : public TestFixture { void constParameterCallback() { check("int callback(std::vector& x) { return x[0]; }\n" - "void f() { dostuff(callback); }"); + "void f() { dostuff(callback); }\n"); ASSERT_EQUALS("[test.cpp:2:20] -> [test.cpp:1:32]: (style) Parameter 'x' can be declared as reference to const. However it seems that 'callback' is a callback function, if 'x' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\n", errout_str()); // #9906 @@ -4188,13 +4188,13 @@ class TestOther : public TestFixture { "\n" "void EventEngine::signalEvent(ev::sig& signal, int revents) {\n" " switch (signal.signum) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:48] -> [test.cpp:13:40]: (style) Parameter 'signal' can be declared as reference to const. However it seems that 'signalEvent' is a callback function, if 'signal' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\n", errout_str()); check("void f(int* p) {}\n" // 12843 "void g(std::map&m) {\n" " m[&f] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. " "However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\n", errout_str()); @@ -4220,49 +4220,49 @@ class TestOther : public TestFixture { } void constPointer() { - check("void foo(int *p) { return *p; }"); + check("void foo(int *p) { return *p; }\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); - check("void foo(int *p) { x = *p; }"); + check("void foo(int *p) { x = *p; }\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); - check("void foo(int *p) { int &ref = *p; ref = 12; }"); + check("void foo(int *p) { int &ref = *p; ref = 12; }\n"); ASSERT_EQUALS("", errout_str()); - check("void foo(int *p) { x = *p + 10; }"); + check("void foo(int *p) { x = *p + 10; }\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); - check("void foo(int *p) { return p[10]; }"); + check("void foo(int *p) { return p[10]; }\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); - check("void foo(int *p) { int &ref = p[0]; ref = 12; }"); + check("void foo(int *p) { int &ref = p[0]; ref = 12; }\n"); ASSERT_EQUALS("", errout_str()); - check("void foo(int *p) { x[*p] = 12; }"); + check("void foo(int *p) { x[*p] = 12; }\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); - check("void foo(int *p) { if (p) {} }"); + check("void foo(int *p) { if (p) {} }\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); - check("void foo(int *p) { if (p || x) {} }"); + check("void foo(int *p) { if (p || x) {} }\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); - check("void foo(int *p) { if (p == 0) {} }"); + check("void foo(int *p) { if (p == 0) {} }\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); - check("void foo(int *p) { if (!p) {} }"); + check("void foo(int *p) { if (!p) {} }\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); - check("void foo(int *p) { if (*p > 123) {} }"); + check("void foo(int *p) { if (*p > 123) {} }\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); - check("void foo(int *p) { return *p + 1; }"); + check("void foo(int *p) { return *p + 1; }\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); - check("void foo(int *p) { return *p > 1; }"); + check("void foo(int *p) { return *p > 1; }\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); - check("void foo(const int* c) { if (c == 0) {}; }"); + check("void foo(const int* c) { if (c == 0) {}; }\n"); ASSERT_EQUALS("", errout_str()); check("struct a { void b(); };\n" @@ -4295,59 +4295,59 @@ class TestOther : public TestFixture { " int& i = (*x)[0];\n" " i++;\n" " return i;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { int a; };\n" "A f(std::vector* x) {\n" " x->front().a = 1;\n" " return x->front();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(std::vector* v) {\n" " for(auto&& x:*v)\n" " x = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" " int* x;\n" " A(int* y) : x(y)\n" " {}\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool b, int* x, int* y) {\n" " int* z = x;\n" " int* w = b ? y : z;\n" " *w = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool b, int* x, int* y) {\n" " int& z = *x;\n" " int& w = b ? *y : z;\n" " w = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class Base { virtual void dostuff(int *p) = 0; };\n" // #10397 - "class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };"); + "class Derived: public Base { int x; void dostuff(int *p) override { x = *p; } };\n"); ASSERT_EQUALS("", errout_str()); check("struct Data { char buf[128]; };\n" // #10483 "void encrypt(Data& data) {\n" " const char a[] = \"asfasd\";\n" " memcpy(data.buf, &a, sizeof(a));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #10547 check("void foo(std::istream &istr) {\n" " unsigned char x[2];\n" " istr >> x[0];\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #10744 @@ -4898,7 +4898,7 @@ class TestOther : public TestFixture { check("struct S {\n" // #14817 " explicit S(int *a) : m{ a[0], a[1] } {}\n" " int m[2];\n" - "}" + "}\n" "struct T {\n" " explicit T(int *a) : m{ &a[0], &a[1] } {}\n" " int* m[2];\n" @@ -5019,7 +5019,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:11] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" @@ -5035,7 +5035,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" @@ -5052,7 +5052,7 @@ class TestOther : public TestFixture { " }\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" @@ -5070,7 +5070,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" @@ -5085,7 +5085,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" @@ -5100,7 +5100,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" @@ -5117,7 +5117,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" @@ -5134,7 +5134,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" @@ -5149,7 +5149,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" @@ -5164,7 +5164,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:11] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void bar() {}\n" // bar isn't noreturn @@ -5180,7 +5180,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:11] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo(int a) {\n" @@ -5192,7 +5192,7 @@ class TestOther : public TestFixture { " case 3:\n" " strcpy(str, \"b'\");\n" " }\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); TODO_ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", "", errout_str()); @@ -5206,7 +5206,7 @@ class TestOther : public TestFixture { " case 3:\n" " strncpy(str, \"b'\");\n" " }\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", "", errout_str()); @@ -5223,7 +5223,7 @@ class TestOther : public TestFixture { " strcpy(str, \"b'\");\n" " z++;\n" " }\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); TODO_ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", "", errout_str()); @@ -5239,7 +5239,7 @@ class TestOther : public TestFixture { " strcpy(str, \"b'\");\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int a) {\n" @@ -5252,7 +5252,7 @@ class TestOther : public TestFixture { " case 3:\n" " strcpy(str, \"b'\");\n" " }\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // Ticket #5158 "segmentation fault (valid code)" @@ -5285,7 +5285,7 @@ class TestOther : public TestFixture { " case 1: x = 3; goto a;\n" " case 1: x = 6; goto a;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -5301,7 +5301,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" @@ -5316,7 +5316,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" @@ -5329,7 +5329,7 @@ class TestOther : public TestFixture { " ++y;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5342,7 +5342,7 @@ class TestOther : public TestFixture { " ++y;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5355,7 +5355,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:9] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" @@ -5370,7 +5370,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:9] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" @@ -5383,7 +5383,7 @@ class TestOther : public TestFixture { " --y;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5396,7 +5396,7 @@ class TestOther : public TestFixture { " --y;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5409,7 +5409,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" @@ -5424,7 +5424,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" @@ -5437,7 +5437,7 @@ class TestOther : public TestFixture { " y++;\n" " }\n" " bar(y);\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5450,7 +5450,7 @@ class TestOther : public TestFixture { " y++;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5463,7 +5463,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:10] -> [test.cpp:9:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" @@ -5478,7 +5478,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:10] -> [test.cpp:11:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("void foo()\n" "{\n" @@ -5491,7 +5491,7 @@ class TestOther : public TestFixture { " y--;\n" " }\n" " bar(y);\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5504,7 +5504,7 @@ class TestOther : public TestFixture { " y--;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5520,7 +5520,7 @@ class TestOther : public TestFixture { " }\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5537,7 +5537,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5551,7 +5551,7 @@ class TestOther : public TestFixture { " y++;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5565,7 +5565,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5581,7 +5581,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5597,7 +5597,7 @@ class TestOther : public TestFixture { " }\n" " bar(y);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5611,7 +5611,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5625,7 +5625,7 @@ class TestOther : public TestFixture { " y = 3;\n" " }\n" " bar(y);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:10] -> [test.cpp:10:11]: (style) Variable 'y' is reassigned a value before the old one has been used. 'break;' missing? [redundantAssignInSwitch]\n", errout_str()); check("bool f() {\n" @@ -5643,7 +5643,7 @@ class TestOther : public TestFixture { " };\n" " ret = true;\n" " return ret;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:8:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:11:13] -> [test.cpp:14:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\n", @@ -5662,7 +5662,7 @@ class TestOther : public TestFixture { " y |= 3;\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\n", errout_str()); check("void foo(int a)\n" @@ -5676,7 +5676,7 @@ class TestOther : public TestFixture { " y = y | 3;\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\n", errout_str()); check("void foo(int a)\n" @@ -5690,7 +5690,7 @@ class TestOther : public TestFixture { " y |= 3;\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\n", errout_str()); check("void foo(int a)\n" @@ -5705,7 +5705,7 @@ class TestOther : public TestFixture { " y |= 3;\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int a)\n" @@ -5720,7 +5720,7 @@ class TestOther : public TestFixture { " y |= z;\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int a)\n" @@ -5735,7 +5735,7 @@ class TestOther : public TestFixture { " y |= 3;\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int a)\n" @@ -5750,7 +5750,7 @@ class TestOther : public TestFixture { " y |= 3;\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:11] -> [test.cpp:8:11]: (style) Variable 'y' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); check("void foo(int a)\n" @@ -5764,7 +5764,7 @@ class TestOther : public TestFixture { " y &= 3;\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:9]: (style) Redundant bitwise operation on 'y' in 'switch' statement. 'break;' missing? [redundantBitwiseOperationInSwitch]\n", errout_str()); check("void foo(int a)\n" @@ -5779,7 +5779,7 @@ class TestOther : public TestFixture { " y |= 3;\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int a)\n" @@ -5793,7 +5793,7 @@ class TestOther : public TestFixture { " y ^= 3;\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int a)\n" @@ -5807,7 +5807,7 @@ class TestOther : public TestFixture { " y |= 3;\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int a)\n" @@ -5821,7 +5821,7 @@ class TestOther : public TestFixture { " y &= 3;\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int a)\n" @@ -5835,7 +5835,7 @@ class TestOther : public TestFixture { " y &= 2;\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -5847,20 +5847,20 @@ class TestOther : public TestFixture { " continue;\n" " }\n" " }\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("int foo(int a) {\n" " return 0;\n" " return(a-1);\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("int foo(int a) {\n" " A:" " return(0);\n" " goto A;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); constexpr char xmldata[] = "\n" @@ -5875,7 +5875,7 @@ class TestOther : public TestFixture { check("void foo() {\n" " exit(0);\n" " break;\n" - "}", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); + "}\n", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("class NeonSession {\n" @@ -5884,16 +5884,16 @@ class TestOther : public TestFixture { "void NeonSession::exit()\n" "{\n" " SAL_INFO(\"ucb.ucp.webdav\", \"neon commands cannot be aborted\");\n" - "}", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); + "}\n", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); ASSERT_EQUALS("", errout_str()); check("void NeonSession::exit()\n" "{\n" " SAL_INFO(\"ucb.ucp.webdav\", \"neon commands cannot be aborted\");\n" - "}", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); + "}\n", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); ASSERT_EQUALS("", errout_str()); - check("void foo() { xResAccess->exit(); }", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); + check("void foo() { xResAccess->exit(); }\n", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); ASSERT_EQUALS("", errout_str()); check("void foo(int a)\n" @@ -5907,7 +5907,7 @@ class TestOther : public TestFixture { " c++;\n" " break;\n" " }\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("void foo(int a)\n" @@ -5920,7 +5920,7 @@ class TestOther : public TestFixture { " c++;\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int a)\n" @@ -5931,7 +5931,7 @@ class TestOther : public TestFixture { " break;\n" " }\n" " }\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("void foo(int a)\n" @@ -5943,7 +5943,7 @@ class TestOther : public TestFixture { " }\n" " a+=2;\n" " }\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("void foo(int a)\n" @@ -5954,50 +5954,50 @@ class TestOther : public TestFixture { " }\n" " a+=2;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int foo() {\n" " throw 0;\n" " return 1;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("void foo() {\n" " throw 0;\n" " return;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("int foo() {\n" " throw = 0;\n" " return 1;\n" - "}", dinit(CheckOptions, $.cpp = false, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.cpp = false, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("int foo() {\n" " return 0;\n" " return 1;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("int foo() {\n" " return 0;\n" " foo();\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\n", errout_str()); check("int foo(int unused) {\n" " return 0;\n" " (void)unused;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("int foo(int unused1, int unused2) {\n" " return 0;\n" " (void)unused1;\n" " (void)unused2;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("int foo(int unused1, int unused2) {\n" @@ -6005,14 +6005,14 @@ class TestOther : public TestFixture { " (void)unused1;\n" " (void)unused2;\n" " foo();\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\n", errout_str()); check("int foo() {\n" " if(bar)\n" " return 0;\n" " return 124;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int foo() {\n" @@ -6023,7 +6023,7 @@ class TestOther : public TestFixture { " return 0;\n" " }\n" " return 124;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("void foo() {\n" @@ -6031,7 +6031,7 @@ class TestOther : public TestFixture { " return;\n" " break;\n" " }\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); // #5707 @@ -6042,20 +6042,20 @@ class TestOther : public TestFixture { " }\n" " return 0;\n" " j=2;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\n", errout_str()); check("int foo() {\n" " return 0;\n" " label:\n" " throw 0;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\n", errout_str()); check("struct A {\n" " virtual void foo (P & Val) throw ();\n" " virtual void foo1 (P & Val) throw ();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int foo() {\n" @@ -6064,7 +6064,7 @@ class TestOther : public TestFixture { " bar();\n" " label:\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #3457 check("int foo() {\n" @@ -6073,7 +6073,7 @@ class TestOther : public TestFixture { " bar();\n" " label:\n" " } while (true);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #3457 check("int foo() {\n" @@ -6082,7 +6082,7 @@ class TestOther : public TestFixture { " bar();\n" " label:\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #3457 // #3383. TODO: Use preprocessor @@ -6091,20 +6091,20 @@ class TestOther : public TestFixture { " return 0;\n" "\n" // #endif " return 1;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("int foo() {\n" "\n" // #ifdef A " return 0;\n" "\n" // #endif " return 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); // #4711 lambda functions check("int f() {\n" " return g([](int x){(void)x+1; return x;});\n" - "}", + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); @@ -6119,7 +6119,7 @@ class TestOther : public TestFixture { " __asm__ (\"rorw $8, %w0\" : \"=r\" (__v) : \"0\" (__x) : \"cc\");\n" " (void)__v;\n" " }));\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // #6008 @@ -6128,7 +6128,7 @@ class TestOther : public TestFixture { " int sum = a_ + b_;\n" " return sum;\n" " };\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // #5789 @@ -6136,20 +6136,20 @@ class TestOther : public TestFixture { " uint64_t enter, exit;\n" " uint64_t events;\n" " per_state_info() : enter(0), exit(0), events(0) {}\n" - "};", dinit(CheckOptions, $.inconclusive = false)); + "};\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // #6664 check("void foo() {\n" " (beat < 100) ? (void)0 : exit(0);\n" " bar();\n" - "}", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); + "}\n", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " (beat < 100) ? exit(0) : (void)0;\n" " bar();\n" - "}", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); + "}\n", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); ASSERT_EQUALS("", errout_str()); // #8261 @@ -6157,13 +6157,13 @@ class TestOther : public TestFixture { TODO_ASSERT_THROW(check("void foo() {\n" " (beat < 100) ? (void)0 : throw(0);\n" " bar();\n" - "}", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)), InternalError); + "}\n", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)), InternalError); //ASSERT_EQUALS("", errout_str()); check("int foo() {\n" " exit(0);\n" " return 1;\n" // <- clarify for tools that function does not continue.. - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -6406,7 +6406,7 @@ class TestOther : public TestFixture { " case A||B:\n" " foo();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '&&' probably doesn't work as intended. [suspiciousCase]\n" "[test.cpp:5:16]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\n" "[test.cpp:7:15]: (warning, inconclusive) Found suspicious case label in switch(). Operator '||' probably doesn't work as intended. [suspiciousCase]\n", errout_str()); @@ -6416,7 +6416,7 @@ class TestOther : public TestFixture { " case 1:\n" " a=A&&B;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // TODO Do not throw AST validation exception @@ -6425,19 +6425,19 @@ class TestOther : public TestFixture { " case A&&B?B:A:\n" " foo();\n" " }\n" - "}"), InternalError); + "}\n"), InternalError); //ASSERT_EQUALS("", errout_str()); } void suspiciousEqualityComparison() { check("void foo(int c) {\n" " if (x) c == 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); check("void foo(const int* c) {\n" " if (x) *c == 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); @@ -6445,90 +6445,90 @@ class TestOther : public TestFixture { " if (c == 1) {\n" " c = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int c) {\n" " c == 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:7]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); check("void foo(int c) {\n" " for (int i = 0; i == 10; i ++) {\n" " a ++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int c) {\n" " for (i == 0; i < 10; i ++) {\n" " c ++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); check("void foo(int c) {\n" " for (i == 1; i < 10; i ++) {\n" " c ++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); check("void foo(int c) {\n" " for (i == 2; i < 10; i ++) {\n" " c ++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); check("void foo(int c) {\n" " for (int i = 0; i < 10; i == c) {\n" " c ++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:31]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); check("void foo(int c) {\n" " for (; running == 1;) {\n" " c ++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int c) {\n" " printf(\"%i\", ({x==0;}));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int arg) {\n" " printf(\"%i\", ({int x = do_something(); x == 0;}));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int x) {\n" " printf(\"%i\", ({x == 0; x > 0 ? 10 : 20}));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:22]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead? [constStatement]\n", errout_str()); check("void foo(int x) {\n" " for (const Token* end = tok->link(); tok != end; tok = (tok == end) ? end : tok->next()) {\n" " x++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int x) {\n" " for (int i = (x == 0) ? 0 : 5; i < 10; i ++) {\n" " x++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int x) {\n" " for (int i = 0; i < 10; i += (x == 5) ? 1 : 2) {\n" " x++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -6584,26 +6584,26 @@ class TestOther : public TestFixture { " int x = 1;\n" " x = x;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n", errout_str()); check("void foo()\n" "{\n" " int x = x;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n", errout_str()); check("struct A { int b; };\n" "void foo(A* a1, A* a2) {\n" " a1->b = a1->b;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11]: (style) Redundant assignment of 'a1->b' to itself. [selfAssignment]\n", errout_str()); check("int x;\n" "void f()\n" "{\n" " x = x = 3;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n", errout_str()); // #4073 (segmentation fault) @@ -6611,59 +6611,59 @@ class TestOther : public TestFixture { "{\n" " if (a == 42)\n" " a = a;\n" - "}"); + "}\n"); check("void foo()\n" "{\n" " int x = 1;\n" " x = x + 1;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" " int *x = getx();\n" " *x = x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " BAR *x = getx();\n" " x = x;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:7]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n", errout_str()); // #2502 - non-primitive type -> there might be some side effects check("void foo()\n" "{\n" " Fred fred; fred = fred;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " x = (x == 0);" " func(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int x) {\n" " x = (x != 0);" " func(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // ticket #3001 - false positive check("void foo(int x) {\n" " x = x ? x : 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #3800 - false negative when variable is extern check("extern int i;\n" "void f() {\n" " i = i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:7]: (style) Redundant assignment of 'i' to itself. [selfAssignment]\n", errout_str()); // #4291 - id for variables accessed through 'this' @@ -6673,7 +6673,7 @@ class TestOther : public TestFixture { "};\n" "void Foo::func() {\n" " this->var = var;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:15]: (style) Redundant assignment of 'this->var' to itself. [selfAssignment]\n", errout_str()); check("class Foo {\n" @@ -6682,7 +6682,7 @@ class TestOther : public TestFixture { "};\n" "Foo::Foo(int var) {\n" " this->var = var;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #6406 - designated initializer doing bogus self assignment @@ -6692,7 +6692,7 @@ class TestOther : public TestFixture { "void something(void) {}\n" "void f() {\n" " struct callbacks ops = { .s = ops.s };\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:6]: (style) Redundant assignment of 'something' to itself.\n", "", errout_str()); check("class V\n" @@ -6707,12 +6707,12 @@ class TestOther : public TestFixture { " x = x; y = y; z = z;\n" " }\n" " double x, y, z;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:10:11]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n" "[test.cpp:10:18]: (style) Redundant assignment of 'y' to itself. [selfAssignment]\n" "[test.cpp:10:25]: (style) Redundant assignment of 'z' to itself. [selfAssignment]\n", errout_str()); - check("void f(int i) { i = !!i; }"); + check("void f(int i) { i = !!i; }\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -6782,7 +6782,7 @@ class TestOther : public TestFixture { " Lock(123);\n" " std::cout << \"hello\" << std::endl;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:15:5]: (style) Instance of 'Lock' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); } @@ -6801,7 +6801,7 @@ class TestOther : public TestFixture { "{\n" " CouldBeFunction ( 123 ) ;\n" " return 0 ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -6818,7 +6818,7 @@ class TestOther : public TestFixture { " error();\n" " do_something();\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); } @@ -6828,7 +6828,7 @@ class TestOther : public TestFixture { "{\n" " NotAFunction ( 123 );\n" " return 0 ;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (style) Instance of 'NotAFunction' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); } @@ -6838,7 +6838,7 @@ class TestOther : public TestFixture { "{\n" " NotAClass ( 123 ) ;\n" " return true ;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (style) Instance of 'NotAClass' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); } @@ -6847,7 +6847,7 @@ class TestOther : public TestFixture { "{\n" " if ( a > b ) return c == a ;\n" " return b == a ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -6857,7 +6857,7 @@ class TestOther : public TestFixture { "public:\n" "~Something ( ) ;\n" "Something ( ) ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -6876,7 +6876,7 @@ class TestOther : public TestFixture { " int a = 1;\n" " IncrementFunctor()(a);\n" " return a;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -6889,7 +6889,7 @@ class TestOther : public TestFixture { " };\n" " Foo();\n" " do_something();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); } @@ -6901,7 +6901,7 @@ class TestOther : public TestFixture { "\n" "void fn() {\n" " Foo().bar();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -6930,7 +6930,7 @@ class TestOther : public TestFixture { "void foo() {\n" " stat(\"file.txt\", &st);\n" " do_something();\n" - "}"); + "}\n"); ASSERT_EQUALS("",errout_str()); check("struct AMethodObject {\n" // #4336 @@ -7084,7 +7084,7 @@ class TestOther : public TestFixture { "\n" " { sigaction(SIGHUP, &sa, 0); };\n" " { sigaction(SIGINT, &sa, 0); };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -7095,76 +7095,76 @@ class TestOther : public TestFixture { " };\n" "\n" " const AB ab[3] = { AB(0), AB(1), AB(2) };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void clarifyCalculation() { check("int f(char c) {\n" " return 10 * (c == 0) ? 1 : 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:26]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\n", errout_str()); check("void f(char c) {\n" " printf(\"%i\", 10 * (c == 0) ? 1 : 2);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:32]: (style) Clarify calculation precedence for '*' and '?'. [clarifyCalculation]\n", errout_str()); check("void f() {\n" " return (2*a)?b:c;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(char c) {\n" " printf(\"%i\", a + b ? 1 : 2);\n" - "}",dinit(CheckOptions, $.inconclusive = false)); + "}\n",dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\n", errout_str()); check("void f() {\n" " std::cout << x << y ? 2 : 3;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:25]: (style) Clarify calculation precedence for '<<' and '?'. [clarifyCalculation]\n", errout_str()); check("void f() {\n" " int ab = a - b ? 2 : 3;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20]: (style) Clarify calculation precedence for '-' and '?'. [clarifyCalculation]\n", errout_str()); check("void f() {\n" " int ab = a | b ? 2 : 3;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20]: (style) Clarify calculation precedence for '|' and '?'. [clarifyCalculation]\n", errout_str()); // ticket #195 check("int f(int x, int y) {\n" " return x >> ! y ? 8 : 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:21]: (style) Clarify calculation precedence for '>>' and '?'. [clarifyCalculation]\n", errout_str()); check("int f() {\n" " return shift < sizeof(int64_t)*8 ? 1 : 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); - check("void f() { a = *p ? 1 : 2; }"); + check("void f() { a = *p ? 1 : 2; }\n"); ASSERT_EQUALS("", errout_str()); - check("void f(int x) { const char *p = x & 1 ? \"1\" : \"0\"; }"); + check("void f(int x) { const char *p = x & 1 ? \"1\" : \"0\"; }\n"); ASSERT_EQUALS("", errout_str()); - check("void foo() { x = a % b ? \"1\" : \"0\"; }"); + check("void foo() { x = a % b ? \"1\" : \"0\"; }\n"); ASSERT_EQUALS("", errout_str()); - check("void f(int x) { return x & 1 ? '1' : '0'; }"); + check("void f(int x) { return x & 1 ? '1' : '0'; }\n"); ASSERT_EQUALS("", errout_str()); - check("void f(int x) { return x & 16 ? 1 : 0; }"); + check("void f(int x) { return x & 16 ? 1 : 0; }\n"); ASSERT_EQUALS("", errout_str()); - check("void f(int x) { return x % 16 ? 1 : 0; }"); + check("void f(int x) { return x % 16 ? 1 : 0; }\n"); ASSERT_EQUALS("", errout_str()); - check("enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }"); + check("enum {X,Y}; void f(int x) { return x & Y ? 1 : 0; }\n"); ASSERT_EQUALS("", errout_str()); } @@ -7172,7 +7172,7 @@ class TestOther : public TestFixture { check("char* f(char* c) {\n" " *c++;\n" " return c;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\n" "[test.cpp:2:7]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\n", @@ -7181,7 +7181,7 @@ class TestOther : public TestFixture { check("char* f(char** c) {\n" " *c[5]--;\n" " return *c;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\n" "[test.cpp:2:10]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\n", @@ -7189,7 +7189,7 @@ class TestOther : public TestFixture { check("void f(Foo f) {\n" " *f.a++;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\n" "[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\n", @@ -7197,7 +7197,7 @@ class TestOther : public TestFixture { check("void f(Foo f) {\n" " *f.a[5].v[3]++;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\n" "[test.cpp:2:17]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\n", @@ -7205,7 +7205,7 @@ class TestOther : public TestFixture { check("void f(Foo f) {\n" " *f.a(1, 5).v[x + y]++;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\n" "[test.cpp:2:24]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\n", @@ -7214,18 +7214,18 @@ class TestOther : public TestFixture { check("char* f(char* c) {\n" " (*c)++;\n" " return c;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(char* c) {\n" " bar(*c++);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("char*** f(char*** c) {\n" " ***c++;\n" " return c;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\n" "[test.cpp:2:9]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\n", @@ -7234,7 +7234,7 @@ class TestOther : public TestFixture { check("char** f(char*** c) {\n" " **c[5]--;\n" " return **c;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '*', result is not used. [constStatement]\n" "[test.cpp:2:11]: (warning) In expression like '*A++' the result of '*' is unused. Did you intend to write '(*A)++;'? [clarifyStatement]\n", @@ -7243,7 +7243,7 @@ class TestOther : public TestFixture { check("char*** f(char*** c) {\n" " (***c)++;\n" " return c;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(const int*** p) {\n" // #10923 @@ -7253,12 +7253,12 @@ class TestOther : public TestFixture { check("void *f(char** c) {\n" " bar(**c++);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void *f(char* p) {\n" " for (p = path; *p++;) ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -7278,7 +7278,7 @@ class TestOther : public TestFixture { " b = 1;\n" " else\n" " b = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n", errout_str()); check("void f(int a, int &b) {\n" @@ -7289,7 +7289,7 @@ class TestOther : public TestFixture { " b = 2;\n" " } else\n" " b = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:3:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n", errout_str()); check("void f(int a, int &b) {\n" @@ -7301,7 +7301,7 @@ class TestOther : public TestFixture { " else\n" " b = 2;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:9] -> [test.cpp:5:9]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n", errout_str()); check("int f(int signed, unsigned char value) {\n" @@ -7311,7 +7311,7 @@ class TestOther : public TestFixture { " else\n" " ret = (unsigned char)value;\n" " return ret;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -7319,7 +7319,7 @@ class TestOther : public TestFixture { " __asm__(\"mov ax, bx\");\n" " else\n" " __asm__(\"mov bx, bx\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #3407 check("void f() {\n" @@ -7327,7 +7327,7 @@ class TestOther : public TestFixture { " __asm__(\"mov ax, bx\");\n" " else\n" " __asm__(\"mov ax, bx\");\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5] -> [test.cpp:2:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n", errout_str()); } @@ -7341,7 +7341,7 @@ class TestOther : public TestFixture { " frac = front/(front-back);\n" " else\n" " frac = front/(front-back);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n", errout_str()); check("void f()\n" @@ -7350,7 +7350,7 @@ class TestOther : public TestFixture { " { frac = front/(front-back);}\n" " else\n" " frac = front/((front-back));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:3] -> [test.cpp:3:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n", errout_str()); // No message about empty branches (#5354) @@ -7360,7 +7360,7 @@ class TestOther : public TestFixture { " {}\n" " else\n" " {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -7372,7 +7372,7 @@ class TestOther : public TestFixture { " DOSTUFF1\n" " else\n" " DOSTUFF2\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -7384,7 +7384,7 @@ class TestOther : public TestFixture { " } else {\n" " x = j;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:5:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n" "[test.cpp:2:9]: (style) The scope of the variable 'j' can be reduced. [variableScope]\n", errout_str()); @@ -7397,7 +7397,7 @@ class TestOther : public TestFixture { " } else {\n" " x = j;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -7408,7 +7408,7 @@ class TestOther : public TestFixture { " } else {\n" " return new A::Z(true);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -7422,7 +7422,7 @@ class TestOther : public TestFixture { " unsigned int i = 0;\n" " j = i;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:7] -> [test.cpp:3:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'. [duplicateBranch]\n", errout_str()); check("void f(bool b) {\n" @@ -7434,7 +7434,7 @@ class TestOther : public TestFixture { " unsigned int i = 0;\n" " j = 1;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool b) {\n" @@ -7444,7 +7444,7 @@ class TestOther : public TestFixture { " } else {\n" " int i = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool b) {\n" @@ -7456,7 +7456,7 @@ class TestOther : public TestFixture { " int i = 0;\n" " j = i;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int i) {\n" @@ -7475,7 +7475,7 @@ class TestOther : public TestFixture { " } else {\n" " int i = 0;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool b) {\n" @@ -7483,14 +7483,14 @@ class TestOther : public TestFixture { " int i = 0;\n" " } else {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void duplicateExpression1() { check("void foo(int a) {\n" " if (a == a) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\n", errout_str()); check("void fun(int b) {\n" @@ -7499,7 +7499,7 @@ class TestOther : public TestFixture { " d > d &&\n" " e < e &&\n" " f ;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\n" "[test.cpp:3:15]: (style) Same expression on both sides of '=='. [duplicateExpression]\n" "[test.cpp:4:15]: (style) Same expression on both sides of '>'. [duplicateExpression]\n" @@ -7507,82 +7507,82 @@ class TestOther : public TestFixture { check("void foo() {\n" " return a && a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (style) Same expression on both sides of '&&'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " a = b && b;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Same expression on both sides of '&&'. [duplicateExpression]\n", errout_str()); check("void foo(int b) {\n" " f(a,b == b);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Same expression on both sides of '=='. [duplicateExpression]\n", errout_str()); check("void foo(int b) {\n" " f(b == b, a);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Same expression on both sides of '=='. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (x!=2 || x!=2) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); check("void foo(int a, int b) {\n" " if ((a < b) && (b > a)) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (style) Same expression on both sides of '&&' because 'aa' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void foo(int a, int b) {\n" " if ((a <= b) && (b >= a)) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'a<=b' and 'b>=a' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void foo() {\n" " if (x!=2 || y!=3 || x!=2) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:22]: (style) Same expression 'x!=2' found multiple times in chain of '||' operators. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (x!=2 && (x=y) && x!=2) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " if (a && b || a && b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (a && b || b && c) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " if (a && b | b && c) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (style) Same expression on both sides of '|'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if ((a + b) | (a + b)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (style) Same expression on both sides of '|'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if ((a | b) & (a | b)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (style) Same expression on both sides of '&'. [duplicateExpression]\n", errout_str()); check("void foo(int a, int b) {\n" " if ((a | b) == (a | b)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (style) Same expression on both sides of '=='. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (a1[a2[c & 0xff] & 0xff]) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void d(const char f, int o, int v)\n" @@ -7590,127 +7590,127 @@ class TestOther : public TestFixture { " if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\n" " ((f=='R') && (o == 2) && ((v < 2) || (v > 99))) ||\n" " ((f=='T') && (o == 2) && ((v < 200) || (v > 9999)))) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); - check("int f(int x) { return x+x; }"); + check("int f(int x) { return x+x; }\n"); ASSERT_EQUALS("", errout_str()); - check("void f(int x) { while (x+=x) ; }"); + check("void f(int x) { while (x+=x) ; }\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " if (a && b && b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (style) Same expression on both sides of '&&'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (a || b || b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (a / 1000 / 1000) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int foo(int i) {\n" " return i/i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Same expression on both sides of '/'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (a << 1 << 1) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); - check("int f() { return !!y; }"); // No FP + check("int f() { return !!y; }\n"); // No FP ASSERT_EQUALS("", errout_str()); // make sure there are not "same expression" fp when there are different casts - check("void f(long x) { if ((int32_t)x == (int64_t)x) {} }", + check("void f(long x) { if ((int32_t)x == (int64_t)x) {} }\n", dinit(CheckOptions, $.inconclusive = false) ); ASSERT_EQUALS("", errout_str()); // make sure there are not "same expression" fp when there are different ({}) expressions - check("void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }"); + check("void f(long x) { if (({ 1+2; }) == ({3+4;})) {} }\n"); ASSERT_EQUALS("", errout_str()); // #5535: Reference named like its type - check("void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }"); + check("void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }\n"); ASSERT_EQUALS("[test.cpp:1:25]: (style) Variable 'UMSConfig' can be declared as reference to const [constVariableReference]\n", errout_str()); // #3868 - false positive (same expression on both sides of |) check("void f(int x) {\n" " a = x ? A | B | C\n" " : A | B;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(const Bar &bar) {\n" " bool a = bar.isSet() && bar->isSet();\n" " bool b = bar.isSet() && bar.isSet();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:26]: (style) Same expression on both sides of '&&'. [duplicateExpression]\n", errout_str()); check("void foo(int a, int b) {\n" " if ((b + a) | (a + b)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (style) Same expression on both sides of '|' because 'b+a' and 'a+b' represent the same value. [duplicateExpression]\n", errout_str()); check("void foo(const std::string& a, const std::string& b) {\n" " return a.find(b+\"&\") || a.find(\"&\"+b);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int a, int b) {\n" " if ((b > a) | (a > b)) {}\n" // > is not commutative - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(double a, double b) {\n" " if ((b + a) > (a + b)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17]: (style) The comparison 'b+a > a+b' is always false because 'b+a' and 'a+b' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f(int x) {\n" " if ((x == 1) && (x == 0x00000001))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:18]: (style) Same expression on both sides of '&&' because 'x==1' and 'x==0x00000001' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " enum { Four = 4 };\n" - " if (Four == 4) {}" - "}"); + " if (Four == 4) {}\n" + "}\n"); ASSERT_EQUALS("[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " enum { Four = 4 };\n" " static_assert(Four == 4, \"\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " enum { Four = 4 };\n" " _Static_assert(Four == 4, \"\");\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " enum { Four = 4 };\n" " static_assert(4 == Four, \"\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " enum { FourInEnumOne = 4 };\n" " enum { FourInEnumTwo = 4 };\n" " if (FourInEnumOne == FourInEnumTwo) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\n", errout_str()); @@ -7718,13 +7718,13 @@ class TestOther : public TestFixture { " enum { FourInEnumOne = 4 };\n" " enum { FourInEnumTwo = 4 };\n" " static_assert(FourInEnumOne == FourInEnumTwo, \"\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int a, int b) {\n" " if (sizeof(a) == sizeof(a)) { }\n" " if (sizeof(a) == sizeof(b)) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:19]: (style) Same expression on both sides of '=='. [duplicateExpression]\n", errout_str()); check("float bar(int) __attribute__((pure));\n" @@ -7733,7 +7733,7 @@ class TestOther : public TestFixture { " if (bar(a) == bar(a)) { }\n" " if (unknown(a) == unknown(a)) { }\n" " if (foo(a) == foo(a)) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:16]: (style) Same expression on both sides of '=='. [duplicateExpression]\n", errout_str()); } @@ -7743,25 +7743,25 @@ class TestOther : public TestFixture { " if (!(dbl == dbl)) have_nan = 1;\n" " if (flt != flt) have_nan = 1;\n" " return have_nan;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); - check("float f(float x) { return x-x; }"); // ticket #4485 (Inf) + check("float f(float x) { return x-x; }\n"); // ticket #4485 (Inf) ASSERT_EQUALS("", errout_str()); - check("float f(float x) { return (X double)x == (X double)x; }", dinit(CheckOptions, $.inconclusive = false)); + check("float f(float x) { return (X double)x == (X double)x; }\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("struct X { float f; };\n" - "float f(struct X x) { return x.f == x.f; }"); + "float f(struct X x) { return x.f == x.f; }\n"); ASSERT_EQUALS("", errout_str()); check("struct X { int i; };\n" - "int f(struct X x) { return x.i == x.i; }"); + "int f(struct X x) { return x.i == x.i; }\n"); ASSERT_EQUALS("[test.cpp:2:32]: (style) Same expression on both sides of '=='. [duplicateExpression]\n", errout_str()); // #5284 - when type is unknown, assume it's float - check("int f() { return x==x; }"); + check("int f() { return x==x; }\n"); ASSERT_EQUALS("", errout_str()); } @@ -7778,7 +7778,7 @@ class TestOther : public TestFixture { check("void foo() {\n" " if (x() || x()) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A {\n" @@ -7787,7 +7787,7 @@ class TestOther : public TestFixture { "};\n" "void A::foo() const {\n" " if (bar() && bar()) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:15]: (style) Same expression on both sides of '&&'. [duplicateExpression]\n", errout_str()); check("struct A {\n" @@ -7797,7 +7797,7 @@ class TestOther : public TestFixture { "};\n" "void A::foo() {\n" " if (bar() && bar()) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class B {\n" @@ -7811,55 +7811,55 @@ class TestOther : public TestFixture { " A a;\n" " if (b.bar(1) && b.bar(1)) {}\n" " if (a.bar(1) && a.bar(1)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:11:18]: (style) Same expression on both sides of '&&'. [duplicateExpression]\n", errout_str()); check("class D { void strcmp(); };\n" "void foo() {\n" " D d;\n" " if (d.strcmp() && d.strcmp()) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\n" - "}", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); + "}\n", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); ASSERT_EQUALS("[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); check("void GetValue() { return rand(); }\n" "void foo() {\n" " if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void __attribute__((const)) GetValue() { return X; }\n" "void foo() {\n" " if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); check("void GetValue() __attribute__((const));\n" "void GetValue() { return X; }\n" "void foo() {\n" " if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:27]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (str == \"(\" || str == \"(\") {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); check("void foo() {\n" " if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #5334 check("void f(C *src) {\n" " if (x(src) || x(src))\n" " a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(A *src) {\n" @@ -7870,12 +7870,12 @@ class TestOther : public TestFixture { // #5819 check("Vector func(Vector vec1) {\n" " return fabs(vec1 & vec1 & vec1);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("Vector func(int vec1) {\n" " return fabs(vec1 & vec1 & vec1);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:22]: (style) Same expression on both sides of '&'. [duplicateExpression]\n" "[test.cpp:2:29]: (style) Same expression on both sides of '&'. [duplicateExpression]\n", @@ -7886,25 +7886,25 @@ class TestOther : public TestFixture { void duplicateExpression4() { check("void foo() {\n" " if (*a++ != b || *a++ != b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " if (*a-- != b || *a-- != b) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // assignment check("void f() {\n" " while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void duplicateExpression5() { // #3749 - macros with same values check("void f() {\n" " if ($a == $a) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkP("#define X 1\n" @@ -7926,7 +7926,7 @@ class TestOther : public TestFixture { void duplicateExpression6() { // #4639 check("float IsNan(float value) { return !(value == value); }\n" "double IsNan(double value) { return !(value == value); }\n" - "long double IsNan(long double value) { return !(value == value); }"); + "long double IsNan(long double value) { return !(value == value); }\n"); ASSERT_EQUALS("", errout_str()); } @@ -7934,36 +7934,36 @@ class TestOther : public TestFixture { check("void f() {\n" " const int i = sizeof(int);\n" " if ( i != sizeof (int)){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:25] -> [test.cpp:3:12]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " const int i = sizeof(int);\n" " if ( sizeof (int) != i){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:25] -> [test.cpp:3:23]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value. [knownConditionTrueFalse]\n", errout_str()); - check("void f(int a = 1) { if ( a != 1){}}"); + check("void f(int a = 1) { if ( a != 1){}}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int a = 1;\n" " if ( a != 1){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int a = 1;\n" " int b = 1;\n" " if ( a != b){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " int a = 1;\n" " int b = a;\n" " if ( a != b){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:13] -> [test.cpp:4:12]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value. [knownConditionTrueFalse]\n", errout_str()); check("void use(int);\n" @@ -7972,7 +7972,7 @@ class TestOther : public TestFixture { " int b = 1;\n" " use(b);\n" " if ( a != 1){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:13] -> [test.cpp:6:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void use(int);\n" @@ -7981,7 +7981,7 @@ class TestOther : public TestFixture { " use(a);\n" " a = 2;\n" " if ( a != 1){}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void use(int);\n" @@ -7990,38 +7990,38 @@ class TestOther : public TestFixture { " use(a);\n" " a = 1;\n" " if ( a != 1){}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("const int a = 1;\n" "void f() {\n" " if ( a != 1){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:15] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\n", errout_str()); check("int a = 1;\n" " void f() {\n" " if ( a != 1){}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " static const int a = 1;\n" " if ( a != 1){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:26] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" " static int a = 1;\n" " if ( a != 1){}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int a = 1;\n" " if ( a != 1){\n" " a++;\n" - " }}"); + " }}\n"); ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:3:12]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void f(int b) {\n" @@ -8030,13 +8030,13 @@ class TestOther : public TestFixture { " if ( a != 1){}\n" " a++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(bool a, bool b) {\n" " const bool c = a;\n" " return a && b && c;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20] -> [test.cpp:3:19]: (style) Same expression 'a' found multiple times in chain of '&&' operators because 'a' and 'c' represent the same value. [knownConditionTrueFalse]\n", errout_str()); @@ -8044,13 +8044,13 @@ class TestOther : public TestFixture { check("void f(const bool b) {\n" " const bool b1 = !b;\n" " if(!b && b1){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20] -> [test.cpp:3:10]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value. [knownConditionTrueFalse]\n", errout_str()); // 7284 check("void f(void) {\n" " if (a || !!a) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value. [knownConditionTrueFalse]\n", errout_str()); // 8205 @@ -8061,7 +8061,7 @@ class TestOther : public TestFixture { " if (Diag==0) {}\n" " break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15] -> [test.cpp:5:16]: (style) The comparison 'Diag == 0' is always true. [knownConditionTrueFalse]\n", errout_str()); // #9744 @@ -8089,13 +8089,13 @@ class TestOther : public TestFixture { " int b = a;\n" " a = 2;\n" " if ( b != a){}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}"); + check("void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}"); + check("void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\n"); ASSERT_EQUALS("", errout_str()); check("struct A { int f() const; };\n" @@ -8106,7 +8106,7 @@ class TestOther : public TestFixture { " x = g();\n" " if (x.f() == a) break;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(int i);\n" @@ -8119,14 +8119,14 @@ class TestOther : public TestFixture { " const bool x = a.f(A::B);\n" " const bool y = a.f(A::C);\n" " if(!x && !y) return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " const bool x = a.f(A::B);\n" " const bool y = a.f(A::C);\n" " if (!x && !y) return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool * const b);\n" @@ -8135,17 +8135,17 @@ class TestOther : public TestFixture { " bool y = true;\n" " f(&x);\n" " if (!x && !y) return;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " const int a = {};\n" " if(a == 1) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("volatile const int var = 42;\n" - "void f() { if(var == 42) {} }"); + "void f() { if(var == 42) {} }\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -8154,7 +8154,7 @@ class TestOther : public TestFixture { " c.a = &a;\n" " g(&c);\n" " if (a == 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -8164,7 +8164,7 @@ class TestOther : public TestFixture { " uint16_t x = 1000;\n" " uint8_t y = x;\n" " if (x != y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -8175,7 +8175,7 @@ class TestOther : public TestFixture { " const int b = a-1;\n" " const int c = a+1;\n" " return c;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -8196,7 +8196,7 @@ class TestOther : public TestFixture { " setZoom(m_zoom + 1);\n" " double scale_ratio = getScale() / old_scale;\n" // <- FP " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -8205,14 +8205,14 @@ class TestOther : public TestFixture { "{\n" " int var = buffer[index - 1];\n" " return buffer[index - 1] - var;\n" // << - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:25] -> [test.cpp:4:34]: (style) Same expression on both sides of '-' because 'buffer[index-1]' and 'var' represent the same value. [duplicateExpression]\n", errout_str()); } void duplicateExpression13() { //#7899 check("void f() {\n" " if (sizeof(long) == sizeof(long long)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -8345,7 +8345,7 @@ class TestOther : public TestFixture { void duplicateExpression20() { check("enum { N = 1 };\n" // #14202 - "int f() { return N - 1; }"); + "int f() { return N - 1; }\n"); ASSERT_EQUALS("", errout_str()); } @@ -8411,23 +8411,23 @@ class TestOther : public TestFixture { check("void f() {\n" " int a = 1;\n" " while ( a != 1){}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:3:15]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\n", errout_str()); - check("void f() { int a = 1; while ( a != 1){ a++; }}"); + check("void f() { int a = 1; while ( a != 1){ a++; }}\n"); ASSERT_EQUALS("", errout_str()); - check("void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}"); + check("void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }"); + check("void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " for(int i = 0; i < 10;) {\n" " if( i != 0 ) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:17] -> [test.cpp:3:15]: (style) The comparison 'i != 0' is always false. [knownConditionTrueFalse]\n", errout_str()); check("void f() {\n" @@ -8435,7 +8435,7 @@ class TestOther : public TestFixture { " if( i != 0 ) {}\n" " i++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -8443,14 +8443,14 @@ class TestOther : public TestFixture { " if( i != 0 ) { i++; }\n" " i++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " for(int i = 0; i < 10;) {\n" " if( i != 0 ) { i++; }\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -8459,7 +8459,7 @@ class TestOther : public TestFixture { " if( i != 0 ) {}\n" " i++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int b) {\n" @@ -8468,7 +8468,7 @@ class TestOther : public TestFixture { " if ( a != 1){}\n" " b++;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:17] -> [test.cpp:4:16]: (style) The comparison 'a != 1' is always false. [knownConditionTrueFalse]\n", errout_str()); check("struct T {\n" // #11083 @@ -8511,35 +8511,35 @@ class TestOther : public TestFixture { void duplicateExpressionTernary() { // #6391 check("void f() {\n" " return A ? x : x;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\n", errout_str()); check("int f(bool b, int a) {\n" " const int c = a;\n" " return b ? a : c;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:19] -> [test.cpp:3:18]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\n", errout_str()); check("void f() {\n" " return A ? x : z;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(unsigned char c) {\n" " x = y ? (signed char)c : (unsigned char)c;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("std::string stringMerge(std::string const& x, std::string const& y) {\n" // #7938 " return ((x > y) ? (y + x) : (x + y));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #6426 { const char code[] = "void foo(bool flag) {\n" " bar( (flag) ? ~0u : ~0ul);\n" - "}"; + "}\n"; /*const*/ Settings settings = settings1; settings.platform.sizeof_int = 4; settings.platform.int_bit = 32; @@ -8559,31 +8559,31 @@ class TestOther : public TestFixture { void duplicateValueTernary() { check("void f() {\n" " if( a ? (b ? false:false): false ) ;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:23]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\n", errout_str()); - check("int f1(int a) {return (a == 1) ? (int)1 : 1; }"); + check("int f1(int a) {return (a == 1) ? (int)1 : 1; }\n"); ASSERT_EQUALS("[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\n", errout_str()); - check("int f2(int a) {return (a == 1) ? (int)1 : (int)1; }"); + check("int f2(int a) {return (a == 1) ? (int)1 : (int)1; }\n"); ASSERT_EQUALS("[test.cpp:1:41]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\n", errout_str()); - check("int f3(int a) {return (a == 1) ? 1 : (int)1; }"); + check("int f3(int a) {return (a == 1) ? 1 : (int)1; }\n"); ASSERT_EQUALS("[test.cpp:1:36]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\n", errout_str()); - check("int f4(int a) {return (a == 1) ? 1 : 1; }"); + check("int f4(int a) {return (a == 1) ? 1 : 1; }\n"); ASSERT_EQUALS("[test.cpp:1:36]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\n", errout_str()); - check("int f5(int a) {return (a == (int)1) ? (int)1 : 1; }"); + check("int f5(int a) {return (a == (int)1) ? (int)1 : 1; }\n"); ASSERT_EQUALS("[test.cpp:1:46]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\n", errout_str()); - check("int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }"); + check("int f6(int a) {return (a == (int)1) ? (int)1 : (int)1; }\n"); ASSERT_EQUALS("[test.cpp:1:46]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\n", errout_str()); - check("int f7(int a) {return (a == (int)1) ? 1 : (int)1; }"); + check("int f7(int a) {return (a == (int)1) ? 1 : (int)1; }\n"); ASSERT_EQUALS("[test.cpp:1:41]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\n", errout_str()); - check("int f8(int a) {return (a == (int)1) ? 1 : 1; }"); + check("int f8(int a) {return (a == (int)1) ? 1 : 1; }\n"); ASSERT_EQUALS("[test.cpp:1:41]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\n", errout_str()); check("struct Foo {\n" @@ -8637,10 +8637,10 @@ class TestOther : public TestFixture { } void duplicateValueTernarySizeof() { // #13773 - check("int f() { return x ? sizeof(uint32_t) : sizeof(unsigned int); }"); + check("int f() { return x ? sizeof(uint32_t) : sizeof(unsigned int); }\n"); ASSERT_EQUALS("", errout_str()); - check("int f() { return x ? sizeof(uint32_t) : sizeof(uint32_t); }"); + check("int f() { return x ? sizeof(uint32_t) : sizeof(uint32_t); }\n"); ASSERT_EQUALS("[test.cpp:1:39]: (style) Same expression in both branches of ternary operator. [duplicateExpressionTernary]\n", errout_str()); } @@ -8649,7 +8649,7 @@ class TestOther : public TestFixture { " if (I >= 0 && I < 3) {}\n" "}\n" "\n" - "static auto a = f<0>();"); + "static auto a = f<0>();\n"); ASSERT_EQUALS("", errout_str()); check("template\n" // #7754 @@ -8735,35 +8735,35 @@ class TestOther : public TestFixture { } void oppositeExpression() { - check("void f(bool a) { if(a && !a) {} }"); + check("void f(bool a) { if(a && !a) {} }\n"); ASSERT_EQUALS("[test.cpp:1:23]: (style) Opposite expression on both sides of '&&'. [oppositeExpression]\n", errout_str()); - check("void f(bool a) { if(a != !a) {} }"); + check("void f(bool a) { if(a != !a) {} }\n"); ASSERT_EQUALS("[test.cpp:1:23]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\n", errout_str()); - check("void f(bool a) { if( a == !(a) ) {}}"); + check("void f(bool a) { if( a == !(a) ) {}}\n"); ASSERT_EQUALS("[test.cpp:1:24]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n", errout_str()); - check("void f(bool a) { if( a != !(a) ) {}}"); + check("void f(bool a) { if( a != !(a) ) {}}\n"); ASSERT_EQUALS("[test.cpp:1:24]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\n", errout_str()); - check("void f(bool a) { if( !(a) == a ) {}}"); + check("void f(bool a) { if( !(a) == a ) {}}\n"); ASSERT_EQUALS("[test.cpp:1:27]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n", errout_str()); - check("void f(bool a) { if( !(a) != a ) {}}"); + check("void f(bool a) { if( !(a) != a ) {}}\n"); ASSERT_EQUALS("[test.cpp:1:27]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\n", errout_str()); - check("void f(bool a) { if( !(!a) == !(a) ) {}}"); + check("void f(bool a) { if( !(!a) == !(a) ) {}}\n"); ASSERT_EQUALS("[test.cpp:1:28]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n", errout_str()); - check("void f(bool a) { if( !(!a) != !(a) ) {}}"); + check("void f(bool a) { if( !(!a) != !(a) ) {}}\n"); ASSERT_EQUALS("[test.cpp:1:28]: (style) Opposite expression on both sides of '!='. [oppositeExpression]\n", errout_str()); check("void f1(bool a) {\n" " const bool b = a;\n" " if( a == !(b) ) {}\n" " if( b == !(a) ) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20] -> [test.cpp:3:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n" "[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n", errout_str()); @@ -8771,26 +8771,26 @@ class TestOther : public TestFixture { " const bool b = *a;\n" " if( *a == !(b) ) {}\n" " if( b == !(*a) ) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:20] -> [test.cpp:3:12]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n" "[test.cpp:2:20] -> [test.cpp:4:11]: (style) Opposite expression on both sides of '=='. [oppositeExpression]\n", errout_str()); - check("void f(bool a) { a = !a; }"); + check("void f(bool a) { a = !a; }\n"); ASSERT_EQUALS("", errout_str()); - check("void f(int a) { if( a < -a ) {}}"); + check("void f(int a) { if( a < -a ) {}}\n"); ASSERT_EQUALS("[test.cpp:1:23]: (style) Opposite expression on both sides of '<'. [oppositeExpression]\n", errout_str()); - check("void f(int a) { a -= -a; }"); + check("void f(int a) { a -= -a; }\n"); ASSERT_EQUALS("", errout_str()); - check("void f(int a) { a = a / (-a); }"); + check("void f(int a) { a = a / (-a); }\n"); ASSERT_EQUALS("", errout_str()); - check("bool f(int i){ return !((i - 1) & i); }"); + check("bool f(int i){ return !((i - 1) & i); }\n"); ASSERT_EQUALS("", errout_str()); - check("bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }"); + check("bool f(unsigned i){ return (x > 0) && (x & (x-1)) == 0; }\n"); ASSERT_EQUALS("", errout_str()); check("void A::f(bool a, bool c)\n" @@ -8798,27 +8798,27 @@ class TestOther : public TestFixture { " const bool b = a;\n" " if(c) { a = false; }\n" " if(b && !a) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(bool c) {\n" " const bool b = a;\n" " if(c) { a = false; }\n" " if(b && !a) { }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " bool x = a;\n" " dostuff();\n" " if (x && a) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " const bool b = g();\n" " if (!b && g()) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(const bool *a) {\n" @@ -8861,7 +8861,7 @@ class TestOther : public TestFixture { "void test() {\n" " int i = f();\n" " int j = f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct Foo { int f() const; int g() const; };\n" @@ -8869,7 +8869,7 @@ class TestOther : public TestFixture { " Foo f = Foo{};\n" " int i = f.f();\n" " int j = f.f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct Foo { int f() const; int g() const; };\n" @@ -8878,7 +8878,7 @@ class TestOther : public TestFixture { " Foo f2 = Foo{};\n" " int i = f.f();\n" " int j = f.f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:9] -> [test.cpp:5:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("int f() __attribute__((pure));\n" @@ -8886,7 +8886,7 @@ class TestOther : public TestFixture { "void test() {\n" " int i = 1 + f();\n" " int j = 1 + f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("int f() __attribute__((pure));\n" @@ -8894,7 +8894,7 @@ class TestOther : public TestFixture { "void test() {\n" " int i = f() + 1;\n" " int j = 1 + f();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f() __attribute__((pure));\n" @@ -8903,7 +8903,7 @@ class TestOther : public TestFixture { " int x = f();\n" " int i = x + 1;\n" " int j = f() + 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f() __attribute__((pure));\n" @@ -8911,7 +8911,7 @@ class TestOther : public TestFixture { "void test() {\n" " int i = f() + f();\n" " int j = f() + f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("int f(int) __attribute__((pure));\n" @@ -8919,7 +8919,7 @@ class TestOther : public TestFixture { "void test() {\n" " int i = f(0);\n" " int j = f(0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("int f(int) __attribute__((pure));\n" @@ -8928,39 +8928,39 @@ class TestOther : public TestFixture { " const int x = 0;\n" " int i = f(0);\n" " int j = f(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void test(const int * p, const int * q) {\n" " int i = *p;\n" " int j = *p;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct A { int x; int y; };" "void test(A a) {\n" " int i = a.x;\n" " int j = a.x;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:2:9]: (style) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("void test() {\n" " int i = 0;\n" " int j = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void test() {\n" " int i = -1;\n" " int j = -1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(int);\n" "void test() {\n" " int i = f(0);\n" " int j = f(1);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f();\n" @@ -8968,21 +8968,21 @@ class TestOther : public TestFixture { "void test() {\n" " int i = f() || f();\n" " int j = f() && f();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct Foo {};\n" "void test() {\n" " Foo i = Foo();\n" " Foo j = Foo();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct Foo {};\n" "void test() {\n" " Foo i = Foo{};\n" " Foo j = Foo{};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct Foo { int f() const; float g() const; };\n" @@ -8990,7 +8990,7 @@ class TestOther : public TestFixture { " Foo f = Foo{};\n" " int i = f.f();\n" " int j = f.f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct Foo { int f(); int g(); };\n" @@ -8998,43 +8998,43 @@ class TestOther : public TestFixture { " Foo f = Foo{};\n" " int i = f.f();\n" " int j = f.f();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void test() {\n" " int i = f();\n" " int j = f();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void test(int x) {\n" " int i = ++x;\n" " int j = ++x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void test(int x) {\n" " int i = x++;\n" " int j = x++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void test(int x) {\n" " int i = --x;\n" " int j = --x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void test(int x) {\n" " int i = x--;\n" " int j = x--;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void test(int x) {\n" " int i = x + 1;\n" " int j = 1 + x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -9043,7 +9043,7 @@ class TestOther : public TestFixture { "void foo(SW* x) {\n" " int start = x->first;\n" " int end = x->first;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\n" "[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n", errout_str()); @@ -9052,7 +9052,7 @@ class TestOther : public TestFixture { "void foo(SW* x, int i, int j) {\n" " int start = x->first;\n" " int end = x->first;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'start' and 'end'. [duplicateAssignExpression]\n" "[test.cpp:2:14]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n", errout_str()); @@ -9062,13 +9062,13 @@ class TestOther : public TestFixture { " Foo f = Foo{};\n" " int i = f.f();\n" " int j = f.f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("void test(const int * p) {\n" " int i = *p;\n" " int j = *p;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9] -> [test.cpp:2:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct Foo { int f() const; int g(int) const; };\n" @@ -9076,7 +9076,7 @@ class TestOther : public TestFixture { " Foo f = Foo{};\n" " int i = f.f();\n" " int j = f.f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct Foo { int f() const; };\n" @@ -9084,7 +9084,7 @@ class TestOther : public TestFixture { " Foo f = Foo{};\n" " int i = f.f();\n" " int j = f.f();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:9] -> [test.cpp:4:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); } @@ -9096,7 +9096,7 @@ class TestOther : public TestFixture { " int j = a.x;\n" " use(i);\n" " i = j;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct A { int x; int y; };" @@ -9106,7 +9106,7 @@ class TestOther : public TestFixture { " int j = a.x;\n" " use(j);\n" " j = i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); check("struct A { int x; int y; };" @@ -9116,7 +9116,7 @@ class TestOther : public TestFixture { " int j = a.x;\n" " use(j);\n" " if (i == j) {}\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); @@ -9128,7 +9128,7 @@ class TestOther : public TestFixture { " int j = a.x;\n" " use(j);\n" " if (i == a.x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); @@ -9140,7 +9140,7 @@ class TestOther : public TestFixture { " int j = a.x;\n" " use(i);\n" " if (j == a.x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:4:9] -> [test.cpp:3:9]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'. [duplicateAssignExpression]\n", errout_str()); @@ -9171,7 +9171,7 @@ class TestOther : public TestFixture { " }\n" " previous = current;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:16:7] -> [test.cpp:15:7]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'. [duplicateAssignExpression]\n", errout_str()); } @@ -9187,21 +9187,21 @@ class TestOther : public TestFixture { " int b = x.f();\n" " (void)a;\n" " (void)b;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:13] -> [test.cpp:7:13]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'. [duplicateAssignExpression]\n", errout_str()); // Issue #8712 check("void f() {\n" " unsigned char d;\n" " d = d % 5;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("template \n" "T f() {\n" " T x = T();\n" "}\n" - "int &a = f();"); + "int &a = f();\n"); ASSERT_EQUALS("", errout_str()); // Issue #8713 @@ -9213,7 +9213,7 @@ class TestOther : public TestFixture { " uint32_t a = 42;\n" " uint32_t b = uint32_t(A ::B / 1024);\n" " int32_t c = int32_t(a / b);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Issue #8709 @@ -9222,7 +9222,7 @@ class TestOther : public TestFixture { " switch (d) { case b:; }\n" " double e(b);\n" " if(e <= 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #10718 @@ -9243,7 +9243,7 @@ class TestOther : public TestFixture { " int val = 0;\n" " if (val < 0) continue;\n" " if ((val > 0)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\n" "[test.cpp:2:13] -> [test.cpp:4:12]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\n", errout_str()); @@ -9274,7 +9274,7 @@ class TestOther : public TestFixture { " if (val < 0) {\n" " if ((val > 0)) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\n" "[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val > 0' is always false. [knownConditionTrueFalse]\n", errout_str()); @@ -9283,7 +9283,7 @@ class TestOther : public TestFixture { " if (val < 0) {\n" " if ((val < 0)) {}\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13] -> [test.cpp:3:11]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\n" "[test.cpp:2:13] -> [test.cpp:4:14]: (style) The comparison 'val < 0' is always false. [knownConditionTrueFalse]\n", errout_str()); @@ -9292,25 +9292,25 @@ class TestOther : public TestFixture { " int foo = 0;\n" " if (activate) {}\n" " else if (foo) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void checkSignOfUnsignedVariable() { check("void foo() {\n" " for(unsigned char i = 10; i >= 0; i--) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:31]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(bool b) {\n" " for(unsigned int i = 10; b || i >= 0; i--) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:35]: (style) Unsigned expression 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); { const char code[] = "void foo(unsigned int x) {\n" " if (x < 0) {}\n" - "}"; + "}\n"; check(code, dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check(code, dinit(CheckOptions, $.inconclusive = false, $.verbose = true)); @@ -9319,19 +9319,19 @@ class TestOther : public TestFixture { check("void foo(unsigned int x) {\n" " if (x < 0u) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x) {\n" " if (x < 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); { const char code[] = "void foo(unsigned x) {\n" " int y = 0;\n" " if (x < y) {}\n" - "}"; + "}\n"; check(code, dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check(code, dinit(CheckOptions, $.inconclusive = false, $.verbose = true)); @@ -9342,149 +9342,149 @@ class TestOther : public TestFixture { " if (b)\n" " y = 1;\n" " if (x < y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(unsigned int x) {\n" " if (0 > x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(unsigned int x) {\n" " if (0UL > x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x) {\n" " if (0 > x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(unsigned int x) {\n" " if (x >= 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(unsigned int x, unsigned y) {\n" " if (x - y >= 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Unsigned expression 'x-y' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(unsigned int x) {\n" " if (x >= 0ull) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(int x) {\n" " if (x >= 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(unsigned int x) {\n" " if (0 <= x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(unsigned int x) {\n" " if (0ll <= x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(int x) {\n" " if (0 <= x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(unsigned int x, bool y) {\n" " if (x < 0 && y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (x < 0 && y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(unsigned int x, bool y) {\n" " if (0 > x && y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (0 > x && y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(unsigned int x, bool y) {\n" " if (x >= 0 && y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (x >= 0 && y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(unsigned int x, bool y) {\n" " if (y && x < 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (y && x < 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(unsigned int x, bool y) {\n" " if (y && 0 > x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (y && 0 > x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(unsigned int x, bool y) {\n" " if (y && x >= 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:14]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (y && x >= 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(unsigned int x, bool y) {\n" " if (x < 0 || y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (x < 0 || y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(unsigned int x, bool y) {\n" " if (0 > x || y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (0 > x || y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(unsigned int x, bool y) {\n" " if (x >= 0 || y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\n", errout_str()); check("void foo(int x, bool y) {\n" " if (x >= 0 || y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #3233 - FP when template is used (template parameter is numeric constant) @@ -9492,7 +9492,7 @@ class TestOther : public TestFixture { const char code[] = "template void foo(unsigned int x) {\n" " if (x <= n);\n" "}\n" - "foo<0>();"; + "foo<0>();\n"; check(code, dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check(code); @@ -9502,7 +9502,7 @@ class TestOther : public TestFixture { { check("template void foo(unsigned int x) {\n" "if (x <= 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:7]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); } @@ -9513,7 +9513,7 @@ class TestOther : public TestFixture { " {\n" " value = 0u;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\n", errout_str()); // #9040 @@ -9530,7 +9530,7 @@ class TestOther : public TestFixture { " const uint32_t x = 0;\n" " constexpr const auto y = 0xFFFFU;\n" " if (y < x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: (style) Checking if unsigned expression 'y' is less than zero. [unsignedLessThanZero]\n", errout_str()); // #12387 @@ -9542,14 +9542,14 @@ class TestOther : public TestFixture { "}\n" "void g() {\n" " f(0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #13734 check("void f() {\n" " uint8_t a[N + 1];\n" " for (unsigned p = 0; p < (sizeof(a) / sizeof((a)[0])); ++p) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(const unsigned char u) {\n" @@ -9561,7 +9561,7 @@ class TestOther : public TestFixture { " if (0 > u) {}\n" " if (0 <= u) {}\n" " if (0 >= u) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11]: (style) Checking if unsigned expression 'u' is less than zero. [unsignedLessThanZero]\n" "[test.cpp:4:11]: (style) Unsigned expression 'u' can't be negative so it is unnecessary to test it. [unsignedPositive]\n" "[test.cpp:5:11]: (style) Checking if unsigned expression 'u' is less than zero. [unsignedLessThanZero]\n" @@ -9574,14 +9574,14 @@ class TestOther : public TestFixture { void checkSignOfPointer() { check("void foo(const int* x) {\n" " if (x >= 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\n", errout_str()); { const char code[] = "void foo(const int* x) {\n" " int y = 0;\n" " if (x >= y) {}\n" - "}"; + "}\n"; check(code, dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\n", errout_str()); check(code, dinit(CheckOptions, $.inconclusive = false, $.verbose = true)); @@ -9589,19 +9589,19 @@ class TestOther : public TestFixture { } check("void foo(const int* x) {\n" " if (*x >= 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(const int* x) {\n" " if (x < 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\n", errout_str()); { const char code[] = "void foo(const int* x) {\n" " unsigned y = 0u;\n" " if (x < y) {}\n" - "}"; + "}\n"; check(code, dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\n", errout_str()); @@ -9611,32 +9611,32 @@ class TestOther : public TestFixture { check("void foo(const int* x) {\n" " if (*x < 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(const int* x, const int* y) {\n" " if (x - y < 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(const int* x, const int* y) {\n" " if (x - y <= 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(const int* x, const int* y) {\n" " if (x - y > 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(const int* x, const int* y) {\n" " if (x - y >= 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(const Bar* x) {\n" " if (0 <= x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\n", errout_str()); check("struct S {\n" @@ -9644,7 +9644,7 @@ class TestOther : public TestFixture { "};\n" "void foo(S* first) {\n" " if (first.ptr >= 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\n" "[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n", errout_str()); @@ -9654,7 +9654,7 @@ class TestOther : public TestFixture { "};\n" "void foo(S* first, S* second) {\n" " if((first.ptr - second.ptr) >= 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\n", errout_str()); @@ -9664,7 +9664,7 @@ class TestOther : public TestFixture { "};\n" "void foo(S* first) {\n" " if((first.ptr) >= 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:18]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\n" "[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n", errout_str()); @@ -9674,7 +9674,7 @@ class TestOther : public TestFixture { "};\n" "void foo(S* first, S* second) {\n" " if(0 <= first.ptr - second.ptr) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\n", errout_str()); @@ -9684,7 +9684,7 @@ class TestOther : public TestFixture { "};\n" "void foo(S* first, S* second) {\n" " if(0 <= (first.ptr - second.ptr)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\n", errout_str()); @@ -9694,7 +9694,7 @@ class TestOther : public TestFixture { "};\n" "void foo(S* first, S* second) {\n" " if(first.ptr - second.ptr < 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\n", errout_str()); @@ -9704,7 +9704,7 @@ class TestOther : public TestFixture { "};\n" "void foo(S* first, S* second) {\n" " if((first.ptr - second.ptr) < 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\n", errout_str()); @@ -9714,7 +9714,7 @@ class TestOther : public TestFixture { "};\n" "void foo(S* first, S* second) {\n" " if(0 > first.ptr - second.ptr) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\n", errout_str()); @@ -9724,69 +9724,69 @@ class TestOther : public TestFixture { "};\n" "void foo(S* first, S* second) {\n" " if(0 > (first.ptr - second.ptr)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:13]: (style) Parameter 'first' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:4:23]: (style) Parameter 'second' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(const int* x) {\n" " if (0 <= x[0]) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(Bar* x) {\n" " if (0 <= x.y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(Bar* x) {\n" " if (0 <= x->y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(Bar* x, Bar* y) {\n" " if (0 <= x->y - y->y ) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:1:23]: (style) Parameter 'y' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(const Bar* x) {\n" " if (0 > x) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\n", errout_str()); check("void foo(const int* x) {\n" " if (0 > x[0]) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(Bar* x) {\n" " if (0 > x.y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo(Bar* x) {\n" " if (0 > x->y) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:15]: (style) Parameter 'x' can be declared as pointer to const [constParameterPointer]\n", errout_str()); check("void foo() {\n" " int (*t)(void *a, void *b);\n" " if (t(a, b) < 0) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " int (*t)(void *a, void *b);\n" " if (0 > t(a, b)) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct object_info { int *typep; };\n" "void packed_object_info(struct object_info *oi) {\n" " if (oi->typep < 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\n" "[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\n", errout_str()); @@ -9794,7 +9794,7 @@ class TestOther : public TestFixture { check("struct object_info { int typep[10]; };\n" "void packed_object_info(struct object_info *oi) {\n" " if (oi->typep < 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:17]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\n" "[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\n", errout_str()); @@ -9802,28 +9802,28 @@ class TestOther : public TestFixture { check("struct object_info { int *typep; };\n" "void packed_object_info(struct object_info *oi) {\n" " if (*oi->typep < 0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:45]: (style) Parameter 'oi' can be declared as pointer to const [constParameterPointer]\n", errout_str()); } void checkSuspiciousSemicolon1() { check("void foo() {\n" " for(int i = 0; i < 10; ++i);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Empty block check("void foo() {\n" " for(int i = 0; i < 10; ++i); {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'for' statement. [suspiciousSemicolon]\n", errout_str()); check("void foo() {\n" " while (!quit); {\n" " do_something();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'while' statement. [suspiciousSemicolon]\n", errout_str()); } @@ -9832,21 +9832,21 @@ class TestOther : public TestFixture { " if (i == 1); {\n" " do_something();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:3]: (warning) Suspicious use of ; at the end of 'if' statement. [suspiciousSemicolon]\n", errout_str()); // Seen this in the wild check("void foo() {\n" " if (Match());\n" " do_something();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " if (Match());\n" " else\n" " do_something();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -9855,7 +9855,7 @@ class TestOther : public TestFixture { " {\n" " do_something();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -9864,7 +9864,7 @@ class TestOther : public TestFixture { " {\n" " do_something();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -9873,20 +9873,20 @@ class TestOther : public TestFixture { "void foo() {\n" " if (x == 123);\n" " REQUIRE(y=z);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void checkSuspiciousComparison() { checkP("void f(int a, int b) {\n" " a > b;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (warning, inconclusive) Found suspicious operator '>', result is not used. [constStatement]\n", errout_str()); checkP("void f() {\n" // #10607 " for (auto p : m)\n" " std::vector> k;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -9894,25 +9894,25 @@ class TestOther : public TestFixture { check("void foo(char *p) {\n" " char *a; a = malloc(1024);\n" " free(a + 10);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\n", errout_str()); check("void foo(char *p) {\n" " char *a; a = malloc(1024);\n" " free(a - 10);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\n", errout_str()); check("void foo(char *p) {\n" " char *a; a = malloc(1024);\n" " free(10 + a);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\n", errout_str()); check("void foo(char *p) {\n" " char *a; a = new char[1024];\n" " delete[] (a + 10);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\n", errout_str()); @@ -9920,7 +9920,7 @@ class TestOther : public TestFixture { check("void foo(char *p) {\n" " char *a; a = new char;\n" " delete a + 10;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:3:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\n", errout_str()); @@ -9929,7 +9929,7 @@ class TestOther : public TestFixture { " char *a; a = new char;\n" " bar(a);\n" " delete a + 10;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char *p) {\n" @@ -9938,7 +9938,7 @@ class TestOther : public TestFixture { " bar(a);\n" " delete a + 10;\n" " delete b + 10;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\n", errout_str()); check("void foo(char *p) {\n" @@ -9947,14 +9947,14 @@ class TestOther : public TestFixture { " bar(a, b);\n" " delete a + 10;\n" " delete b + 10;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(char *p) {\n" " char *a; a = new char;\n" " bar()\n" " delete a + 10;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:16]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:4:3]: (error) Mismatching address is deleted. The address you get from new must be deleted without offset. [invalidFree]\n", errout_str()); @@ -9963,7 +9963,7 @@ class TestOther : public TestFixture { " char *ptr; ptr = malloc(42);\n" " ptr += xx;\n" " free(ptr + 1 - xx);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:3]: (error) Mismatching address is freed. The address you get from malloc() must be freed without offset. [invalidFree]\n", errout_str()); check("void foo(size_t xx) {\n" @@ -9971,7 +9971,7 @@ class TestOther : public TestFixture { " std::cout << ptr;\n" " ptr = otherPtr;\n" " free(otherPtr - xx - 1);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:9]: (style) Variable 'ptr' can be declared as pointer to const [constVariablePointer]\n", errout_str()); @@ -9981,7 +9981,7 @@ class TestOther : public TestFixture { check("const std::string& getA(){static std::string a;return a;}\n" "void foo() {\n" " const std::string a = getA();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:23]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\n", errout_str()); check("class A { public: A() {} char x[100]; };\n" @@ -9990,7 +9990,7 @@ class TestOther : public TestFixture { "{\n" " const A a = getA();\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\n", errout_str()); check("const int& getA(){static int a;return a;}\n" @@ -9998,7 +9998,7 @@ class TestOther : public TestFixture { "{\n" " const int a = getA();\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("const int& getA(){static int a;return a;}\n" @@ -10007,7 +10007,7 @@ class TestOther : public TestFixture { " int getA = 0;\n" " const int a = getA + 3;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:1:12] -> [test.cpp:4:9]: (style) Local variable 'getA' shadows outer function [shadowFunction]\n", errout_str()); check("class A { public: A() {} char x[100]; };\n" @@ -10016,7 +10016,7 @@ class TestOther : public TestFixture { "{\n" " const A a(getA());\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:13]: (performance, inconclusive) Use const reference for 'a' to avoid unnecessary data copying. [redundantCopyLocalConst]\n", errout_str()); check("const int& getA(){static int a;return a;}\n" @@ -10024,7 +10024,7 @@ class TestOther : public TestFixture { "{\n" " const int a(getA());\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class A{\n" @@ -10036,7 +10036,7 @@ class TestOther : public TestFixture { "{\n" " const A a = getA() + 1;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class A{\n" @@ -10048,7 +10048,7 @@ class TestOther : public TestFixture { "{\n" " const A a(getA()+1);\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #5190 - FP when creating object with constructor that takes a reference @@ -10057,7 +10057,7 @@ class TestOther : public TestFixture { "const A &getA();\n" "void f() {\n" " const B b(getA());\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class A {};\n" @@ -10065,7 +10065,7 @@ class TestOther : public TestFixture { "const A& getA();\n" "void f() {\n" " const B b{ getA() };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #5618 @@ -10078,7 +10078,7 @@ class TestOther : public TestFixture { " const std::string temp = tok->str();\n" " tok->str(tok->strAt(2));\n" " }\n" - "}"; + "}\n"; check(code5618); ASSERT_EQUALS("", errout_str()); check(code5618, dinit(CheckOptions, $.inconclusive = false)); @@ -10089,7 +10089,7 @@ class TestOther : public TestFixture { "X f(const X &in) {\n" " const X s = f(in);\n" " return f(s);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #7981 - False positive redundantCopyLocalConst - const ref argument to ctor @@ -10101,7 +10101,7 @@ class TestOther : public TestFixture { " \n" "void foo() {\n" " const CD cd(CD::getOne());\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" // #10545 @@ -10114,7 +10114,7 @@ class TestOther : public TestFixture { " if (i != 0)\n" " return old;\n" " return {};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct X { int x; };\n" // #10191 @@ -10296,62 +10296,62 @@ class TestOther : public TestFixture { "{\n" " int a; a = 123;\n" " (void)(a << -1);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\n", errout_str()); check("void foo()\n" "{\n" " int a; a = 123;\n" " (void)(a >> -1);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:13]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\n", errout_str()); check("void foo()\n" "{\n" " int a; a = 123;\n" " a <<= -1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\n", errout_str()); check("void foo()\n" "{\n" " int a; a = 123;\n" " a >>= -1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:6]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\n", errout_str()); check("void foo()\n" "{\n" " std::cout << -1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" " std::cout << a << -1 ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" " std::cout << 3 << -1 ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " x = (-10+2) << 3;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\n", errout_str()); - check("x = y ? z << $-1 : 0;"); + check("x = y ? z << $-1 : 0;\n"); ASSERT_EQUALS("", errout_str()); // Negative LHS - check("const int x = -1 >> 2;"); + check("const int x = -1 >> 2;\n"); ASSERT_EQUALS("[test.cpp:1:18]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\n", errout_str()); // #6383 - unsigned type - check("const int x = (unsigned int)(-1) >> 2;"); + check("const int x = (unsigned int)(-1) >> 2;\n"); ASSERT_EQUALS("", errout_str()); // #7814 - UB happening in valueflowcode when it tried to compute shifts. check("int shift1() { return 1 >> -1 ;}\n" "int shift2() { return 1 << -1 ;}\n" "int shift3() { return -1 >> 1 ;}\n" - "int shift4() { return -1 << 1 ;}"); + "int shift4() { return -1 << 1 ;}\n"); ASSERT_EQUALS("[test.cpp:1:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\n" "[test.cpp:2:25]: (error) Shifting by a negative value is undefined behaviour [shiftNegative]\n" "[test.cpp:3:26]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\n" @@ -10400,7 +10400,7 @@ class TestOther : public TestFixture { " memset(a, 123, 5);\n" " memcpy(a, b, 5);\n" " memmove(a, b, 5);\n" - "}"); + "}\n"); ASSERT_EQUALS(// TODO "[test.cpp:4] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\n" "[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\n" "[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*a)'? [incompleteArrayFill]\n" @@ -10411,7 +10411,7 @@ class TestOther : public TestFixture { "void f() {\n" " memset(::a, 123, 5);\n" " memset(Z::b.a, 123, 5);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\n" "[test.cpp:5]: (warning, inconclusive) Array 'Z::b.a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*Z::b.a)'?\n", "[test.cpp:4:5]: (warning, inconclusive) Array '::a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*::a)'? [incompleteArrayFill]\n", errout_str()); @@ -10419,45 +10419,45 @@ class TestOther : public TestFixture { check("void f() {\n" " Foo* a[5];\n" " memset(a, 'a', 5);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\n", errout_str()); check("class Foo {int a; int b;};\n" "void f() {\n" " Foo a[5];\n" " memset(a, 'a', 5);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\n", errout_str()); check("void f() {\n" " Foo a[5];\n" // Size of foo is unknown " memset(a, 'a', 5);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " char a[5];\n" " memset(a, 'a', 5);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int a[5];\n" " memset(a+15, 'a', 5);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " bool a[5];\n" " memset(a, false, 5);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\n", errout_str()); check("void f() {\n" " const int n = 5;" " int a[n];\n" " memset(a, 0, n);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning, inconclusive) Array 'a' is filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'? [incompleteArrayFill]\n", errout_str()); } @@ -10468,7 +10468,7 @@ class TestOther : public TestFixture { check("void f(int i) {\n" " i = 1;\n" " i = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:2:7]: note: i is assigned\n" "[test.cpp:3:7]: note: i is overwritten\n", errout_str()); @@ -10478,7 +10478,7 @@ class TestOther : public TestFixture { "void f() {\n" " i = 1;\n" " i = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:3:7]: note: i is assigned\n" "[test.cpp:4:7]: note: i is overwritten\n", errout_str()); @@ -10487,7 +10487,7 @@ class TestOther : public TestFixture { " int i;\n" " i = 1;\n" " i = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:3:7]: note: i is assigned\n" "[test.cpp:4:7]: note: i is overwritten\n", errout_str()); @@ -10496,14 +10496,14 @@ class TestOther : public TestFixture { " static int i;\n" " i = 1;\n" " i = 1;\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("error", "", errout_str()); check("void f() {\n" " int i[10];\n" " i[2] = 1;\n" " i[2] = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: style: Variable 'i[2]' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:3:10]: note: i[2] is assigned\n" "[test.cpp:4:10]: note: i[2] is overwritten\n", errout_str()); @@ -10513,14 +10513,14 @@ class TestOther : public TestFixture { " i[x] = 1;\n" " x=1;\n" " i[x] = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(const int x) {\n" " int i[10];\n" " i[x] = 1;\n" " i[x] = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: style: Variable 'i[x]' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:3:10]: note: i[x] is assigned\n" "[test.cpp:4:10]: note: i[x] is overwritten\n", errout_str()); @@ -10529,14 +10529,14 @@ class TestOther : public TestFixture { check("void f() {\n" " Foo& bar = foo();\n" " bar = x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " Foo& bar = foo();\n" " bar = x;\n" " bar = y;\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("error", "", errout_str()); check("void f() {\n" @@ -10544,7 +10544,7 @@ class TestOther : public TestFixture { " bar = y();\n" " foo();\n" " bar = y();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Tests with function call between assignment @@ -10552,7 +10552,7 @@ class TestOther : public TestFixture { " i = 1;\n" " bar();\n" " i = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:2:7]: note: i is assigned\n" "[test.cpp:4:7]: note: i is overwritten\n", errout_str()); @@ -10562,7 +10562,7 @@ class TestOther : public TestFixture { " i = 1;\n" " bar();\n" // Global variable might be accessed in bar() " i = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -10570,7 +10570,7 @@ class TestOther : public TestFixture { " i = 1;\n" " bar();\n" // bar() might call f() recursively. This could be a false positive in more complex examples (when value of i is used somewhere. See #4229) " i = 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -10578,7 +10578,7 @@ class TestOther : public TestFixture { " i = 1;\n" " bar();\n" " i = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:3:7]: note: i is assigned\n" "[test.cpp:5:7]: note: i is overwritten\n", errout_str()); @@ -10588,14 +10588,14 @@ class TestOther : public TestFixture { " i = 1;\n" " bar(i);\n" // Passed as argument " i = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " Foo bar = foo();\n" " bar();\n" // #5568. operator() called " bar = y();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Branch tests @@ -10603,7 +10603,7 @@ class TestOther : public TestFixture { " i = 1;\n" " if(x)\n" " i = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int i) {\n" @@ -10611,7 +10611,7 @@ class TestOther : public TestFixture { " i = 0;\n" " i = 1;\n" " i = 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:7]: style: Variable 'i' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:4:7]: note: i is assigned\n" "[test.cpp:5:7]: note: i is overwritten\n", errout_str()); @@ -10624,7 +10624,7 @@ class TestOther : public TestFixture { "void f() {\n" " x = 2;\n" " x = g();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int g() {\n" @@ -10633,7 +10633,7 @@ class TestOther : public TestFixture { "void f(int x) {\n" " x = 2;\n" " x = g();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:5:7]: note: x is assigned\n" "[test.cpp:6:7]: note: x is overwritten\n", errout_str()); @@ -10642,7 +10642,7 @@ class TestOther : public TestFixture { " Foo& bar = foo();\n" " bar = x;\n" " bar = y();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class C {\n" @@ -10654,7 +10654,7 @@ class TestOther : public TestFixture { "void C::f() {\n" " x = 2;\n" " x = g();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class C {\n" @@ -10666,7 +10666,7 @@ class TestOther : public TestFixture { "void C::f(Foo z) {\n" " x = 2;\n" " x = z.g();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // ({ }) @@ -10674,7 +10674,7 @@ class TestOther : public TestFixture { " int x;\n" " x = 321;\n" " x = ({ asm(123); })\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // from #3103 (avoid a false negative) @@ -10683,7 +10683,7 @@ class TestOther : public TestFixture { " x = 1;\n" " x = 1;\n" " return x + 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7]: style: Variable 'x' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:3:7]: note: x is assigned\n" "[test.cpp:4:7]: note: x is overwritten\n", errout_str()); @@ -10695,20 +10695,20 @@ class TestOther : public TestFixture { " if (y)\n" // <-- cppcheck does not know anything about 'y' " x = 2;\n" " return x + 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // initialization, assignment with 0 check("void f() {\n" // Ticket #4356 " int x = 0;\n" // <- ignore initialization with 0 " x = 3;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " state_t *x = NULL;\n" " x = dostuff();\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\n", errout_str()); @@ -10717,7 +10717,7 @@ class TestOther : public TestFixture { " state_t *x;\n" " x = NULL;\n" " x = dostuff();\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:12]: style: Variable 'x' can be declared as pointer to const [constVariablePointer]\n", errout_str()); @@ -10727,7 +10727,7 @@ class TestOther : public TestFixture { " bar(++x);\n" " x = 5;\n" " return bar(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // struct member.. @@ -10738,7 +10738,7 @@ class TestOther : public TestFixture { " ab.a = 1;\n" " ab.a = 2;\n" " return ab.a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:10]: style: Variable 'ab.a' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:5:10]: note: ab.a is assigned\n" "[test.cpp:6:10]: note: ab.a is overwritten\n", errout_str()); @@ -10750,7 +10750,7 @@ class TestOther : public TestFixture { " ab.a = 1;\n" " ab = do_something();\n" " return ab.a;\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("error", "", errout_str()); check("struct AB { int a; int b; };\n" @@ -10761,7 +10761,7 @@ class TestOther : public TestFixture { " do_something(&ab);\n" " ab.a = 2;\n" " return ab.a;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct AB { int a; int b; };\n" @@ -10772,7 +10772,7 @@ class TestOther : public TestFixture { " do_something(&ab);\n" " ab.a = 2;\n" " return ab.a;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct AB { int a; int b; };\n" @@ -10783,7 +10783,7 @@ class TestOther : public TestFixture { " ab++;\n" " ab->a = 1;\n" " ab->b = 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct AB { int a; int b; };\n" @@ -10794,20 +10794,20 @@ class TestOther : public TestFixture { " ab = x;\n" " ab->a = 1;\n" " ab->b = 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(struct AB *ab) {\n" // # " ab->data->x = 1;\n" " ab = &ab1;\n" " ab->data->x = 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #5964 check("void func(char *buffer, const char *format, int precision, unsigned value) {\n" " (precision < 0) ? sprintf(buffer, format, value) : sprintf(buffer, format, precision, value);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // don't crash @@ -10820,14 +10820,14 @@ class TestOther : public TestFixture { "void func(struct state *s) {\n" " s->foo[s->x++] = 2;\n" " s->d[1].fc.i++;\n" - "}"); + "}\n"); // #6525 - inline assembly check("void f(int i) {\n" " i = 1;\n" " asm(\"foo\");\n" " i = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #6555 @@ -10840,7 +10840,7 @@ class TestOther : public TestFixture { " catch (...) {\n" " barney(p);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" @@ -10852,7 +10852,7 @@ class TestOther : public TestFixture { " catch (...) {\n" " barney(x);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: style: The scope of the variable 'p' can be reduced. [variableScope]\n" "[test.cpp:2:11]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\n", errout_str()); @@ -10868,7 +10868,7 @@ class TestOther : public TestFixture { " catch (...) {\n" " barney(p);\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Member variable pointers @@ -10878,7 +10878,7 @@ class TestOther : public TestFixture { " memptr = &POD::b;\n" " if (memptr)\n" " memptr = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:12]: style: Variable 'memptr' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:3:12]: note: memptr is assigned\n" "[test.cpp:4:12]: note: memptr is overwritten\n", errout_str()); @@ -10888,7 +10888,7 @@ class TestOther : public TestFixture { "{\n" " var[0] = 0.2f;\n" " var[0] = 0.2f;\n" // <-- is initialized twice - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: style: Variable 'var[0]' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:3:10]: note: var[0] is assigned\n" "[test.cpp:4:10]: note: var[0] is overwritten\n", errout_str()); @@ -10897,7 +10897,7 @@ class TestOther : public TestFixture { "{\n" " *var = 0.2f;\n" " *var = 0.2f;\n" // <-- is initialized twice - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:8]: style: Variable '*var' is reassigned a value before the old one has been used. [redundantAssignment]\n" "[test.cpp:3:8]: note: *var is assigned\n" "[test.cpp:4:8]: note: *var is overwritten\n", errout_str()); @@ -10907,7 +10907,7 @@ class TestOther : public TestFixture { " volatile char *reg = (volatile char *)0x12345;\n" " *reg = 12;\n" " *reg = 34;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(std::map& m, int key, int value) {\n" // #6379 @@ -10924,28 +10924,28 @@ class TestOther : public TestFixture { check("void f() {\n" " int a = 0;\n" " a = 4;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int a;\n" " a = 0;\n" " a = 4;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " unsigned a;\n" " a = 0u;\n" " a = 2u;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " void* a;\n" " a = (void*)0;\n" " a = p;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\n", errout_str()); @@ -10954,7 +10954,7 @@ class TestOther : public TestFixture { " void* a;\n" " a = (void*)0U;\n" " a = p;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:10]: (style) Variable 'a' can be declared as pointer to const [constVariablePointer]\n", errout_str()); @@ -10968,7 +10968,7 @@ class TestOther : public TestFixture { " const char* p = \"abc\";\n" " p = \"def\";\n" " return p;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:19] -> [test.cpp:3:7]: (style) Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\n" "[test.cpp:7:19] -> [test.cpp:8:7]: (style) Redundant initialization for 'p'. The initialized value is overwritten before it is read. [redundantInitialization]\n", @@ -10984,7 +10984,7 @@ class TestOther : public TestFixture { " struct foo x;\n" " x.a = _mm_set1_ps(1.0);\n" " x.a = _mm_set1_ps(2.0);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:7] -> [test.cpp:8:7]: (style) Variable 'x.a' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); check("void f() {\n" @@ -10992,13 +10992,13 @@ class TestOther : public TestFixture { " ab.x = 23;\n" " ab.y = 41;\n" " ab.x = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:5:8]: (style) Variable 'ab.x' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); check("void f() {\n" " struct AB ab = {0};\n" " ab = foo();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -11019,7 +11019,7 @@ class TestOther : public TestFixture { " u.l1 = 1;\n" " lTotal += u.b.b1;\n" " u.l1 = 2;\n" //Should not show RedundantAssignment - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // Ticket #5115 "redundantAssignment when using a union" @@ -11037,7 +11037,7 @@ class TestOther : public TestFixture { " } u;\n" " u.l1 = 1;\n" " u.l1 = 2;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); // Ticket #10093 "redundantAssignment when using a union" @@ -11061,7 +11061,7 @@ class TestOther : public TestFixture { " m.u16.ab = 47;\n" " m.u16.cd = 0;\n" " m.u16.ab = m.u32.abcd / 53;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // Ticket #10093 "redundantAssignment when using a union" @@ -11079,7 +11079,7 @@ class TestOther : public TestFixture { " u.as_int = 42;\n" " fn(&u.as_char[0], 4);\n" " u.as_int = 0;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // Ticket #5115 "redundantAssignment when using a union" @@ -11090,7 +11090,7 @@ class TestOther : public TestFixture { " } addr;\n" " addr.s8 = ptr;\n" " addr.u64 += 8;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("struct S {\n" // #12895 @@ -11167,7 +11167,7 @@ class TestOther : public TestFixture { " }\n" " catch (const uno::Exception&) {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void ConvertBitmapData(sal_uInt16 nDestBits) {\n" @@ -11176,7 +11176,7 @@ class TestOther : public TestFixture { " BitmapBuffer aDstBuf;\n" " aSrcBuf.mnBitCount = nDestBits;\n" " bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); check("void ConvertBitmapData(sal_uInt16 nDestBits) {\n" " BitmapBuffer aSrcBuf;\n" @@ -11184,7 +11184,7 @@ class TestOther : public TestFixture { " BitmapBuffer aDstBuf;\n" " aSrcBuf.mnBitCount = nDestBits;\n" " bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:24] -> [test.cpp:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); @@ -11193,7 +11193,7 @@ class TestOther : public TestFixture { " C c;\n" " c = x;\n" " c = x;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7] -> [test.cpp:5:7]: (style, inconclusive) Variable 'c' is reassigned a value before the old one has been used if variable is no semaphore variable. [redundantAssignment]\n", errout_str()); } @@ -11207,7 +11207,7 @@ class TestOther : public TestFixture { " m->prev->next = m->next;\n" " m->next->prev = m->prev;\n" " return m->next;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -11221,7 +11221,7 @@ class TestOther : public TestFixture { " x = 6;\n" " f();\n" " return y;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #10228 @@ -11241,7 +11241,7 @@ class TestOther : public TestFixture { " for (i = 0; i < 4; i++)\n" " buf[i] = 131;\n" " buf[i] = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void bar() {\n" // #9262 do-while with break @@ -11251,20 +11251,20 @@ class TestOther : public TestFixture { " if (foo()) break;\n" " x = 1;\n" " } while (false);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int num) {\n" // #9420 FP " int a = num;\n" " for (int b = 0; b < num; a = b++)\n" " dostuff(a);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(int num) {\n" // #9420 FN " int a = num;\n" " for (int b = 0; b < num; a = b++);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("error", "", errout_str()); } @@ -11277,7 +11277,7 @@ class TestOther : public TestFixture { " break;\n" " }\n" " ret = 3;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:13] -> [test.cpp:8:9]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); } @@ -11287,7 +11287,7 @@ class TestOther : public TestFixture { " *x = 23;\n" " foo(ptr);\n" " *x = 32;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #8997 @@ -11297,7 +11297,7 @@ class TestOther : public TestFixture { " *p = 1;\n" " p += 1;\n" " *p = 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -11306,7 +11306,7 @@ class TestOther : public TestFixture { " *p = 1;\n" " if (condition) return;\n" " *p = 2;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -11318,7 +11318,7 @@ class TestOther : public TestFixture { " i += 2;\n" " arr[i] = 3;\n" " dostuff(arr);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -11332,9 +11332,9 @@ class TestOther : public TestFixture { " if (b) break;\n" " ret = 1;\n" " break;\n" - " }" + " }\n" " return ret;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int a, int b) {\n" @@ -11345,8 +11345,8 @@ class TestOther : public TestFixture { " if (b) break;\n" " ret = 1;\n" " break;\n" - " }" - "}"); + " }\n" + "}\n"); ASSERT_EQUALS("[test.cpp:5:13] -> [test.cpp:7:13]: (style) Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); } @@ -11356,7 +11356,7 @@ class TestOther : public TestFixture { check("void f() {\n" " int err = -ENOMEM;\n" " err = dostuff();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9]: style: Redundant initialization for 'err'. The initialized value is overwritten before it is read. [redundantInitialization]\n" "[test.cpp:2:13]: note: err is initialized\n" "[test.cpp:3:9]: note: err is overwritten\n", @@ -11365,7 +11365,7 @@ class TestOther : public TestFixture { check("void f() {\n" " struct S s = {1,2,3};\n" " s = dostuff();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:7]: style: Redundant initialization for 's'. The initialized value is overwritten before it is read. [redundantInitialization]\n" "[test.cpp:2:16]: note: s is initialized\n" "[test.cpp:3:7]: note: s is overwritten\n", @@ -11374,7 +11374,7 @@ class TestOther : public TestFixture { check("void f() {\n" " int *p = NULL;\n" " p = dostuff();\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:10]: style: Variable 'p' can be declared as pointer to const [constVariablePointer]\n", errout_str()); @@ -11383,14 +11383,14 @@ class TestOther : public TestFixture { check("void f() {\n" " struct S s = {0};\n" " s = dostuff();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("namespace N { enum E {e0,e1}; }\n" "void f() {\n" " N::E e = N::e0;\n" // #9261 " e = dostuff();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" // #10143 @@ -11415,21 +11415,21 @@ class TestOther : public TestFixture { " char a[10];\n" " memcpy(a, foo, bar);\n" " memset(a, 0, bar);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\n", errout_str()); check("void f() {\n" " char a[10];\n" " strcpy(a, foo);\n" " strncpy(a, 0, bar);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\n", errout_str()); check("void f() {\n" " char a[10];\n" " sprintf(a, \"foo\");\n" " memmove(a, 0, bar);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'a' is being written before its old content has been used.\n", errout_str()); check("void f(char *filename) {\n" @@ -11437,14 +11437,14 @@ class TestOther : public TestFixture { " strcpy(p, \"foo\");\n" " dostuff(filename);\n" " strcpy(p, \"foo\");\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Writing to different parts of a buffer check("void f(void* a) {\n" " memcpy(a, foo, bar);\n" " memset(a+5, 0, bar);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Use variable as second argument @@ -11452,7 +11452,7 @@ class TestOther : public TestFixture { " memset(a, 0, 5);\n" " memcpy(b, a, 5);\n" " memset(a, 1, 5);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // strcat is special @@ -11461,7 +11461,7 @@ class TestOther : public TestFixture { " strcpy(a, foo);\n" " strcat(a, bar);\n" // Not redundant " strcpy(a, x);\n" // Redundant - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\n", errout_str()); // Tests with function call between copy @@ -11470,7 +11470,7 @@ class TestOther : public TestFixture { " snprintf(a, foo, bar);\n" " bar();\n" " memset(a, 0, size);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\n", errout_str()); check("void* a;\n" @@ -11478,7 +11478,7 @@ class TestOther : public TestFixture { " memset(a, 0, size);\n" " bar();\n" // Global variable might be accessed in bar() " memset(a, 0, size);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -11486,7 +11486,7 @@ class TestOther : public TestFixture { " memset(a, 0, size);\n" " bar();\n" " memset(a, 0, size);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (performance) Buffer 'a' is being written before its old content has been used.\n", "", errout_str()); check("void bar(void* a) {}\n" @@ -11494,7 +11494,7 @@ class TestOther : public TestFixture { " memset(a, 0, size);\n" " bar(a);\n" // Passed as argument " memset(a, 0, size);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // Branch tests @@ -11502,7 +11502,7 @@ class TestOther : public TestFixture { " memset(a, 0, size);\n" " if(x)\n" " memset(a, 0, size);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #4455 - initialization of local buffer @@ -11510,14 +11510,14 @@ class TestOther : public TestFixture { " char buf[10];\n" " memset(buf, 0, 10);\n" " strcpy(buf, string);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(void) {\n" " char buf[10] = {0};\n" " memset(buf, 0, 10);\n" " strcpy(buf, string);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\n", errout_str()); // #5689 - use return value of strcpy @@ -11525,7 +11525,7 @@ class TestOther : public TestFixture { " int i = atoi(strcpy(a, foo));\n" " strncpy(a, 0, bar);\n" " return i;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #7175 - read+write @@ -11534,7 +11534,7 @@ class TestOther : public TestFixture { " strcpy(buf, x);\n" " strcpy(buf, dostuff(buf));\n" // <- read + write " strcpy(buf, x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -11542,7 +11542,7 @@ class TestOther : public TestFixture { " strcpy(buf, x);\n" " strcpy(buf, dostuff(buf));\n" " strcpy(buf, x);\n" - "}"); + "}\n"); TODO_ASSERT_EQUALS("error", "", errout_str()); } @@ -11612,17 +11612,17 @@ class TestOther : public TestFixture { void varFuncNullUB() { // #4482 check("void a(...);\n" - "void b() { a(NULL); }"); + "void b() { a(NULL); }\n"); ASSERT_EQUALS("[test.cpp:2:13]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]\n", errout_str()); check("void a(char *p, ...);\n" - "void b() { a(NULL, 2); }"); + "void b() { a(NULL, 2); }\n"); ASSERT_EQUALS("", errout_str()); checkP("extern const int sentinel;\n" "void a(int, ...);\n" "#define b(x, ...) a((x), __VA_ARGS__, &sentinel)\n" - "void c() { b(1, NULL); }"); + "void c() { b(1, NULL); }\n"); ASSERT_EQUALS("", errout_str()); } @@ -11636,7 +11636,7 @@ class TestOther : public TestFixture { " bar(c);\n" " c = getchar();\n" " } ;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f() {\n" @@ -11645,7 +11645,7 @@ class TestOther : public TestFixture { " {\n" " bar(c);\n" " } ;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f() {\n" @@ -11655,7 +11655,7 @@ class TestOther : public TestFixture { " bar(c);\n" " c = getchar();\n" " } ;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:17]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f() {\n" @@ -11663,7 +11663,7 @@ class TestOther : public TestFixture { " while( EOF != ( c = getchar() ) )\n" " {\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:19]: (warning) Storing getchar() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f() {\n" @@ -11673,7 +11673,7 @@ class TestOther : public TestFixture { " bar(i);\n" " i = getchar();\n" " } ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -11683,7 +11683,7 @@ class TestOther : public TestFixture { " bar(i);\n" " i = getchar();\n" " } ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); @@ -11693,7 +11693,7 @@ class TestOther : public TestFixture { "do {\n" " c = getc (pFile);\n" "} while (c != EOF);" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:10]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f (FILE * pFile){\n" @@ -11701,7 +11701,7 @@ class TestOther : public TestFixture { "do {\n" " c = getc (pFile);\n" "} while (EOF != c);" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:17]: (warning) Storing getc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f (FILE * pFile){\n" @@ -11709,7 +11709,7 @@ class TestOther : public TestFixture { "do {\n" " i = getc (pFile);\n" "} while (i != EOF);" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f (FILE * pFile){\n" @@ -11717,7 +11717,7 @@ class TestOther : public TestFixture { "do {\n" " i = getc (pFile);\n" "} while (EOF != i);" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); @@ -11727,7 +11727,7 @@ class TestOther : public TestFixture { "do {\n" " c = fgetc (pFile);\n" "} while (c != EOF);" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:10]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f (FILE * pFile){\n" @@ -11735,7 +11735,7 @@ class TestOther : public TestFixture { "do {\n" " c = fgetc (pFile);\n" "} while (EOF != c);" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:17]: (warning) Storing fgetc() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f (FILE * pFile){\n" @@ -11743,7 +11743,7 @@ class TestOther : public TestFixture { "do {\n" " c = fgetc (pFile);\n" "} while (EOF != c);" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f (FILE * pFile){\n" @@ -11751,7 +11751,7 @@ class TestOther : public TestFixture { "do {\n" " i = fgetc (pFile);\n" "} while (i != EOF);" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f (FILE * pFile){\n" @@ -11759,7 +11759,7 @@ class TestOther : public TestFixture { "do {\n" " i = fgetc (pFile);\n" "} while (EOF != i);" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // cin.get() @@ -11769,7 +11769,7 @@ class TestOther : public TestFixture { " std::cout << ch;\n" " ch = std::cin.get();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:18]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f(){\n" @@ -11778,7 +11778,7 @@ class TestOther : public TestFixture { " std::cout << ch;\n" " ch = std::cin.get();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:11]: (warning) Storing cin.get() return value in char variable and then comparing with EOF. [checkCastIntToCharAndBack]\n", errout_str()); check("void f(){\n" @@ -11787,7 +11787,7 @@ class TestOther : public TestFixture { " std::cout << i;\n" " i = std::cin.get();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(){\n" @@ -11796,7 +11796,7 @@ class TestOther : public TestFixture { " std::cout << i;\n" " i = std::cin.get();\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -11805,32 +11805,32 @@ class TestOther : public TestFixture { " if (a < 0)\n" " return a++,\n" " do_something();\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\n", "", errout_str()); check("int fun(int a) {\n" " if (a < 0)\n" " return a++, do_something();\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("int fun(int a) {\n" " if (a < 0)\n" " return a+5,\n" " do_something();\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\n", "", errout_str()); check("int fun(int a) {\n" " if (a < 0)\n" " return a+5, do_something();\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("int fun(int a) {\n" " if (a < 0)\n" " return c::b;\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // #4943 take care of C++11 initializer lists @@ -11841,7 +11841,7 @@ class TestOther : public TestFixture { " { \"2\" },\n" " { \"3\" }\n" " };\n" - "}", dinit(CheckOptions, $.inconclusive = false)); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); } @@ -11857,7 +11857,7 @@ class TestOther : public TestFixture { " explicit B(A a) : a(std::move(a)) {}\n" " void Init(A _a) { a = std::move(_a); }\n" " A a;" - "};", dinit(CheckOptions, $.inconclusive = false)); + "};\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("struct A\n" @@ -11870,7 +11870,7 @@ class TestOther : public TestFixture { " explicit B(A a) : a{std::move(a)} {}\n" " void Init(A _a) { a = std::move(_a); }\n" " A a;" - "};", dinit(CheckOptions, $.inconclusive = false)); + "};\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("struct A\n" @@ -11884,7 +11884,7 @@ class TestOther : public TestFixture { " void Init(A _a) { a = std::move(_a); }\n" " A a;" " A a2;" - "};", dinit(CheckOptions, $.inconclusive = false)); + "};\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("struct A\n" @@ -11898,7 +11898,7 @@ class TestOther : public TestFixture { " void Init(A _a) { a = std::move(_a); }\n" " A a;" " A a2;" - "};", dinit(CheckOptions, $.inconclusive = false)); + "};\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\n", errout_str()); check("struct A\n" @@ -11912,11 +11912,11 @@ class TestOther : public TestFixture { " void Init(A _a) { a = std::move(_a); }\n" " A a;" " A a2;" - "};", dinit(CheckOptions, $.inconclusive = false)); + "};\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\n", errout_str()); check("std::map m;\n" // #10817 - "void f(const decltype(m)::const_iterator i) {}"); + "void f(const decltype(m)::const_iterator i) {}\n"); ASSERT_EQUALS("", errout_str()); check("int (*pf) (std::vector) = nullptr;\n" // #12118 @@ -11959,7 +11959,7 @@ class TestOther : public TestFixture { "};\n" "T f(T t) {\n" " return t;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // don't crash Settings settingsUnix32 = settingsBuilder().platform(Platform::Type::Unix32).build(); @@ -11976,33 +11976,33 @@ class TestOther : public TestFixture { // positive test check("bool f(int x){\n" " return isless(x,x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of two identical variables with isless(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\n", errout_str()); check("bool f(int x){\n" " return isgreater(x,x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\n", errout_str()); check("bool f(int x){\n" " return islessgreater(x,x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of two identical variables with islessgreater(x,x) always evaluates to false. [comparisonFunctionIsAlwaysTrueOrFalse]\n", errout_str()); check("bool f(int x){\n" " return islessequal(x,x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of two identical variables with islessequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\n", errout_str()); check("bool f(int x){\n" " return isgreaterequal(x,x);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:11]: (warning) Comparison of two identical variables with isgreaterequal(x,x) always evaluates to true. [comparisonFunctionIsAlwaysTrueOrFalse]\n", errout_str()); // no warning should be reported for check("bool f(int x, int y){\n" " return isgreaterequal(x,y) && islessequal(x,y) && islessgreater(x,y) && isgreater(x,y) && isless(x,y);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -12010,7 +12010,7 @@ class TestOther : public TestFixture { // no signed integer overflow should happen check("void f(unsigned long long ull) {\n" " if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -12105,7 +12105,7 @@ class TestOther : public TestFixture { void test_isSameExpression() { // see #5738 check("bool isInUnoIncludeFile(StringRef name) {" " return name.startswith(SRCDIR \"/com/\") || name.startswith(SRCDIR \"/uno/\");\n" - "};", dinit(CheckOptions, $.inconclusive = false)); + "};\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); } @@ -12114,7 +12114,7 @@ class TestOther : public TestFixture { " int counter = 0;\n" " InterlockedDecrement(&counter);\n" " whatever();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12123,7 +12123,7 @@ class TestOther : public TestFixture { " if (counter)\n" " return;\n" " destroy();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12131,7 +12131,7 @@ class TestOther : public TestFixture { " InterlockedDecrement(&counter);\n" " if (!counter)\n" " destroy();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12140,7 +12140,7 @@ class TestOther : public TestFixture { " if (counter > 0)\n" " return;\n" " destroy();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12149,7 +12149,7 @@ class TestOther : public TestFixture { " if (0 < counter)\n" " return;\n" " destroy();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12157,7 +12157,7 @@ class TestOther : public TestFixture { " InterlockedDecrement(&counter);\n" " if (counter == 0)\n" " destroy();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12165,7 +12165,7 @@ class TestOther : public TestFixture { " InterlockedDecrement(&counter);\n" " if (0 == counter)\n" " destroy();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12174,7 +12174,7 @@ class TestOther : public TestFixture { " if (0 != counter)\n" " return;\n" " destroy()\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12183,7 +12183,7 @@ class TestOther : public TestFixture { " if (counter != 0)\n" " return;\n" " destroy()\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12191,7 +12191,7 @@ class TestOther : public TestFixture { " InterlockedDecrement(&counter);\n" " if (counter <= 0)\n" " destroy();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12199,7 +12199,7 @@ class TestOther : public TestFixture { " InterlockedDecrement(&counter);\n" " if (0 >= counter)\n" " destroy();\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12208,7 +12208,7 @@ class TestOther : public TestFixture { " if (newCount)\n" " return;\n" " destroy();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12216,7 +12216,7 @@ class TestOther : public TestFixture { " int newCount = InterlockedDecrement(&counter);\n" " if (!newCount)\n" " destroy();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12225,7 +12225,7 @@ class TestOther : public TestFixture { " if (newCount > 0)\n" " return;\n" " destroy();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12234,7 +12234,7 @@ class TestOther : public TestFixture { " if (0 < newCount)\n" " return;\n" " destroy();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12242,7 +12242,7 @@ class TestOther : public TestFixture { " int newCount = InterlockedDecrement(&counter);\n" " if (newCount == 0)\n" " destroy();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12250,7 +12250,7 @@ class TestOther : public TestFixture { " int newCount = InterlockedDecrement(&counter);\n" " if (0 == newCount)\n" " destroy();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12259,7 +12259,7 @@ class TestOther : public TestFixture { " if (0 != newCount)\n" " return;\n" " destroy()\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12268,7 +12268,7 @@ class TestOther : public TestFixture { " if (newCount != 0)\n" " return;\n" " destroy()\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12276,7 +12276,7 @@ class TestOther : public TestFixture { " int newCount = InterlockedDecrement(&counter);\n" " if (newCount <= 0)\n" " destroy();\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkInterlockedDecrement("void f() {\n" @@ -12284,7 +12284,7 @@ class TestOther : public TestFixture { " int newCount = InterlockedDecrement(&counter);\n" " if (0 >= newCount)\n" " destroy;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); checkInterlockedDecrement("int f() {\n" @@ -12295,7 +12295,7 @@ class TestOther : public TestFixture { " } else {\n" " return counter;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("int f() {\n" @@ -12306,7 +12306,7 @@ class TestOther : public TestFixture { " } else {\n" " return counter;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); @@ -12317,7 +12317,7 @@ class TestOther : public TestFixture { " return 0;\n" " }\n" " return counter;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("int f() {\n" @@ -12327,7 +12327,7 @@ class TestOther : public TestFixture { " return 0;\n" " }\n" " return counter;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:12]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("int f() {\n" @@ -12338,7 +12338,7 @@ class TestOther : public TestFixture { " } else\n" " return counter;\n" " \n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); checkInterlockedDecrement("int f() {\n" @@ -12349,21 +12349,21 @@ class TestOther : public TestFixture { " } else\n" " return counter;\n" " \n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:16]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead. [raceAfterInterlockedDecrement]\n", errout_str()); } void testUnusedLabel() { check("void f() {\n" " label:\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\n", errout_str()); check("void f() {\n" " label:\n" " foo();\n" " goto label;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -12373,28 +12373,28 @@ class TestOther : public TestFixture { "}\n" "void g() {\n" " label:\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:5]: (style) Label 'label' is not used. [unusedLabel]\n", errout_str()); check("void f() {\n" " switch(a) {\n" " default:\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " class X {\n" " protected:\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " class X {\n" " my_protected:\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int test(char art) {\n" @@ -12406,7 +12406,7 @@ class TestOther : public TestFixture { " case 2:\n" " return 2;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (warning) Label 'caseZERO' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\n" "[test.cpp:5:5]: (warning) Label 'case1' is not used. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitch]\n", errout_str()); @@ -12416,7 +12416,7 @@ class TestOther : public TestFixture { " return 2;\n" " }\n" " label:\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\n", errout_str()); } @@ -12427,7 +12427,7 @@ class TestOther : public TestFixture { " goto END;\n" "#endif\n" "END:\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:1]: (style) Label 'END' is not used. There is #if in function body so the label might be used in code that is removed by the preprocessor. [unusedLabelConfiguration]\n", errout_str()); } @@ -12445,7 +12445,7 @@ class TestOther : public TestFixture { " END:\n" " return;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:10:5]: (warning) Label 'END' is not used. There is #if in function body so the label might be used in code that is removed by the preprocessor. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitchConfiguration]\n", errout_str()); } @@ -12454,12 +12454,12 @@ class TestOther : public TestFixture { Settings s; check("void f() {\n" " label:\n" - "}", dinit(CheckOptions, $.settings = &s)); + "}\n", dinit(CheckOptions, $.settings = &s)); ASSERT_EQUALS("", errout_str()); s.premiumArgs = "--premium=misra-c-2012"; // <- activates unusedLabel checking check("void f() {\n" " label:\n" - "}", dinit(CheckOptions, $.settings = &s)); + "}\n", dinit(CheckOptions, $.settings = &s)); ASSERT_EQUALS("[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\n", errout_str()); } @@ -12479,24 +12479,24 @@ class TestOther : public TestFixture { check("void f() {\n" " int x = dostuff();\n" " return x + x++;\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); // #7226 check("long int f1(const char *exp) {\n" " return strtol(++exp, (char **)&exp, 10);\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("long int f1(const char *exp) {\n" " return dostuff(++exp, exp, 10);\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); check("void f() {\n" " int a;\n" " while (a=x(), a==123) {}\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); // # 8717 @@ -12521,25 +12521,25 @@ class TestOther : public TestFixture { check("void f(int i) {\n" " int n = ++i + i;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:15]: (error) Expression '++i+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); check("long int f1(const char *exp) {\n" " return dostuff(++exp, ++exp, 10);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\n" "[test.cpp:2:23]: (portability) Expression '++exp,++exp' depends on order of evaluation of side effects. Behavior is Unspecified according to c++17 [unknownEvaluationOrder]\n", errout_str()); check("void f(int i) {\n" " int n = (~(-(++i)) + i);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); const Settings settings11 = settingsBuilder(settings0).cpp(Standards::CPP11).certainty(Certainty::inconclusive).build(); checkCustomSettings("void f(int i) {\n" " i = i++ + 2;\n" - "}", settings11); + "}\n", settings11); ASSERT_EQUALS("[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); // #14431 @@ -12553,7 +12553,7 @@ class TestOther : public TestFixture { // self assignment check("void f() {\n" " int x = x = y + 1;\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS( "[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n" "[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n", // duplicate @@ -12565,7 +12565,7 @@ class TestOther : public TestFixture { checkP("#define X x\n" "void f(int x) {\n" " return x + X++;\n" - "}", dinit(CheckPOptions, $.cpp = false)); + "}\n", dinit(CheckPOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); } @@ -12573,13 +12573,13 @@ class TestOther : public TestFixture { // FP check("void f(int id) {\n" " id = dostuff(id += 42);\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); // FN check("void f(int id) {\n" " id = id + dostuff(id += 42);\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); TODO_ASSERT_EQUALS("error", "", errout_str()); } @@ -12587,19 +12587,19 @@ class TestOther : public TestFixture { check("int f(void) {\n" " int t;\n" " return (unsigned char)(t=1,t^c);\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("void f(void) {\n" " int t;\n" " dostuff(t=1,t^c);\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); check("void f(void) {\n" " int t;\n" " dostuff((t=1,t),2);\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); // #8230 @@ -12628,7 +12628,7 @@ class TestOther : public TestFixture { void testEvaluationOrderSizeof() { check("void f(char *buf) {\n" " dostuff(buf++, sizeof(*buf));" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); } @@ -12647,7 +12647,7 @@ class TestOther : public TestFixture { " if (0 > d.n) {\n" " return;\n" " }\n" - "}", dinit(CheckOptions, $.cpp = false)); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\n" "[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\n", errout_str()); @@ -12659,7 +12659,7 @@ class TestOther : public TestFixture { " A a;\n" " g(std::move(a));\n" " g(std::move(a));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:17]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } @@ -12673,7 +12673,7 @@ class TestOther : public TestFixture { " }\n" " B b1;\n" " B b2;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:6:24]: (warning) Access of moved variable 'b'. [accessMoved]\n", errout_str()); } @@ -12686,7 +12686,7 @@ class TestOther : public TestFixture { " {}\n" " B b1;\n" " B b2;\n" - "};"); + "};\n"); ASSERT_EQUALS("[test.cpp:5:19]: (warning) Access of moved variable 'b'. [accessMoved]\n", errout_str()); } @@ -12717,7 +12717,7 @@ class TestOther : public TestFixture { " A a;\n" " a = g(std::move(a));\n" " a = g(std::move(a));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -12727,7 +12727,7 @@ class TestOther : public TestFixture { " A a;\n" " B b = g(std::move(a));\n" " C c = g(std::move(a));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:23]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } @@ -12743,7 +12743,7 @@ class TestOther : public TestFixture { " h(a);\n" " a = b;\n" " h(a);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\n" "[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } @@ -12754,7 +12754,7 @@ class TestOther : public TestFixture { " A a;\n" " a.reset(g(std::move(a)));\n" " a.reset(g(std::move(a)));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -12766,7 +12766,7 @@ class TestOther : public TestFixture { " A c;\n" " b.reset(g(std::move(a)));\n" " c.reset(g(std::move(a)));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:25]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } @@ -12782,7 +12782,7 @@ class TestOther : public TestFixture { " h(a);\n" " a.reset(b);\n" " h(a);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7]: (warning) Access of moved variable 'a'. [accessMoved]\n" "[test.cpp:8:7]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } @@ -12794,7 +12794,7 @@ class TestOther : public TestFixture { " A b = std::move(a);\n" " g(a);\n" " A c = a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\n" "[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } @@ -12806,7 +12806,7 @@ class TestOther : public TestFixture { " A b = std::move(a);\n" " g(a);\n" " A c = a;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -12817,7 +12817,7 @@ class TestOther : public TestFixture { " A b = std::move(a);\n" " g(a);\n" " A c = a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:7]: (warning) Access of moved variable 'a'. [accessMoved]\n" "[test.cpp:6:11]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } @@ -12828,7 +12828,7 @@ class TestOther : public TestFixture { " A b = std::move(a);\n" " g(a);\n" " A c = a;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\n" "[test.cpp:5:11]: (warning, inconclusive) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } @@ -12841,7 +12841,7 @@ class TestOther : public TestFixture { " if (i)\n" " return g(std::move(b));\n" " return h(std::move(a),std::move(b));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:7:24]: (warning) Access of moved variable 'a'. [accessMoved]\n", errout_str()); } @@ -12851,7 +12851,7 @@ class TestOther : public TestFixture { " g(std::move(v));\n" " v.clear();\n" " if (v.empty()) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -12861,7 +12861,7 @@ class TestOther : public TestFixture { " g(std::move(p));\n" " x = p->x;\n" " y = p->y;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (warning) Access of moved variable 'p'. [accessMoved]\n" "[test.cpp:5:9]: (warning) Access of moved variable 'p'. [accessMoved]\n", errout_str()); } @@ -12871,7 +12871,7 @@ class TestOther : public TestFixture { " std::string s1 = x;\n" " std::string s2 = std::move(s1);\n" " p = &s1;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -12880,16 +12880,16 @@ class TestOther : public TestFixture { " A a;\n" " gx(std::move(a).x());\n" " gy(std::move(a).y());\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void moveAndLambda() { check("void f() {\n" " A a;\n" - " auto h = [a=std::move(a)](){return g(std::move(a));};" + " auto h = [a=std::move(a)](){return g(std::move(a));};\n" " b = a;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -12960,7 +12960,7 @@ class TestOther : public TestFixture { "void f(T && t) {\n" " g(std::forward(t));\n" " T s = t;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:11]: (warning) Access of forwarded variable 't'. [accessForwarded]\n", errout_str()); } @@ -13093,7 +13093,7 @@ class TestOther : public TestFixture { "void Fred::func1(int a, int b, int c) { }\n" "void Fred::func2(int A, int B, int C) { }\n" "void Fred::func3(int a, int b, int c) { }\n" - "void Fred::func4(int A, int B, int C) { }"); + "void Fred::func4(int A, int B, int C) { }\n"); ASSERT_EQUALS("[test.cpp:3:16] -> [test.cpp:4:16]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'. [funcArgNamesDifferent]\n" "[test.cpp:3:23] -> [test.cpp:4:23]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'. [funcArgNamesDifferent]\n" "[test.cpp:3:30] -> [test.cpp:4:30]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'. [funcArgNamesDifferent]\n" @@ -13170,49 +13170,49 @@ class TestOther : public TestFixture { // #7846 - Syntax error when using C++11 braced-initializer in default argument void cpp11FunctionArgInit() { // syntax error is not expected - ASSERT_NO_THROW(check("\n void foo(int declaration = {}) {" + ASSERT_NO_THROW(check("\n void foo(int declaration = {}) {\n" "\n for (int i = 0; i < 10; i++) {}\n" - "\n }" - "\n ")); + "\n }\n" + "\n")); ASSERT_EQUALS("", errout_str()); } void shadowVariables() { check("int x;\n" - "void f() { int x; }"); + "void f() { int x; }\n"); ASSERT_EQUALS("[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer variable [shadowVariable]\n", errout_str()); check("int x();\n" - "void f() { int x; }"); + "void f() { int x; }\n"); ASSERT_EQUALS("[test.cpp:1:5] -> [test.cpp:2:16]: (style) Local variable 'x' shadows outer function [shadowFunction]\n", errout_str()); check("struct C {\n" " C(int x) : x(x) {}\n" // <- we do not want a FP here " int x;\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " if (cond) {int x;}\n" // <- not a shadow variable " int x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int size() {\n" " int size;\n" // <- not a shadow variable - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f() {\n" // #8954 - lambda " int x;\n" - " auto f = [](){ int x; }" - "}"); + " auto f = [](){ int x; }\n" + "}\n"); ASSERT_EQUALS("", errout_str()); - check("void f(int x) { int x; }"); + check("void f(int x) { int x; }\n"); ASSERT_EQUALS("[test.cpp:1:12] -> [test.cpp:1:21]: (style) Local variable 'x' shadows outer argument [shadowArgument]\n", errout_str()); - check("class C { C(); void foo() { static int C = 0; } }"); // #9195 - shadow constructor + check("class C { C(); void foo() { static int C = 0; } }\n"); // #9195 - shadow constructor ASSERT_EQUALS("", errout_str()); check("struct C {\n" // #10091 - shadow destructor @@ -13221,7 +13221,7 @@ class TestOther : public TestFixture { " bool C{};\n" " }\n" "};\n" - "C::~C() = default;"); + "C::~C() = default;\n"); ASSERT_EQUALS("", errout_str()); // 10752 - no @@ -13232,7 +13232,7 @@ class TestOther : public TestFixture { " int i = 0;\n" " return i;\n" " }\n" - "};"); + "};\n"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" @@ -13317,19 +13317,19 @@ class TestOther : public TestFixture { check("void g(int);\n" "void f(int x) {\n" " g((x & 0x01) >> 7);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:17]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\n", errout_str()); check("void g(int);\n" "void f(int x) {\n" " g((int)((x & 0x01) >> 7));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:6]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\n", errout_str()); check("void g(int, int);\n" "void f(int x) {\n" " g(x, (x & 0x01) >> 7);\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:20]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has. [knownArgument]\n", errout_str()); @@ -13337,65 +13337,65 @@ class TestOther : public TestFixture { check("void g(int);\n" "void f(int x) {\n" " g(0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void g(int);\n" "void h() { return 1; }\n" "void f(int x) {\n" " g(h());\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void g(int);\n" "void f(int x) {\n" " g(std::strlen(\"a\"));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void g(int);\n" "void f(int x) {\n" " g((int)0);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void g(Foo *);\n" "void f() {\n" " g(reinterpret_cast(0));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void g(int);\n" "void f(int x) {\n" " x = 0;\n" " g(x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void g(int);\n" "void f() {\n" " const int x = 0;\n" " g(x + 1);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void g(int);\n" "void f() {\n" " char i = 1;\n" " g(static_cast(i));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("char *yytext;\n" "void re_init_scanner() {\n" " int size = 256;\n" " yytext = xmalloc(size * sizeof *yytext);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void foo(const char *c) {\n" " if (*c == '+' && (operand || !isalnum(*c))) {}\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #8986 @@ -13403,14 +13403,14 @@ class TestOther : public TestFixture { "void g() {\n" " const int x[] = { 10, 10 };\n" " f(x[0]);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int);\n" "void g() {\n" " int x[] = { 10, 10 };\n" " f(x[0]);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:9]: (style) Variable 'x' can be declared as const array [constVariable]\n", errout_str()); check("struct A { int x; };" @@ -13419,21 +13419,21 @@ class TestOther : public TestFixture { " A y;\n" " y.x = 1;\n" " g(y.x);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // allow known argument value in assert call check("void g(int);\n" "void f(int x) {\n" " ASSERT((int)((x & 0x01) >> 7));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9905 - expression that does not use integer calculation at all check("void foo() {\n" " const std::string heading = \"Interval\";\n" " std::cout << std::setw(heading.length());\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9909 - struct member with known value @@ -13444,7 +13444,7 @@ class TestOther : public TestFixture { "void growLongStack(LongStack* self) {\n" " self->maxsize = 32;\n" " dostuff(self->maxsize * sizeof(intptr_t));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #11894 @@ -13539,7 +13539,7 @@ class TestOther : public TestFixture { " bar(P, N); \n" " if (c ? a : b)\n" " baz(P, N); \n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -13552,7 +13552,7 @@ class TestOther : public TestFixture { " diff = 1;\n" " }\n" " return diff;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:15] -> [test.cpp:5:8] -> [test.cpp:3:15] -> [test.cpp:5:14] -> [test.cpp:5:12]: (error) Comparing pointers that point to different objects [comparePointers]\n", errout_str()); @@ -13563,7 +13563,7 @@ class TestOther : public TestFixture { " int* xp = &x;\n" " int* yp = &y;\n" " return xp > yp;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:9] -> [test.cpp:4:15] -> [test.cpp:3:9] -> [test.cpp:5:15] -> [test.cpp:6:15]: (error) Comparing pointers that point to different objects [comparePointers]\n" "[test.cpp:4:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\n" @@ -13574,7 +13574,7 @@ class TestOther : public TestFixture { " int x = 0;\n" " int y = 1;\n" " return &x > &y;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Comparing pointers that point to different objects [comparePointers]\n", errout_str()); @@ -13586,7 +13586,7 @@ class TestOther : public TestFixture { " int* xp = &x.data;\n" " int* yp = &y.data;\n" " return xp > yp;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:3:7] -> [test.cpp:5:15] -> [test.cpp:4:7] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\n" "[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\n" @@ -13600,7 +13600,7 @@ class TestOther : public TestFixture { " int* xp = &x->data;\n" " int* yp = &y->data;\n" " return xp > yp;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:10] -> [test.cpp:3:12] -> [test.cpp:5:15] -> [test.cpp:2:16] -> [test.cpp:4:12] -> [test.cpp:6:15] -> [test.cpp:7:15]: (error) Comparing pointers that point to different objects [comparePointers]\n" "[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\n" @@ -13609,7 +13609,7 @@ class TestOther : public TestFixture { check("bool f(int * xp, int* yp) {\n" " return &xp > &yp;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:1:14] -> [test.cpp:2:12] -> [test.cpp:1:23] -> [test.cpp:2:18] -> [test.cpp:2:16]: (error) Comparing pointers that point to different objects [comparePointers]\n", errout_str()); @@ -13618,7 +13618,7 @@ class TestOther : public TestFixture { " int x = 0;\n" " int y = 1;\n" " return &x - &y;\n" - "}"); + "}\n"); ASSERT_EQUALS( "[test.cpp:2:9] -> [test.cpp:4:12] -> [test.cpp:3:9] -> [test.cpp:4:17] -> [test.cpp:4:15]: (error) Subtracting pointers that point to different objects [subtractPointers]\n", errout_str()); @@ -13628,19 +13628,19 @@ class TestOther : public TestFixture { " int* xp = &x[0];\n" " int* yp = &x[1];\n" " return xp > yp;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\n" "[test.cpp:4:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\n", errout_str()); check("bool f(const int * xp, const int* yp) {\n" " return xp > yp;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("bool f(const int & x, const int& y) {\n" " return &x > &y;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int& g();\n" @@ -13650,7 +13650,7 @@ class TestOther : public TestFixture { " const int* xp = &x;\n" " const int* yp = &y;\n" " return xp > yp;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("struct A {int data;};\n" @@ -13660,7 +13660,7 @@ class TestOther : public TestFixture { " int* xp = &x->data;\n" " int* yp = &y->data;\n" " return xp > yp;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:10]: (style) Variable 'xp' can be declared as pointer to const [constVariablePointer]\n" "[test.cpp:6:10]: (style) Variable 'yp' can be declared as pointer to const [constVariablePointer]\n", errout_str()); @@ -13711,21 +13711,21 @@ class TestOther : public TestFixture { " return A::Hash{}(a);\n" " }\n" " };\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } void moduloOfOne() { check("void f(unsigned int x) {\n" " int y = x % 1;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:13]: (style) Modulo of one is always equal to zero [moduloofone]\n", errout_str()); check("void f() {\n" " for (int x = 1; x < 10; x++) {\n" " int y = 100 % x;\n" " }\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(int i, int j) {\n" // #11191 @@ -13758,44 +13758,44 @@ class TestOther : public TestFixture { " union { int i; float f; } u;\n" " u.i = 0;\n" " u.i = u.f;\n" // <- error - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:9]: (error) Overlapping read/write of union is undefined behavior [overlappingWriteUnion]\n", errout_str()); check("void foo() {\n" // #11013 " union { struct { uint8_t a; uint8_t b; }; uint16_t c; } u;\n" " u.a = u.b = 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // memcpy check("void foo() {\n" " char a[10];\n" " memcpy(&a[5], &a[4], 2u);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); check("void foo() {\n" " char a[10];\n" " memcpy(a+5, a+4, 2u);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); check("void foo() {\n" " char a[10];\n" " memcpy(a, a+1, 2u);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); check("void foo() {\n" " char a[8];\n" " memcpy(&a[0], &a[4], 4u);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("_Bool a[10];\n" // #10350 "void foo() {\n" " memcpy(&a[5], &a[4], 2u * sizeof(a[0]));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); check("int K[2];\n" // #12638 @@ -13804,7 +13804,7 @@ class TestOther : public TestFixture { " memcpy(&K[1], &K[0], sizeof(K[0]));\n" " memcpy(p, p + 1, sizeof(*p));\n" " memcpy(p + 1, p, sizeof(*p));\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int K[2];\n" @@ -13813,7 +13813,7 @@ class TestOther : public TestFixture { " memcpy(&K[1], &K[0], 2 *sizeof(K[0]));\n" " memcpy(p, p + 1, 2 * sizeof(*p));\n" " memcpy(p + 1, p, 2 * sizeof(*p));\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\n" "[test.cpp:4:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\n" "[test.cpp:5:5]: (error) Overlapping read/write in memcpy() is undefined behavior [overlappingWriteFunction]\n" @@ -13824,25 +13824,25 @@ class TestOther : public TestFixture { check("void foo() {\n" " wchar_t a[10];\n" " wmemcpy(&a[5], &a[4], 2u);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); check("void foo() {\n" " wchar_t a[10];\n" " wmemcpy(a+5, a+4, 2u);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); check("void foo() {\n" " wchar_t a[10];\n" " wmemcpy(a, a+1, 2u);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (error) Overlapping read/write in wmemcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); // strcpy check("void foo(char *ptr) {\n" " strcpy(ptr, ptr);\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (error) Overlapping read/write in strcpy() is undefined behavior [overlappingWriteFunction]\n", errout_str()); } @@ -13899,7 +13899,7 @@ class TestOther : public TestFixture { "}\n"); ASSERT_EQUALS("[test.cpp:4:17]: (style) Pointer expression 'a.x' converted to bool is always true. [knownPointerToBool]\n", errout_str()); - check("void f(bool* b) { if (b) *b = true; }"); + check("void f(bool* b) { if (b) *b = true; }\n"); ASSERT_EQUALS("", errout_str()); check("bool f() {\n" @@ -13947,7 +13947,7 @@ class TestOther : public TestFixture { "void f() {\n" " bool b[2] = {};\n" " g(b);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -14146,7 +14146,7 @@ class TestOther : public TestFixture { " union bad_union_0 bad1 = {0};\n" " e(&bad1);\n" " bad_union_1 bad2 = {0};\n" - "}"); + "}\n"); const std::string exp = unionZeroInitMessage(20, 28, "bad0", "i") + unionZeroInitMessage(21, 21, "bad1", "i64") + unionZeroInitMessage(23, 15, "bad2", "i"); @@ -14157,7 +14157,7 @@ class TestOther : public TestFixture { check( "void foo(void) {\n" " union { int c; char s8[2]; } u = {0};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -14173,7 +14173,7 @@ class TestOther : public TestFixture { " } s1;\n" " } s0;\n" " } u = {0};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -14181,7 +14181,7 @@ class TestOther : public TestFixture { check( "union u {\n" " Unknown x;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -14201,7 +14201,7 @@ class TestOther : public TestFixture { "\n" "void foo(void) {\n" " Evex evex = {0};\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } }; diff --git a/test/testpostfixoperator.cpp b/test/testpostfixoperator.cpp index 2277039820f..85568c974ac 100644 --- a/test/testpostfixoperator.cpp +++ b/test/testpostfixoperator.cpp @@ -71,7 +71,7 @@ class TestPostfixOperator : public TestFixture { " k--;\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class K {};" @@ -82,7 +82,7 @@ class TestPostfixOperator : public TestFixture { " k++;\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); check("struct K {};" @@ -90,14 +90,14 @@ class TestPostfixOperator : public TestFixture { "{\n" " K k(0);\n" " k++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); check("struct K {};\n" "void foo(K& k)\n" "{\n" " k++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); check("union K {};" @@ -105,7 +105,7 @@ class TestPostfixOperator : public TestFixture { "{\n" " K k(0);\n" " k++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:5]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); check("class K {};" @@ -118,7 +118,7 @@ class TestPostfixOperator : public TestFixture { " }\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:9]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); check("class K {};" @@ -132,7 +132,7 @@ class TestPostfixOperator : public TestFixture { " k++;\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:5]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); @@ -144,7 +144,7 @@ class TestPostfixOperator : public TestFixture { " k--;\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:5:5]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); check("class K {};" @@ -155,7 +155,7 @@ class TestPostfixOperator : public TestFixture { " ++k;\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class K {};" @@ -166,7 +166,7 @@ class TestPostfixOperator : public TestFixture { " --k;\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); // #9042 @@ -177,7 +177,7 @@ class TestPostfixOperator : public TestFixture { "};\n" "template \n" "class s {};\n" - "using BOOL = char;"); + "using BOOL = char;\n"); ASSERT_EQUALS("", errout_str()); } @@ -188,7 +188,7 @@ class TestPostfixOperator : public TestFixture { " std::cout << i << std::endl;\n" " }\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class K {};\n" @@ -198,7 +198,7 @@ class TestPostfixOperator : public TestFixture { " std::cout << i << std::endl;\n" " }\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:28]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); check("class K {};\n" @@ -208,7 +208,7 @@ class TestPostfixOperator : public TestFixture { " std::cout << i << std::endl;\n" " }\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("class K {};\n" @@ -218,7 +218,7 @@ class TestPostfixOperator : public TestFixture { " std::cout << i << std::endl;\n" " }\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:27]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); check("class K {};\n" @@ -228,7 +228,7 @@ class TestPostfixOperator : public TestFixture { " std::cout << i << std::endl;\n" " }\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void f(const std::string &s) {\n" // #7731 @@ -246,7 +246,7 @@ class TestPostfixOperator : public TestFixture { " k++;\n" " std::cout << k << std::endl;\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:5]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); } @@ -261,7 +261,7 @@ class TestPostfixOperator : public TestFixture { " }\n" " v.clear();\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:6:64]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); check("int main() {\n" @@ -275,7 +275,7 @@ class TestPostfixOperator : public TestFixture { " it++;\n" " }\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:8]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); check("int main() {\n" @@ -288,7 +288,7 @@ class TestPostfixOperator : public TestFixture { " it++;\n" " }\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:8:8]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); check("int main() {\n" @@ -302,14 +302,14 @@ class TestPostfixOperator : public TestFixture { " rit--;\n" " }\n" " return 0;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:9:8]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); } void test2168() { ASSERT_THROW_INTERNAL(check("--> declare allocator lock here\n" - "int main(){}"), + "int main(){}\n"), AST); } @@ -317,7 +317,7 @@ class TestPostfixOperator : public TestFixture { check("void f(int* p){\n" " p++;\n" " std::cout << *p;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -327,7 +327,7 @@ class TestPostfixOperator : public TestFixture { "\n" "void f() {\n" " p++;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -335,7 +335,7 @@ class TestPostfixOperator : public TestFixture { check("bool foo() {\n" " std::vector::iterator aIter(aImport.begin());\n" " aIter++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); } @@ -344,14 +344,14 @@ class TestPostfixOperator : public TestFixture { " class A {}; class B {A a;};\n" " B b;\n" " b.a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:7]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); check("bool foo() {\n" " class A {}; class B {A a;};\n" " B b;\n" " foo(b.a++);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -360,7 +360,7 @@ class TestPostfixOperator : public TestFixture { " class A {};\n" " A a;\n" " i++, a++;\n" - "}"); + "}\n"); ASSERT_EQUALS("[test.cpp:4:10]: (performance) Prefer prefix ++/-- operators for non-primitive types. [postfixOperator]\n", errout_str()); check("bool foo(int i) {\n" @@ -368,7 +368,7 @@ class TestPostfixOperator : public TestFixture { " A a;\n" " foo(i, a++);\n" " foo(a++, i);\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -380,7 +380,7 @@ class TestPostfixOperator : public TestFixture { " a += i;\n" " }\n" " return a;\n" - "}"); + "}\n"); ASSERT_EQUALS("", errout_str()); } }; diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 55fcafd4f4f..492727e7b7b 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -57,7 +57,7 @@ class TestPreprocessor : public TestFixture { std::string expandMacros_(const char* file, int line, const char (&code)[size], ErrorLogger &errorLogger) const { simplecpp::OutputList outputList; std::vector files; - simplecpp::TokenList tokens1 = simplecpp::TokenList(code, files, "file.cpp", &outputList); + simplecpp::TokenList tokens1 = simplecpp::TokenList(code, files, "file.cpp", {}, &outputList); Preprocessor p(tokens1, settingsDefault, errorLogger, Path::identify(tokens1.getFiles()[0], false)); ASSERT_LOC(p.loadFiles(files), file, line); simplecpp::TokenList tokens2 = p.preprocess("", files, outputList); @@ -75,7 +75,7 @@ class TestPreprocessor : public TestFixture { throw std::runtime_error("token list not empty"); simplecpp::OutputList outputList; - const simplecpp::TokenList tokens1(code, files, file0, &outputList); + const simplecpp::TokenList tokens1(code, files, file0, dui, &outputList); // Preprocess.. simplecpp::TokenList tokens2(files); @@ -124,7 +124,7 @@ class TestPreprocessor : public TestFixture { simplecpp::OutputList outputList; std::vector files; - simplecpp::TokenList tokens({code, size}, files, Path::simplifyPath(filename), &outputList); + simplecpp::TokenList tokens({code, size}, files, Path::simplifyPath(filename), {}, &outputList); // TODO: we should be using the actual Preprocessor implementation Preprocessor preprocessor(tokens, settings, errorlogger, Path::identify(tokens.getFiles()[0], false)); @@ -399,7 +399,8 @@ class TestPreprocessor : public TestFixture { ASSERT(settings.library.load("", library, false).errorcode == Library::ErrorCode::OK); std::vector files; simplecpp::OutputList outputList; - simplecpp::TokenList tokens(code,files,"test.c",&outputList); + simplecpp::DUI dui; + simplecpp::TokenList tokens(code,files,"test.c",dui,&outputList); Preprocessor preprocessor(tokens, settings, *this, Standards::Language::C); std::set configs = { "" }; std::set configDefines = { "__cplusplus" }; @@ -442,7 +443,7 @@ class TestPreprocessor : public TestFixture { "cpp\n" "#else\n" "c\n" - "#endif"; + "#endif\n"; { // Preprocess => actual result.. @@ -498,7 +499,7 @@ class TestPreprocessor : public TestFixture { { ScopedFile header("ab.h", "#error hello world!\n"); const auto settings = dinit(Settings, $.userDefines = "TEST"); - const char code[] = "#include \"ab.h\""; + const char code[] = "#include \"ab.h\"\n"; (void)getcodeforcfg(settings, *this, code, "TEST", "test.c"); ASSERT_EQUALS("[ab.h:1:2]: (error) #error hello world! [preprocessorErrorDirective]\n", errout_str()); } @@ -508,7 +509,7 @@ class TestPreprocessor : public TestFixture { ScopedFile header("ab.h", ""); const auto settings = dinit(Settings, $.userDefines = "TEST"); const char code[] = "#include \"ab.h\"\n" - "#error aaa"; + "#error aaa\n"; (void)getcodeforcfg(settings, *this, code, "TEST", "test.c"); ASSERT_EQUALS("[test.c:2:2]: (error) #error aaa [preprocessorErrorDirective]\n", errout_str()); } @@ -577,7 +578,7 @@ class TestPreprocessor : public TestFixture { "\n" "#ifndef C\n" "#error aa\n" - "#endif"; + "#endif\n"; ASSERT_EQUALS("A=A;B=B;C\nA=A;C\nC\n", getConfigsStr(filedata)); } @@ -618,7 +619,7 @@ class TestPreprocessor : public TestFixture { // Handling include guards.. const char filedata[] = "#include \"abc.h\"\n" "#ifdef ABC\n" - "#endif"; + "#endif\n"; ASSERT_EQUALS("\nABC=ABC\n", getConfigsStr(filedata)); } @@ -954,7 +955,7 @@ class TestPreprocessor : public TestFixture { void ticket_4922() { // #4922 const char code[] = "__asm__ \n" "{ int extern __value) 0; (double return (\"\" } extern\n" - "__typeof __finite (__finite) __finite __inline \"__GI___finite\");"; + "__typeof __finite (__finite) __finite __inline \"__GI___finite\");\n"; (void)getcode(settings0, *this, code); } @@ -1065,7 +1066,7 @@ class TestPreprocessor : public TestFixture { void macro_simple16() { // # 4703 const char filedata[] = "#define MACRO( A, B, C ) class A##B##C##Creator {};\n" - "MACRO( B\t, U , G )"; + "MACRO( B\t, U , G )\n"; ASSERT_EQUALS("\nclass BUGCreator { } ;", expandMacros(filedata, *this)); } @@ -1073,41 +1074,41 @@ class TestPreprocessor : public TestFixture { // It would probably be OK if the generated code was // "\n123+$123" since the first 123 comes from the source code const char filedata[] = "#define MACRO(A) A+123\n" - "MACRO(123)"; + "MACRO(123)\n"; ASSERT_EQUALS("\n123 + 123", expandMacros(filedata, *this)); } void macro_simple18() { // (1e-7) const char filedata1[] = "#define A (1e-7)\n" - "a=A;"; + "a=A;\n"; ASSERT_EQUALS("\na = ( 1e-7 ) ;", expandMacros(filedata1, *this)); const char filedata2[] = "#define A (1E-7)\n" - "a=A;"; + "a=A;\n"; ASSERT_EQUALS("\na = ( 1E-7 ) ;", expandMacros(filedata2, *this)); const char filedata3[] = "#define A (1e+7)\n" - "a=A;"; + "a=A;\n"; ASSERT_EQUALS("\na = ( 1e+7 ) ;", expandMacros(filedata3, *this)); const char filedata4[] = "#define A (1.e+7)\n" - "a=A;"; + "a=A;\n"; ASSERT_EQUALS("\na = ( 1.e+7 ) ;", expandMacros(filedata4, *this)); const char filedata5[] = "#define A (1.7f)\n" - "a=A;"; + "a=A;\n"; ASSERT_EQUALS("\na = ( 1.7f ) ;", expandMacros(filedata5, *this)); const char filedata6[] = "#define A (.1)\n" - "a=A;"; + "a=A;\n"; ASSERT_EQUALS("\na = ( .1 ) ;", expandMacros(filedata6, *this)); const char filedata7[] = "#define A (1.)\n" - "a=A;"; + "a=A;\n"; ASSERT_EQUALS("\na = ( 1. ) ;", expandMacros(filedata7, *this)); const char filedata8[] = "#define A (8.0E+007)\n" - "a=A;"; + "a=A;\n"; ASSERT_EQUALS("\na = ( 8.0E+007 ) ;", expandMacros(filedata8, *this)); } @@ -1279,8 +1280,8 @@ class TestPreprocessor : public TestFixture { void macro_NULL() { // See ticket #4482 - UB when passing NULL to variadic function - ASSERT_EQUALS("\n0", expandMacros("#define null 0\nnull", *this)); - TODO_ASSERT_EQUALS("\nNULL", "\n0", expandMacros("#define NULL 0\nNULL", *this)); // TODO: Let the tokenizer handle NULL? + ASSERT_EQUALS("\n0", expandMacros("#define null 0\nnull\n", *this)); + TODO_ASSERT_EQUALS("\nNULL\n", "\n0", expandMacros("#define NULL 0\nNULL\n", *this)); // TODO: Let the tokenizer handle NULL? } void string1() { @@ -1530,7 +1531,7 @@ class TestPreprocessor : public TestFixture { "#pragma asm foo\n" " mov r1, 11\n" "#pragma endasm bar\n" - "bbb"; + "bbb\n"; // Preprocess => actual result.. const std::map actual = getcode(settings0, *this, filedata); @@ -1544,7 +1545,7 @@ class TestPreprocessor : public TestFixture { const char filedata[] = "#pragma asm\n" " mov @w1, 11\n" "#pragma endasm ( temp=@w1 )\n" - "bbb"; + "bbb\n"; // Preprocess => actual result.. const std::map actual = getcode(settings0, *this, filedata); @@ -1666,7 +1667,7 @@ class TestPreprocessor : public TestFixture { "#else\n" "#define N 20\n" "#endif\n" - "N"; + "N\n"; // Preprocess => actual result.. const std::map actual = getcode(settings0, *this, filedata); @@ -1734,14 +1735,14 @@ class TestPreprocessor : public TestFixture { const char filedata[] = "#define A 0\n" "#if A\n" "FOO\n" - "#endif"; + "#endif\n"; ASSERT_EQUALS("", getcodeforcfg(settings0, *this, filedata,"","test.c")); } { const char filedata[] = "#define A 1\n" "#if A==1\n" "FOO\n" - "#endif"; + "#endif\n"; ASSERT_EQUALS("\n\nFOO", getcodeforcfg(settings0, *this, filedata,"","test.c")); } } @@ -1751,7 +1752,7 @@ class TestPreprocessor : public TestFixture { "#define B A\n" "#if (B==A) || (B==C)\n" "FOO\n" - "#endif"; + "#endif\n"; ASSERT_EQUALS("\n\n\nFOO", getcodeforcfg(settings0, *this, filedata,"","test.c")); } @@ -1759,7 +1760,7 @@ class TestPreprocessor : public TestFixture { const char filedata[] = "#define A 0\n" "#if (A==0)\n" "FOO\n" - "#endif"; + "#endif\n"; ASSERT_EQUALS("\n\nFOO", getcodeforcfg(settings0, *this, filedata,"","test.c")); } @@ -1767,7 +1768,7 @@ class TestPreprocessor : public TestFixture { const char filedata[] = "#define X +123\n" "#if X==123\n" "FOO\n" - "#endif"; + "#endif\n"; ASSERT_EQUALS("\n\nFOO", getcodeforcfg(settings0, *this, filedata,"","test.c")); } @@ -1777,7 +1778,7 @@ class TestPreprocessor : public TestFixture { "#define B (A & 0x00f0)\n" "#if B==0x0010\n" "FOO\n" - "#endif"; + "#endif\n"; ASSERT_EQUALS("\n\n\nFOO", getcodeforcfg(settings0, *this, filedata,"","test.c")); } { @@ -1786,14 +1787,14 @@ class TestPreprocessor : public TestFixture { "#define C (B & A)\n" "#if C==0x0010\n" "FOO\n" - "#endif"; + "#endif\n"; ASSERT_EQUALS("\n\n\n\nFOO", getcodeforcfg(settings0, *this, filedata,"","test.c")); } { const char filedata[] = "#define A (1+A)\n" // don't hang for recursive macros "#if A==1\n" "FOO\n" - "#endif"; + "#endif\n"; ASSERT_EQUALS("\n\nFOO", getcodeforcfg(settings0, *this, filedata,"","test.c")); } } @@ -1925,7 +1926,7 @@ class TestPreprocessor : public TestFixture { const char filedata[] = "#ifndef A\n" "#define A(x) x\n" "#endif\n" - "A(123);"; + "A(123);\n"; // Preprocess => actual result.. const std::map actual = getcode(settings0, *this, filedata); @@ -2111,7 +2112,7 @@ class TestPreprocessor : public TestFixture { } void remarkComment4() { - const char code[] = "//REMARK /"; + const char code[] = "//REMARK /\n"; const auto remarkComments = getRemarkComments(code, *this); ASSERT_EQUALS(0, remarkComments.size()); } @@ -2160,19 +2161,19 @@ class TestPreprocessor : public TestFixture { void predefine5() { // #3737, #5119 - automatically define __cplusplus // #3737... - const char code[] = "#ifdef __cplusplus\n123\n#endif"; + const char code[] = "#ifdef __cplusplus\n123\n#endif\n"; ASSERT_EQUALS("", getcodeforcfg(settings0, *this, code, "", "test.c")); ASSERT_EQUALS("\n123", getcodeforcfg(settings0, *this, code, "", "test.cpp")); } void predefine6() { // automatically define __STDC_VERSION__ - const char code[] = "#ifdef __STDC_VERSION__\n123\n#endif"; + const char code[] = "#ifdef __STDC_VERSION__\n123\n#endif\n"; ASSERT_EQUALS("\n123", getcodeforcfg(settings0, *this, code, "", "test.c")); ASSERT_EQUALS("", getcodeforcfg(settings0, *this, code, "", "test.cpp")); } void strictAnsi() { - const char code[] = "#ifdef __STRICT_ANSI__\n123\n#endif"; + const char code[] = "#ifdef __STRICT_ANSI__\n123\n#endif\n"; Settings settings; settings.standards.setStd("gnu99"); @@ -2324,7 +2325,7 @@ class TestPreprocessor : public TestFixture { "#define bar foo\n" "#define baz bar+0\n" "#if 0\n" - "#endif"; + "#endif\n"; ASSERT_EQUALS("\n", getConfigsStr(filedata)); } @@ -2733,27 +2734,27 @@ class TestPreprocessor : public TestFixture { void getConfigsInvalid() { // #14732 { - const char filedata[] = "#if<"; + const char filedata[] = "#if<\n"; ASSERT_EQUALS("\n", getConfigsStr(filedata)); } { - const char filedata[] = "#if>"; + const char filedata[] = "#if>\n"; ASSERT_EQUALS("\n", getConfigsStr(filedata)); } { - const char filedata[] = "#if=="; + const char filedata[] = "#if==\n"; ASSERT_EQUALS("\n", getConfigsStr(filedata)); } { - const char filedata[] = "#if<="; + const char filedata[] = "#if<=\n"; ASSERT_EQUALS("\n", getConfigsStr(filedata)); } { - const char filedata[] = "#if>="; + const char filedata[] = "#if>=\n"; ASSERT_EQUALS("\n", getConfigsStr(filedata)); } { - const char filedata[] = "#if!"; + const char filedata[] = "#if!\n"; ASSERT_EQUALS("\n", getConfigsStr(filedata)); } } @@ -2764,7 +2765,7 @@ class TestPreprocessor : public TestFixture { "#elif sizeof(unsigned short) == 4\n" "Fred & Wilma\n" "#else\n" - "#endif"; + "#endif\n"; const std::map actual = getcode(settings0, *this, code); ASSERT_EQUALS("\nFred & Wilma", actual.at("")); @@ -2792,7 +2793,7 @@ class TestPreprocessor : public TestFixture { void garbage() { const char filedata[] = "V\n" "#define X b #endif #line 0 \"x\" ;\n" - "#if ! defined ( Y ) #endif"; + "#if ! defined ( Y ) #endif\n"; // Preprocess => don't crash.. (void)getcode(settings0, *this, filedata); @@ -2816,7 +2817,7 @@ class TestPreprocessor : public TestFixture { ScopedFile header("header.h", ""); - const char code[] = "#include \"header.h\""; + const char code[] = "#include \"header.h\"\n"; (void)getcodeforcfg(settings, *this, code, "", "test.c"); ASSERT_EQUALS("", errout_str()); @@ -2831,7 +2832,7 @@ class TestPreprocessor : public TestFixture { ); setTemplateFormat("simple"); - const char code[] = "#include \"header.h\""; + const char code[] = "#include \"header.h\"\n"; (void)getcodeforcfg(settings, *this, code, "", "test.c"); ASSERT_EQUALS("test.c:1:2: information: Include file: \"header.h\" not found. [missingInclude]\n", errout_str()); @@ -2848,7 +2849,7 @@ class TestPreprocessor : public TestFixture { ScopedFile header("header.h", "", "inc"); - const char code[] = "#include \"header.h\""; + const char code[] = "#include \"header.h\"\n"; (void)getcodeforcfg(settings, *this, code, "", "test.c"); ASSERT_EQUALS("test.c:1:2: information: Include file: \"header.h\" not found. [missingInclude]\n", errout_str()); @@ -2866,7 +2867,7 @@ class TestPreprocessor : public TestFixture { ScopedFile header("header.h", "", "inc"); - const char code[] = "#include \"inc/header.h\""; + const char code[] = "#include \"inc/header.h\"\n"; (void)getcodeforcfg(settings, *this, code, "", "test.c"); ASSERT_EQUALS("", errout_str()); @@ -2884,7 +2885,7 @@ class TestPreprocessor : public TestFixture { ScopedFile header("header.h", "", Path::getCurrentPath()); - std::string code("#include \"" + header.path() + "\""); + std::string code("#include \"" + header.path() + "\"\n"); (void)getcodeforcfg(settings, *this, code.data(), code.size(), "", "test.c"); ASSERT_EQUALS("", errout_str()); @@ -2901,7 +2902,7 @@ class TestPreprocessor : public TestFixture { const std::string header = Path::join(Path::getCurrentPath(), "header.h"); - std::string code("#include \"" + header + "\""); + std::string code("#include \"" + header + "\"\n"); (void)getcodeforcfg(settings, *this, code.data(), code.size(), "", "test.c"); ASSERT_EQUALS("test.c:1:2: information: Include file: \"" + header + "\" not found. [missingInclude]\n", errout_str()); @@ -2918,7 +2919,7 @@ class TestPreprocessor : public TestFixture { ScopedFile header("header.h", ""); - const char code[] = "#include "; + const char code[] = "#include \n"; (void)getcodeforcfg(settings, *this, code, "", "test.c"); ASSERT_EQUALS("test.c:1:2: information: Include file: not found. Please note: Standard library headers do not need to be provided to get proper results. [missingIncludeSystem]\n", errout_str()); @@ -2933,7 +2934,7 @@ class TestPreprocessor : public TestFixture { ); setTemplateFormat("simple"); - const char code[] = "#include "; + const char code[] = "#include \n"; (void)getcodeforcfg(settings, *this, code, "", "test.c"); ASSERT_EQUALS("test.c:1:2: information: Include file: not found. Please note: Standard library headers do not need to be provided to get proper results. [missingIncludeSystem]\n", errout_str()); @@ -2951,7 +2952,7 @@ class TestPreprocessor : public TestFixture { ScopedFile header("header.h", "", "system"); - const char code[] = "#include "; + const char code[] = "#include \n"; (void)getcodeforcfg(settings, *this, code, "", "test.c"); ASSERT_EQUALS("", errout_str()); @@ -2969,7 +2970,7 @@ class TestPreprocessor : public TestFixture { ScopedFile header("header.h", "", Path::getCurrentPath()); - std::string code("#include <" + header.path() + ">"); + std::string code("#include <" + header.path() + ">\n"); (void)getcodeforcfg(settings, *this, code.data(), code.size(), "", "test.c"); ASSERT_EQUALS("", errout_str()); @@ -2986,7 +2987,7 @@ class TestPreprocessor : public TestFixture { const std::string header = Path::join(Path::getCurrentPath(), "header.h"); - std::string code("#include <" + header + ">"); + std::string code("#include <" + header + ">\n"); (void)getcodeforcfg(settings, *this, code.data(), code.size(), "", "test.c"); ASSERT_EQUALS("test.c:1:2: information: Include file: <" + header + "> not found. Please note: Standard library headers do not need to be provided to get proper results. [missingIncludeSystem]\n", errout_str()); @@ -3008,7 +3009,7 @@ class TestPreprocessor : public TestFixture { const char code[] = "#include \"missing.h\"\n" "#include \n" "#include \n" - "#include \"header2.h\""; + "#include \"header2.h\"\n"; (void)getcodeforcfg(settings, *this, code, "", "test.c"); ASSERT_EQUALS("test.c:1:2: information: Include file: \"missing.h\" not found. [missingInclude]\n" @@ -3068,8 +3069,8 @@ class TestPreprocessor : public TestFixture { std::vector files; simplecpp::TokenList tokens(code, files, "test.c"); - ScopedFile header1("header1.h", "1"); - ScopedFile header2("header2.h", "2"); + ScopedFile header1("header1.h", "1\n"); + ScopedFile header2("header2.h", "2\n"); Settings settings; Preprocessor preprocessor(tokens, settings, *this, Standards::Language::CPP); @@ -3087,7 +3088,7 @@ class TestPreprocessor : public TestFixture { } void hasInclude() { - const char code[] = "#if __has_include()\n123\n#endif"; + const char code[] = "#if __has_include()\n123\n#endif\n"; Settings settings; settings.standards.setStd("c++11"); @@ -3107,7 +3108,7 @@ class TestPreprocessor : public TestFixture { // #11928 / #10045 const char code[] = "void f(long l) {\n" " if (l > INT_MAX) {}\n" - "}"; + "}\n"; const std::string actual = getcodeforcfg(settings0, *this, code, "", "test.c"); ASSERT_EQUALS("void f ( long l ) {\n" "if ( l > $2147483647 ) { }\n" @@ -3116,9 +3117,9 @@ class TestPreprocessor : public TestFixture { void hashCalculation() { // #12383 - const char code[] = "int a;"; - const char code2[] = "int a;"; // extra space - const char code3[] = "\n\nint a;"; // extra new line + const char code[] = "int a;\n"; + const char code2[] = "int a;\n"; // extra space + const char code3[] = "\n\nint a;\n"; // extra new line ASSERT_EQUALS(getHash(code), getHash(code)); ASSERT_EQUALS(getHash(code2), getHash(code2)); @@ -3130,7 +3131,7 @@ class TestPreprocessor : public TestFixture { void standard() { - const char code[] = "int a;"; + const char code[] = "int a;\n"; // TODO: this bypasses the standard determined from the settings - the parameter should not be exposed simplecpp::DUI dui; @@ -3171,7 +3172,7 @@ class TestPreprocessor : public TestFixture { std::vector files; TokenList tokenlist{settingsDefault, Standards::Language::CPP}; // TODO: can this happen from application code? if yes we need to turn it into a proper error - ASSERT_THROW_EQUALS(preprocess(code, files, "test.cpp", tokenlist, dui), std::runtime_error, "unexpected simplecpp::Output type 9"); + ASSERT_THROW_EQUALS(preprocess(code, files, "test.cpp", tokenlist, dui), std::runtime_error, "unexpected simplecpp::Output type 12"); ASSERT(!tokenlist.front()); // nothing is tokenized when an unknown standard is provided } } @@ -3181,8 +3182,8 @@ class TestPreprocessor : public TestFixture { const char inc[] = "class A {\n" "public:\n" " void f() {}\n" - "};"; - const char code[] = R"(#include "test.h")"; + "};\n"; + const char code[] = "#include \"test.h\"\n"; ScopedFile header("test.h", inc); const std::string processed = getcodeforcfg(settingsDefault, *this, code, "", "test.cpp"); ASSERT_EQUALS( @@ -3197,7 +3198,7 @@ class TestPreprocessor : public TestFixture { void pragmaAsm() { - const char code[] = "#pragma asm"; + const char code[] = "#pragma asm\n"; ASSERT_THROW_INTERNAL(getcodeforcfg(settingsDefault, *this, code, "", "test.cpp"), InternalError::SYNTAX); } }; diff --git a/test/testprogrammemory.cpp b/test/testprogrammemory.cpp index 688efa0075b..c37431de608 100644 --- a/test/testprogrammemory.cpp +++ b/test/testprogrammemory.cpp @@ -39,7 +39,7 @@ class TestProgramMemory : public TestFixture { } void copyOnWrite() const { - SimpleTokenList tokenlist("1+1;"); + SimpleTokenList tokenlist("1+1;\n"); Token* tok = tokenlist.front(); const nonneg int id = 123; tok->exprId(id); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 6960b791426..812ba29bc21 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -371,7 +371,7 @@ class TestSimplifyTemplate : public TestFixture { void template1() { const char code[] = "template T f(T val) { T a; }\n" - "f(10);"; + "f(10);\n"; const char expected[] = "int f ( int val ) ; " "f ( 10 ) ; " @@ -382,7 +382,7 @@ class TestSimplifyTemplate : public TestFixture { void template2() { const char code[] = "template class Fred { T a; };\n" - "Fred fred;"; + "Fred fred;\n"; const char expected[] = "class Fred ; " "Fred fred ; " @@ -393,7 +393,7 @@ class TestSimplifyTemplate : public TestFixture { void template3() { const char code[] = "template class Fred { T data[sz]; };\n" - "Fred fred;"; + "Fred fred;\n"; const char expected[] = "class Fred ; " "Fred fred ; " @@ -404,7 +404,7 @@ class TestSimplifyTemplate : public TestFixture { void template4() { const char code[] = "template class Fred { Fred(); };\n" - "Fred fred;"; + "Fred fred;\n"; const char expected[] = "class Fred ; " "Fred fred ; " @@ -416,7 +416,7 @@ class TestSimplifyTemplate : public TestFixture { void template5() { const char code[] = "template class Fred { };\n" "template Fred::Fred() { }\n" - "Fred fred;"; + "Fred fred;\n"; const char expected[] = "class Fred ; " "Fred fred ; " @@ -429,7 +429,7 @@ class TestSimplifyTemplate : public TestFixture { void template6() { const char code[] = "template class Fred { };\n" "Fred fred1;\n" - "Fred fred2;"; + "Fred fred2;\n"; const char expected[] = "class Fred ; " "Fred fred1 ; " @@ -530,7 +530,7 @@ class TestSimplifyTemplate : public TestFixture { "template < typename T > class A { void f ( ) { B < T > a ; a = B < T > :: g ( ) ; T b ; b = 0 ; if ( b ) { b = 0 ; } } } ; " "template < typename T > B < T > h ( ) { return B < T > ( ) ; }", tok(code)); - ASSERT_EQUALS("class A { template < typename T > int foo ( T d ) ; } ;", tok("class A{ template int foo(T d);};")); + ASSERT_EQUALS("class A { template < typename T > int foo ( T d ) ; } ;", tok("class A{ template int foo(T d);};\n")); } void template9() { @@ -635,7 +635,7 @@ class TestSimplifyTemplate : public TestFixture { " y(AA::create(new CC(AA(), 0)))\n" " {}\n" "\n" - "int yy[AA::size()];"; + "int yy[AA::size()];\n"; const char expected[] = "class BB { } ; " "class AA ; " "class AA ; " @@ -711,7 +711,7 @@ class TestSimplifyTemplate : public TestFixture { " vec(const vec& v) {}\n" // <- never used don't instantiate "};\n" "\n" - "vec<4> v;"; + "vec<4> v;\n"; const char expected2[] = "struct vec<4> ; " "vec<4> v ; " "struct vec<4> { " @@ -769,7 +769,7 @@ class TestSimplifyTemplate : public TestFixture { void template18() { const char code[] = "template class foo { T a; };\n" - "foo *f;"; + "foo *f;\n"; const char expected[] = "class foo ; " "foo * f ; " @@ -814,7 +814,7 @@ class TestSimplifyTemplate : public TestFixture { void template21() { { const char code[] = "template struct Fred { T a; };\n" - "Fred fred;"; + "Fred fred;\n"; const char expected[] = "struct Fred ; " "Fred fred ; " @@ -825,7 +825,7 @@ class TestSimplifyTemplate : public TestFixture { { const char code[] = "template struct Fred { T data[sz]; };\n" - "Fred fred;"; + "Fred fred;\n"; const char expected[] = "struct Fred ; " "Fred fred ; " @@ -836,7 +836,7 @@ class TestSimplifyTemplate : public TestFixture { { const char code[] = "template struct Fred { Fred(); };\n" - "Fred fred;"; + "Fred fred;\n"; const char expected[] = "struct Fred ; " "Fred fred ; " @@ -848,7 +848,7 @@ class TestSimplifyTemplate : public TestFixture { { const char code[] = "template struct Fred { };\n" "Fred fred1;\n" - "Fred fred2;"; + "Fred fred2;\n"; const char expected[] = "struct Fred ; " "Fred fred1 ; " @@ -861,7 +861,7 @@ class TestSimplifyTemplate : public TestFixture { void template22() { const char code[] = "template struct Fred { T a; };\n" - "Fred fred;"; + "Fred fred;\n"; const char expected[] = "struct Fred ; " "Fred fred ; " @@ -874,7 +874,7 @@ class TestSimplifyTemplate : public TestFixture { const char code[] = "template void foo() { }\n" "void bar() {\n" " std::cout << (foo());\n" - "}"; + "}\n"; const char expected[] = "void foo ( ) ; " "void bar ( ) {" @@ -895,7 +895,7 @@ class TestSimplifyTemplate : public TestFixture { "template class bitset: B\n" "{};\n" "\n" - "bitset<1> z;"; + "bitset<1> z;\n"; const char expected[] = "struct B<4> ; " "class bitset<1> ; " "bitset<1> z ; " @@ -913,7 +913,7 @@ class TestSimplifyTemplate : public TestFixture { "template class bitset: B<((sizeof(int)) ? : 1)>\n" "{};\n" "\n" - "bitset<1> z;"; + "bitset<1> z;\n"; const char expected[] = "struct B<4> ; " "class bitset<1> ; " "bitset<1> z ; " @@ -936,7 +936,7 @@ class TestSimplifyTemplate : public TestFixture { void template27() { // #3350 - template inside macro call - const char code[] = "X(template class Fred);"; + const char code[] = "X(template class Fred);\n"; ASSERT_THROW_INTERNAL(tok(code), SYNTAX); } @@ -953,19 +953,19 @@ class TestSimplifyTemplate : public TestFixture { void template30() { // #3529 - template < template < .. - const char code[] = "template class A, class B> void f(){}"; + const char code[] = "template class A, class B> void f(){}\n"; ASSERT_EQUALS("template < template < class > class A , class B > void f ( ) { }", tok(code)); } void template31() { // #4010 - template reference type - const char code[] = "template struct A{}; A a;"; + const char code[] = "template struct A{}; A a;\n"; ASSERT_EQUALS("struct A ; " "A a ; " "struct A { } ;", tok(code)); // #7409 - rvalue - const char code2[] = "template struct A{}; A a;"; + const char code2[] = "template struct A{}; A a;\n"; ASSERT_EQUALS("struct A ; " "A a ; " "struct A { } ;", tok(code2)); @@ -995,7 +995,7 @@ class TestSimplifyTemplate : public TestFixture { const char code[] = "template struct A { };\n" "template struct B { };\n" "template struct C { A > > ab; };\n" - "C c;"; + "C c;\n"; ASSERT_EQUALS("struct A>> ; " "struct B> ; " "struct C ; " @@ -1010,7 +1010,7 @@ class TestSimplifyTemplate : public TestFixture { const char code[] = "struct A { };\n" "template struct B { };\n" "template struct C { };\n" - "C< B > c;"; + "C< B > c;\n"; ASSERT_EQUALS("struct A { } ; " "template < class T > struct B { } ; " // <- redundant.. but nevermind "struct C> ; " @@ -1025,13 +1025,13 @@ class TestSimplifyTemplate : public TestFixture { const char code[] = "namespace abc {\n" "template struct X { void f(X &x) {} };\n" "}\n" - "template <> int X::Y(0);"; + "template <> int X::Y(0);\n"; (void)tok(code); } void template35() { // #4074 - "A<'x'> a;" is not recognized as template instantiation const char code[] = "template class A {};\n" - "A <'x'> a;"; + "A <'x'> a;\n"; ASSERT_EQUALS("class A<'x'> ; " "A<'x'> a ; " "class A<'x'> { } ;", tok(code)); @@ -1040,7 +1040,7 @@ class TestSimplifyTemplate : public TestFixture { void template36() { // #4310 - Passing unknown template instantiation as template argument const char code[] = "template struct X { T t; };\n" "template struct Y { Foo < X< Bar > > _foo; };\n" // <- Bar is unknown - "Y bar;"; + "Y bar;\n"; ASSERT_EQUALS("struct X> ; " "struct Y ; " "Y bar ; " @@ -1054,7 +1054,7 @@ class TestSimplifyTemplate : public TestFixture { const char code[] = "class A { };\n" "template class B {};\n" "B b1;\n" - "B b2;"; + "B b2;\n"; ASSERT_EQUALS("class A { } ; class B ; B b1 ; B b2 ; class B { } ;", tok(code)); } @@ -1062,7 +1062,7 @@ class TestSimplifyTemplate : public TestFixture { const char code[] = "struct A { };\n" "template class B {};\n" "B b1;\n" - "B b2;"; + "B b2;\n"; ASSERT_EQUALS("struct A { } ; class B ; B b1 ; B b2 ; class B { } ;", tok(code)); } @@ -1070,7 +1070,7 @@ class TestSimplifyTemplate : public TestFixture { const char code[] = "enum A { };\n" "template class B {};\n" "B b1;\n" - "B b2;"; + "B b2;\n"; ASSERT_EQUALS("enum A { } ; class B ; B b1 ; B b2 ; class B { } ;", tok(code)); } @@ -1078,7 +1078,7 @@ class TestSimplifyTemplate : public TestFixture { void template_unhandled() { // An unhandled template usage should not be simplified.. - ASSERT_EQUALS("x < int > ( ) ;", tok("x();")); + ASSERT_EQUALS("x < int > ( ) ;", tok("x();\n")); } void template38() { // #4832 - Crash on C++11 right angle brackets @@ -1112,21 +1112,21 @@ class TestSimplifyTemplate : public TestFixture { } void template39() { // #4742 - Used to freeze in 1.60 - const char code[] = "template struct vector {" - " operator T() const;" - "};" - "void f() {" - " vector> v;" - " const vector vi = static_cast>(v);" - "}"; + const char code[] = "template struct vector {\n" + " operator T() const;\n" + "};\n" + "void f() {\n" + " vector> v;\n" + " const vector vi = static_cast>(v);\n" + "}\n"; (void)tok(code); } void template40() { // #5055 - false negatives when there is template specialization outside struct - const char code[] = "struct A {" - " template struct X { T t; };" - "};" - "template<> struct A::X { int *t; };"; + const char code[] = "struct A {\n" + " template struct X { T t; };\n" + "};\n" + "template<> struct A::X { int *t; };\n"; const char expected[] = "struct A { " "struct X ; " "template < typename T > struct X { T t ; } ; " @@ -1137,13 +1137,13 @@ class TestSimplifyTemplate : public TestFixture { void template41() { // #4710 - const in template instantiation not handled perfectly const char code1[] = "template struct X { };\n" - "void f(const X x) { }"; + "void f(const X x) { }\n"; ASSERT_EQUALS("struct X ; " "void f ( const X x ) { } " "struct X { } ;", tok(code1)); const char code2[] = "template T f(T t) { return t; }\n" - "int x() { return f(123); }"; + "int x() { return f(123); }\n"; ASSERT_EQUALS("int f ( int t ) ; " "int x ( ) { return f ( 123 ) ; } " "int f ( int t ) { return t ; }", tok(code2)); @@ -1157,7 +1157,7 @@ class TestSimplifyTemplate : public TestFixture { " }() + ^ {\n" " return sizeof...(args);\n" " }();\n" - "}"; + "}\n"; ASSERT_THROW_INTERNAL(tok(code), SYNTAX); } @@ -1175,7 +1175,7 @@ class TestSimplifyTemplate : public TestFixture { "int main(void) {\n" " C ca;\n" " return 0;\n" - "}"; + "}\n"; const char expected[] = "struct E ; " "struct C> ; " "struct C ; " @@ -1214,14 +1214,14 @@ class TestSimplifyTemplate : public TestFixture { } void template44() { // #5297 - const char code[] = "template struct StackContainer {" - " void foo(int i) {" - " if (0 >= 1 && i<0) {}" - " }" - "};" - "template class ZContainer : public StackContainer {};" - "struct FGSTensor {};" - "class FoldedZContainer : public ZContainer {};"; + const char code[] = "template struct StackContainer {\n" + " void foo(int i) {\n" + " if (0 >= 1 && i<0) {}\n" + " }\n" + "};\n" + "template class ZContainer : public StackContainer {};\n" + "struct FGSTensor {};\n" + "class FoldedZContainer : public ZContainer {};\n"; const char expected[] = "struct StackContainer ; " "class ZContainer ; " "struct FGSTensor { } ; " @@ -1236,14 +1236,14 @@ class TestSimplifyTemplate : public TestFixture { } void template45() { // #5814 - const char code[] = "namespace Constants { const int fourtytwo = 42; } " - "template struct TypeMath { " - " static const int mult = sizeof(T) * U; " - "}; " - "template struct FOO { " - " enum { value = TypeMath::mult }; " - "}; " - "FOO foo;"; + const char code[] = "namespace Constants { const int fourtytwo = 42; }\n" + "template struct TypeMath {\n" + " static const int mult = sizeof(T) * U;\n" + "};\n" + "template struct FOO {\n" + " enum { value = TypeMath::mult };\n" + "};\n" + "FOO foo;\n"; const char expected[] = "namespace Constants { const int fourtytwo = 42 ; } " "struct TypeMath ; " "struct FOO ; " @@ -1259,32 +1259,32 @@ class TestSimplifyTemplate : public TestFixture { } void template46() { // #5816 - ASSERT_NO_THROW(tok("template struct A { static const int value = 0; }; " - "template struct B { " - " enum { value = A::value }; " - "};")); + ASSERT_NO_THROW(tok("template struct A { static const int value = 0; };\n" + "template struct B {\n" + " enum { value = A::value };\n" + "};\n")); ASSERT_EQUALS("", errout_str()); - ASSERT_NO_THROW(tok("template struct A {}; " - "enum { e = sizeof(A) }; " - "template struct B {};")); + ASSERT_NO_THROW(tok("template struct A {};\n" + "enum { e = sizeof(A) };\n" + "template struct B {};\n")); ASSERT_EQUALS("", errout_str()); - ASSERT_NO_THROW(tok("template struct A { static const int value = 0; }; " - "template struct B { typedef int type; }; " - "template struct C { " - " enum { value = A::type, int>::value }; " - "};")); + ASSERT_NO_THROW(tok("template struct A { static const int value = 0; };\n" + "template struct B { typedef int type; };\n" + "template struct C {\n" + " enum { value = A::type, int>::value };\n" + "};\n")); ASSERT_EQUALS("", errout_str()); } void template47() { // #6023 - ASSERT_NO_THROW(tok("template > class C1 {}; " - "class C2 : public C1 {};")); + ASSERT_NO_THROW(tok("template > class C1 {};\n" + "class C2 : public C1 {};\n")); ASSERT_EQUALS("", errout_str()); } void template48() { // #6134 (hang) - (void)tok("template int f( { } ); " - "int foo = f<1>(0);"); + (void)tok("template int f( { } );\n" + "int foo = f<1>(0);\n"); ASSERT_EQUALS("", errout_str()); } @@ -1326,17 +1326,17 @@ class TestSimplifyTemplate : public TestFixture { } void template52() { // #6437 - const char code[] = "template int sum() { " - " return value + sum(); " - "} " - "template int calculate_value() { " - " if (x != y) { " - " return sum(); " - " } else { " - " return 0; " - " } " - "} " - "int value = calculate_value<1,1>();"; + const char code[] = "template int sum() {\n" + " return value + sum();\n" + "}\n" + "template int calculate_value() {\n" + " if (x != y) {\n" + " return sum();\n" + " } else {\n" + " return 0;\n" + " }\n" + "}\n" + "int value = calculate_value<1,1>();\n"; const char expected[] = "int sum<0> ( ) ; " "int calculate_value<1,1> ( ) ; " "int value ; value = calculate_value<1,1> ( ) ; " @@ -1354,13 +1354,13 @@ class TestSimplifyTemplate : public TestFixture { } void template53() { // #4335 - const char code[] = "template struct Factorial { " - " enum { value = N * Factorial::value }; " - "};" - "template <> struct Factorial<0> { " - " enum { value = 1 }; " - "};" - "const int x = Factorial<4>::value;"; + const char code[] = "template struct Factorial {\n" + " enum { value = N * Factorial::value };\n" + "};\n" + "template <> struct Factorial<0> {\n" + " enum { value = 1 };\n" + "};\n" + "const int x = Factorial<4>::value;\n"; const char expected[] = "struct Factorial<0> ; " "struct Factorial<4> ; " "struct Factorial<3> ; " @@ -1387,12 +1387,12 @@ class TestSimplifyTemplate : public TestFixture { } void template54() { // #6587 (use-after-free) - (void)tok("template _Tp* fn(); " - "template struct A { " - " template ())> " - " struct B { }; " - "}; " - "A a;"); + (void)tok("template _Tp* fn();\n" + "template struct A {\n" + " template ())>\n" + " struct B { };\n" + "};\n" + "A a;\n"); } void template55() { // #6604 @@ -1406,7 +1406,7 @@ class TestSimplifyTemplate : public TestFixture { "{\n" " friend struct ConstCastHelper, T>;\n" " AtSmartPtr(const AtSmartPtr& r);\n" - "};")); + "};\n")); // Similar problem can also happen with ... ASSERT_EQUALS( @@ -1426,16 +1426,16 @@ class TestSimplifyTemplate : public TestFixture { " (A*)(p);\n" " }\n" "};\n" - "A a(0);")); + "A a(0);\n")); } void template56() { // #7117 - const char code[] = "template struct Foo { " - " std::array mfoo; " - "}; " - "void foo() { " - " Foo myFoo; " - "}"; + const char code[] = "template struct Foo {\n" + " std::array mfoo;\n" + "};\n" + "void foo() {\n" + " Foo myFoo;\n" + "}\n"; const char expected[] = "struct Foo ; " "void foo ( ) { " "Foo myFoo ; " @@ -1448,7 +1448,7 @@ class TestSimplifyTemplate : public TestFixture { void template57() { // #7891 const char code[] = "template struct Test { Test(T); };\n" - "Test test( 0 );"; + "Test test( 0 );\n"; const char exp[] = "struct Test ; " "Test test ( 0 ) ; " "struct Test { Test ( unsigned long ) ; } ;"; @@ -1462,7 +1462,7 @@ class TestSimplifyTemplate : public TestFixture { "}\n" "void foo() {\n" " TestArithmetic();\n" - "}"; + "}\n"; const char exp[] = "void TestArithmetic ( ) ; " "void foo ( ) {" " TestArithmetic ( ) ; " @@ -1488,7 +1488,7 @@ class TestSimplifyTemplate : public TestFixture { "}\n" "int main () {\n" " return diagonalGroupTest<4>();\n" - "}"; + "}\n"; const char exp[] = "struct Factorial<0> ; " "struct Factorial<4> ; " "struct Factorial<3> ; " @@ -1510,7 +1510,7 @@ class TestSimplifyTemplate : public TestFixture { "template void f() {}\n" "template void h() { f::type(0)>(); }\n" "\n" - "void j() { h(); }"; + "void j() { h(); }\n"; const char exp[] = "struct S ; " "void f::type(0)> ( ) ; " "void h ( ) ; " @@ -1533,7 +1533,7 @@ class TestSimplifyTemplate : public TestFixture { " void f1(Bar x) {}\n" " Foo> f2() { }\n" "};\n" - "Bar c;"; + "Bar c;\n"; const char exp[] = "struct Foo> ; " "struct Bar ; " "Bar c ; " @@ -1550,7 +1550,7 @@ class TestSimplifyTemplate : public TestFixture { "template void f() { x = y ? C1::allocate(1) : 0; }\n" "template class C3 {};\n" "template C3::C3(const C3 &v) { C1 c1; }\n" - "C3 c3;"; + "C3 c3;\n"; const char exp[] = "struct C1 ; " "template < class T > void f ( ) { x = y ? ( C1 < int > :: allocate ( 1 ) ) : 0 ; } " "class C3 ; " @@ -1562,8 +1562,8 @@ class TestSimplifyTemplate : public TestFixture { } void template63() { // #8576 - const char code[] = "template struct TestClass { T m_hi; };" - "TestClass> objTest3;"; + const char code[] = "template struct TestClass { T m_hi; };\n" + "TestClass> objTest3;\n"; const char exp[] = "struct TestClass> ; " "TestClass> objTest3 ; " "struct TestClass> { std :: auto_ptr < v > m_hi ; } ;"; @@ -1584,7 +1584,7 @@ class TestSimplifyTemplate : public TestFixture { " t_func<0>();\n" " t_func<1>();\n" "}\n" - "};"; + "};\n"; const char exp[] = "bool foo ( ) ; " "struct A { " "void t_func<0> ( ) ; " @@ -1622,7 +1622,7 @@ class TestSimplifyTemplate : public TestFixture { "int main() {\n" " AssociationDAGlobalGraphObserver grObs;\n" " return 1;\n" - "}"; + "}\n"; const char exp[] = "namespace bpp " "{ " "class AssociationDAGraphImplObserver ; " @@ -1642,7 +1642,7 @@ class TestSimplifyTemplate : public TestFixture { " const int ** foo();\n" "};\n" "template const int ** Fred::foo() { return nullptr; }\n" - "Fred fred;"; + "Fred fred;\n"; const char exp[] = "struct Fred ; " "Fred fred ; " "struct Fred { " @@ -1665,7 +1665,7 @@ class TestSimplifyTemplate : public TestFixture { "template Container::Container(const Container & x) { nElements = x.nElements; c = x.c; }\n" "template Container & Container::operator = (const Container & x) { mElements = x.mElements; c = x.c; return *this; }\n" "template Container::~Container() {}\n" - "Container intContainer;"; + "Container intContainer;\n"; const char expected[] = "struct Container ; " "Container intContainer ; " @@ -1690,7 +1690,7 @@ class TestSimplifyTemplate : public TestFixture { " char dummy[sizeof(T)];\n" " T value;\n" "};\n" - "Fred fred;"; + "Fred fred;\n"; const char exp[] = "union Fred ; " "Fred fred ; " "union Fred { " @@ -1705,7 +1705,7 @@ class TestSimplifyTemplate : public TestFixture { " int test;\n" " template T lookup() { return test; }\n" " int Fun() { return lookup(); }\n" - "};"; + "};\n"; const char exp[] = "class Test { " "int test ; " "int lookup ( ) ; " @@ -1723,7 +1723,7 @@ class TestSimplifyTemplate : public TestFixture { "template\n" "class Bar : private Bar {\n" " void foo() { }\n" - "};"; + "};\n"; const char exp[] = "template < typename T , typename V , int KeySize = 0 > class Bar ; " "class Bar ; " "class Bar { " @@ -1755,7 +1755,7 @@ class TestSimplifyTemplate : public TestFixture { " return f1(pInterface, interface_type::static_type());\n" "}\n" "\n" - "Reference< class XPropertyList > dostuff();"; + "Reference< class XPropertyList > dostuff();\n"; const char exp[] = "int f1 ( int * pInterface , int x ) { return 0 ; } " "class Reference ; " "Reference dostuff ( ) ; " @@ -1768,7 +1768,7 @@ class TestSimplifyTemplate : public TestFixture { const char code[] = "template class Tokenizer;\n" "const Tokenizer *tokenizer() const;\n" "template \n" - "Tokenizer::Tokenizer() { }"; + "Tokenizer::Tokenizer() { }\n"; const char exp[] = "template < typename N , typename P > class Tokenizer ; " "const Tokenizer < Node , Path > * tokenizer ( ) const ; " "template < typename N , typename P > " @@ -1780,7 +1780,7 @@ class TestSimplifyTemplate : public TestFixture { const char code[] = "template\n" "void keep_range(T& value, const T mini, const T maxi){}\n" "template void keep_range(float& v, const float l, const float u);\n" - "template void keep_range(int& v, const int l, const int u);"; + "template void keep_range(int& v, const int l, const int u);\n"; const char exp[] = "void keep_range ( float & value , const float mini , const float maxi ) ; " "void keep_range ( int & value , const int mini , const int maxi ) ; " "void keep_range ( float & value , const float mini , const float maxi ) { } " @@ -1793,7 +1793,7 @@ class TestSimplifyTemplate : public TestFixture { "class PushBackStreamBuf {\n" "public:\n" " void pushBack(const BTlist &vec);\n" - "};"; + "};\n"; const char exp[] = "class BTlist ; " "class PushBackStreamBuf { " "public: " @@ -1806,7 +1806,7 @@ class TestSimplifyTemplate : public TestFixture { void template75() { const char code[] = "template\n" "T foo(T& value){ return value; }\n" - "template std::vector> foo>>(std::vector>& v);"; + "template std::vector> foo>>(std::vector>& v);\n"; const char exp[] = "std :: vector < std :: vector < int > > foo>> ( std :: vector < std :: vector < int > > & value ) ; " "std :: vector < std :: vector < int > > foo>> ( std :: vector < std :: vector < int > > & value ) { return value ; }"; ASSERT_EQUALS(exp, tok(code)); @@ -1836,7 +1836,7 @@ class TestSimplifyTemplate : public TestFixture { "int main() {\n" " std::cout << is_void::value << std::endl;\n" " std::cout << is_void::value << std::endl;\n" - "}"; + "}\n"; const char exp[] = "struct is_void ; " "struct is_void ; " "struct is_void : std :: true_type { } ; " @@ -1851,7 +1851,7 @@ class TestSimplifyTemplate : public TestFixture { void template78() { const char code[] = "template \n" "struct Base { };\n" - "struct S : Base ::Type { };"; + "struct S : Base ::Type { };\n"; const char exp[] = "struct Base ; " "struct S : Base :: Type { } ; " "struct Base { } ;"; @@ -1869,7 +1869,7 @@ class TestSimplifyTemplate : public TestFixture { "void some_func() {\n" " Foo x;\n" " x.foo();\n" - "}"; + "}\n"; const char exp[] = "class Foo { " "public: " "void foo ( ) ; " @@ -1890,7 +1890,7 @@ class TestSimplifyTemplate : public TestFixture { const char code[] = "class Fred {\n" " template T foo(T t) const { return t; }\n" "};\n" - "const void * p = Fred::foo(nullptr);"; + "const void * p = Fred::foo(nullptr);\n"; const char exp[] = "class Fred { " "const void * foo ( const void * t ) const ; " "} ; " @@ -1908,7 +1908,7 @@ class TestSimplifyTemplate : public TestFixture { "SortWith::SortWith(Type) {}\n" "int main() {\n" " SortWith(0);\n" - "}"; + "}\n"; const char exp[] = "template < typename Type > " "struct SortWith { " "SortWith ( Type ) ; " @@ -1938,7 +1938,7 @@ class TestSimplifyTemplate : public TestFixture { " swizzle<1>(tt2);\n" " tvec3 tt3;\n" " swizzle<2,3>(tt3);\n" - "}"; + "}\n"; const char exp[] = "const int f16 = 16 ; " "class tvec2 ; " "class tvec3 ; " @@ -1969,7 +1969,7 @@ class TestSimplifyTemplate : public TestFixture { "MultiConsumer::MultiConsumer() : sizeBuffer(0) {}\n" "MultiReads::MultiReads() {\n" " mc = new MultiConsumer();\n" - "}"; + "}\n"; const char exp[] = "template < typename Task > " // TODO: this should be expanded "class MultiConsumer { " "MultiConsumer ( ) ; " @@ -1987,7 +1987,7 @@ class TestSimplifyTemplate : public TestFixture { const char code[] = "template \n" "auto d() -> typename a::e {\n" " d();\n" - "}"; + "}\n"; const char exp[] = "template < class b , int c , class > " "auto d ( ) . a < decltype ( b { } ) > :: e { " "d < int , c , int > ( ) ; " @@ -1998,8 +1998,8 @@ class TestSimplifyTemplate : public TestFixture { const char code[] = "template \n" "auto d() -> typename a::e {\n" " d();\n" - "}" - "void foo() { d(); }"; + "}\n" + "void foo() { d(); }\n"; const char exp[] = "auto d ( ) . a < char > :: e ; " "auto d ( ) . a < int > :: e ; " "void foo ( ) { d ( ) ; } " @@ -2023,7 +2023,7 @@ class TestSimplifyTemplate : public TestFixture { "extern template void C::foo();\n" "template\n" "template::value)>::type>\n" - "void C::foo() {}"; + "void C::foo() {}\n"; // @todo the output is very wrong but we are only worried about the crash for now (void)tok(code); } @@ -2039,7 +2039,7 @@ class TestSimplifyTemplate : public TestFixture { "template \n" "S U::u;\n" "template S U::u;\n" - "S &i = U::u;"; + "S &i = U::u;\n"; (void)tok(code); } @@ -2047,7 +2047,7 @@ class TestSimplifyTemplate : public TestFixture { const char code[] = "template\n" "T f1(T t) { return t; }\n" "template const char * f1(const char *);\n" - "template const char & f1(const char &);"; + "template const char & f1(const char &);\n"; const char exp[] = "const char * f1 ( const char * t ) ; " "const char & f1 ( const char & t ) ; " "const char * f1 ( const char * t ) { return t ; } " @@ -2074,7 +2074,7 @@ class TestSimplifyTemplate : public TestFixture { "int main() {\n" " CTest::Greeting(true);\n" " return 0;\n" - "}"; + "}\n"; const char exp[] = "class CTest { " "public: " "static void Greeting ( bool ) ; " @@ -2104,7 +2104,7 @@ class TestSimplifyTemplate : public TestFixture { "template void Fred::foo();\n" "template void Fred::foo();\n" "template <> void Fred::foo() { }\n" - "template <> void Fred::foo() { }"; + "template <> void Fred::foo() { }\n"; const char exp[] = "struct Fred { " "static void foo ( ) ; " "static void foo ( ) ; " @@ -2122,7 +2122,7 @@ class TestSimplifyTemplate : public TestFixture { const char code[] = "template struct S1 {};\n" "void f(S1) {}\n" "template \n" - "decltype(S1().~S1()) fun1() {};"; + "decltype(S1().~S1()) fun1() {};\n"; const char exp[] = "struct S1 ; " "void f ( S1 ) { } " "template < typename T > " @@ -2137,7 +2137,7 @@ class TestSimplifyTemplate : public TestFixture { "template<> char foo(char a) { return a; }\n" "template<> int foo(int a) { return a; }\n" "template float foo(float);\n" - "template double foo(double);"; + "template double foo(double);\n"; const char exp[] = "int foo ( int a ) ; " "char foo ( char a ) ; " "float foo ( float t ) ; " @@ -2155,7 +2155,7 @@ class TestSimplifyTemplate : public TestFixture { " template<> int foo(int a) { return a; }\n" "};\n" "template float Fred::foo(float);\n" - "template double Fred::foo(double);"; + "template double Fred::foo(double);\n"; const char exp[] = "struct Fred { " "int foo ( int a ) ; " "char foo ( char a ) ; " @@ -2180,7 +2180,7 @@ class TestSimplifyTemplate : public TestFixture { " template float NS2::foo(float);\n" " template bool NS1::NS2::foo(bool);\n" "}\n" - "template double NS1::NS2::foo(double);"; + "template double NS1::NS2::foo(double);\n"; const char exp[] = "namespace NS1 { " "namespace NS2 { " "int foo ( int a ) ; " @@ -2213,7 +2213,7 @@ class TestSimplifyTemplate : public TestFixture { " template float NS::foo(float);\n" " template bool NS1::NS::foo(bool);\n" "}\n" - "template double NS1::NS::foo(double);"; + "template double NS1::NS::foo(double);\n"; const char exp[] = "namespace NS1 { " "namespace NS { " "int foo ( int a ) ; " @@ -2244,7 +2244,7 @@ class TestSimplifyTemplate : public TestFixture { " foo(2);\n" " foo(3.14);\n" " foo(3.14f);\n" - "}"; + "}\n"; const char exp[] = "void foo ( const double & d ) ; " "void foo ( const float & t ) ; " "void foo ( const int & t ) ; " @@ -2273,7 +2273,7 @@ class TestSimplifyTemplate : public TestFixture { "void Vector2::process() {\n" " ForEach();\n" "}\n" - "Vector2 c;"; + "Vector2 c;\n"; const char exp[] = "void ForEach ( ) ; " "class Vector2 ; " "Vector2 c ; " @@ -2303,7 +2303,7 @@ class TestSimplifyTemplate : public TestFixture { "Array matmul() {\n" " return foo( );\n" "}\n" - "template Array> matmul>();"; + "template Array> matmul>();\n"; const char exp[] = "class Array ; " "class Array> ; " "class Array ; " @@ -2331,7 +2331,7 @@ class TestSimplifyTemplate : public TestFixture { "template<>\n" "int Value = 456;\n" "float f = Value;\n" - "int i = Value;"; + "int i = Value;\n"; const char exp[] = "float Value ; Value = 123 ; " "int Value ; Value = 456 ; " "float f ; f = Value ; " @@ -2350,7 +2350,7 @@ class TestSimplifyTemplate : public TestFixture { "long f0 = fib<0>;\n" "long f1 = fib<1>;\n" "long f2 = fib<2>;\n" - "long f3 = fib<3>;"; + "long f3 = fib<3>;\n"; const char exp[] = "constexpr long fib<2> = fib<1> + fib<0> ; " "constexpr long fib<3> = fib<2> + fib<1> ; " "constexpr long fib<0> = 0 ; " @@ -2410,7 +2410,7 @@ class TestSimplifyTemplate : public TestFixture { "}\n" "using namespace NS1::NS2::NS3::NS4;\n" "Fred fred_bool1;\n" - "NS1::NS2::NS3::NS4::Fred fred_int1;"; + "NS1::NS2::NS3::NS4::Fred fred_int1;\n"; const char exp[] = "namespace NS1 { " "namespace NS2 { " "namespace NS3 { " @@ -2488,7 +2488,7 @@ class TestSimplifyTemplate : public TestFixture { " unique_ptr_with_deleter tmp(new A(), [](A* a) {\n" " delete a;\n" " });\n" - "}"; + "}\n"; const char exp[] = "class A { } ; " "static void func ( ) { " "std :: unique_ptr < A , std :: function < void ( A * ) > > tmp ( new A ( ) , [ ] ( A * a ) { " @@ -2536,7 +2536,7 @@ class TestSimplifyTemplate : public TestFixture { " using ArrayType = std::vector;\n" " void func(typename ArrayType::size_type i) {\n" " }\n" - "};"; + "};\n"; const char exp[] = "class A { " "public: " @@ -2557,7 +2557,7 @@ class TestSimplifyTemplate : public TestFixture { "}\n" "void f() {\n" " if(std::is_floating_point::value) {}\n" - "}"; + "}\n"; const char exp[] = "namespace ns { " "template < class T > " "struct is_floating_point " @@ -2582,7 +2582,7 @@ class TestSimplifyTemplate : public TestFixture { " return t;\n" " }\n" "}\n" - "sample::Sample s1;"; + "sample::Sample s1;\n"; const char exp[] = "namespace sample { " "class Sample ; " "} " @@ -2608,7 +2608,7 @@ class TestSimplifyTemplate : public TestFixture { " BOOST_HANA_CONSTANT_CHECK ( hana :: equal (\n" " hana :: at_key ( hana :: make_map ( p < 0 , 0 > ( ) ) , key < 0 > ( ) ) ,\n" " val < 0 > ( ) ) ) ;\n" - "}"; + "}\n"; const char exp[] = "auto key<0> ( ) ; " "auto val<0> ( ) ; " "auto p<0,0> ( ) ; " @@ -2628,7 +2628,7 @@ class TestSimplifyTemplate : public TestFixture { "template