Add -std=c++17 and allow semicolon in 'if ()'

This commit is contained in:
Daniel Marjamäki 2019-04-12 09:10:25 +02:00
parent cb06aebdab
commit b04d1815ed
4 changed files with 15 additions and 7 deletions

View File

@ -606,6 +606,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
mSettings->standards.cpp = Standards::CPP11;
} else if (std::strcmp(argv[i], "--std=c++14") == 0) {
mSettings->standards.cpp = Standards::CPP14;
} else if (std::strcmp(argv[i], "--std=c++17") == 0) {
mSettings->standards.cpp = Standards::CPP17;
}
// Output formatter
@ -1095,7 +1097,9 @@ void CmdLineParser::printHelp()
" * c++11\n"
" C++ code is C++11 compatible\n"
" * c++14\n"
" C++ code is C++14 compatible (default)\n"
" C++ code is C++14 compatible\n"
" * c++17\n"
" C++ code is C++17 compatible (default)\n"
" --suppress=<spec> Suppress warnings that match <spec>. The format of\n"
" <spec> is:\n"
" [error id]:[filename]:[line]\n"

View File

@ -36,10 +36,10 @@ struct Standards {
enum cstd_t { C89, C99, C11, CLatest=C11 } c;
/** C++ code standard */
enum cppstd_t { CPP03, CPP11, CPP14, CPPLatest=CPP14 } cpp;
enum cppstd_t { CPP03, CPP11, CPP14, CPP17, CPPLatest=CPP17 } cpp;
/** This constructor clear all the variables **/
Standards() : c(C11), cpp(CPP14) {}
Standards() : c(C11), cpp(CPP17) {}
bool setC(const std::string& str) {
if (str == "c89" || str == "C89") {
@ -69,6 +69,10 @@ struct Standards {
cpp = CPP14;
return true;
}
if (str == "c++17" || str == "C++17") {
cpp = CPP17;
return true;
}
return false;
}
};

View File

@ -9040,7 +9040,7 @@ void Tokenizer::findGarbageCode() const
if (!Token::Match(tok->next(), "( !!)"))
syntaxError(tok);
if (tok->str() != "for") {
if (isGarbageExpr(tok->next(), tok->linkAt(1)))
if (isGarbageExpr(tok->next(), tok->linkAt(1), mSettings->standards.cpp>=Standards::cppstd_t::CPP17))
syntaxError(tok);
}
}
@ -9197,12 +9197,12 @@ void Tokenizer::findGarbageCode() const
}
bool Tokenizer::isGarbageExpr(const Token *start, const Token *end)
bool Tokenizer::isGarbageExpr(const Token *start, const Token *end, bool allowSemicolon)
{
for (const Token *tok = start; tok != end; tok = tok->next()) {
if (tok->isControlFlowKeyword())
return true;
if (tok->str() == ";")
if (!allowSemicolon && tok->str() == ";")
return true;
if (tok->str() == "{")
tok = tok->link();

View File

@ -632,7 +632,7 @@ private:
void findGarbageCode() const;
/** Detect garbage expression */
static bool isGarbageExpr(const Token *start, const Token *end);
static bool isGarbageExpr(const Token *start, const Token *end, bool allowSemicolon);
/**
* Remove __declspec()