This commit is contained in:
parent
a57fc9ace6
commit
d26022ac9a
|
@ -1997,7 +1997,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
|
||||||
Token::simpleMatch(tok->linkAt(1), ") {") &&
|
Token::simpleMatch(tok->linkAt(1), ") {") &&
|
||||||
(!tok->previous() || Token::Match(tok->previous(), ";|}"))) {
|
(!tok->previous() || Token::Match(tok->previous(), ";|}"))) {
|
||||||
if (mTokenizer.isC()) {
|
if (mTokenizer.isC()) {
|
||||||
debugMessage(tok, "debug", "SymbolDatabase::isFunction found C function '" + tok->str() + "' without a return type.");
|
returnImplicitIntError(tok);
|
||||||
*funcStart = tok;
|
*funcStart = tok;
|
||||||
*argStart = tok->next();
|
*argStart = tok->next();
|
||||||
*declEnd = tok->linkAt(1)->next();
|
*declEnd = tok->linkAt(1)->next();
|
||||||
|
@ -3522,6 +3522,19 @@ void SymbolDatabase::debugMessage(const Token *tok, const std::string &type, con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SymbolDatabase::returnImplicitIntError(const Token *tok) const
|
||||||
|
{
|
||||||
|
if (tok && mSettings.severity.isEnabled(Severity::portability) && mSettings.standards.c != Standards::C89 && mErrorLogger) {
|
||||||
|
const std::list<const Token*> locationList(1, tok);
|
||||||
|
const ErrorMessage errmsg(locationList, &mTokenizer.list,
|
||||||
|
Severity::portability,
|
||||||
|
"returnImplicitInt",
|
||||||
|
"Omitted return type of function '" + tok->str() + "' defaults to int, this is not supported by ISO C99 and later standards.",
|
||||||
|
Certainty::normal);
|
||||||
|
mErrorLogger->reportErr(errmsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const Function* Type::getFunction(const std::string& funcName) const
|
const Function* Type::getFunction(const std::string& funcName) const
|
||||||
{
|
{
|
||||||
if (classScope) {
|
if (classScope) {
|
||||||
|
|
|
@ -1371,6 +1371,8 @@ public:
|
||||||
*/
|
*/
|
||||||
void debugMessage(const Token *tok, const std::string &type, const std::string &msg) const;
|
void debugMessage(const Token *tok, const std::string &type, const std::string &msg) const;
|
||||||
|
|
||||||
|
void returnImplicitIntError(const Token *tok) const;
|
||||||
|
|
||||||
void printOut(const char * title = nullptr) const;
|
void printOut(const char * title = nullptr) const;
|
||||||
void printVariable(const Variable *var, const char *indent) const;
|
void printVariable(const Variable *var, const char *indent) const;
|
||||||
void printXml(std::ostream &out) const;
|
void printXml(std::ostream &out) const;
|
||||||
|
|
|
@ -2380,12 +2380,12 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
void check_(const char* file, int line, const char code[], bool debug = true, const char filename[] = "test.cpp") {
|
void check_(const char* file, int line, const char code[], bool debug = true, const char filename[] = "test.cpp", const Settings* pSettings = nullptr) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
const Settings settings = settingsBuilder(settings1).debugwarnings(debug).build();
|
const Settings settings = settingsBuilder(pSettings ? *pSettings : settings1).debugwarnings(debug).build();
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
|
@ -2986,7 +2986,12 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("main(int argc, char *argv[]) { }", true, "test.c");
|
check("main(int argc, char *argv[]) { }", true, "test.c");
|
||||||
ASSERT_EQUALS("[test.c:1]: (debug) SymbolDatabase::isFunction found C function 'main' without a return type.\n", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
const Settings s = settingsBuilder(settings1).severity(Severity::portability).build();
|
||||||
|
check("main(int argc, char *argv[]) { }", false, "test.c", &s);
|
||||||
|
ASSERT_EQUALS("[test.c:1]: (portability) Omitted return type of function 'main' defaults to int, this is not supported by ISO C99 and later standards.\n",
|
||||||
|
errout.str());
|
||||||
|
|
||||||
check("namespace boost {\n"
|
check("namespace boost {\n"
|
||||||
" std::locale generate_locale()\n"
|
" std::locale generate_locale()\n"
|
||||||
|
|
Loading…
Reference in New Issue