Skip to content

Commit b04d181

Browse files
committed
Add -std=c++17 and allow semicolon in 'if ()'
1 parent cb06aeb commit b04d181

4 files changed

Lines changed: 15 additions & 7 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
606606
mSettings->standards.cpp = Standards::CPP11;
607607
} else if (std::strcmp(argv[i], "--std=c++14") == 0) {
608608
mSettings->standards.cpp = Standards::CPP14;
609+
} else if (std::strcmp(argv[i], "--std=c++17") == 0) {
610+
mSettings->standards.cpp = Standards::CPP17;
609611
}
610612

611613
// Output formatter
@@ -1095,7 +1097,9 @@ void CmdLineParser::printHelp()
10951097
" * c++11\n"
10961098
" C++ code is C++11 compatible\n"
10971099
" * c++14\n"
1098-
" C++ code is C++14 compatible (default)\n"
1100+
" C++ code is C++14 compatible\n"
1101+
" * c++17\n"
1102+
" C++ code is C++17 compatible (default)\n"
10991103
" --suppress=<spec> Suppress warnings that match <spec>. The format of\n"
11001104
" <spec> is:\n"
11011105
" [error id]:[filename]:[line]\n"

lib/standards.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ struct Standards {
3636
enum cstd_t { C89, C99, C11, CLatest=C11 } c;
3737

3838
/** C++ code standard */
39-
enum cppstd_t { CPP03, CPP11, CPP14, CPPLatest=CPP14 } cpp;
39+
enum cppstd_t { CPP03, CPP11, CPP14, CPP17, CPPLatest=CPP17 } cpp;
4040

4141
/** This constructor clear all the variables **/
42-
Standards() : c(C11), cpp(CPP14) {}
42+
Standards() : c(C11), cpp(CPP17) {}
4343

4444
bool setC(const std::string& str) {
4545
if (str == "c89" || str == "C89") {
@@ -69,6 +69,10 @@ struct Standards {
6969
cpp = CPP14;
7070
return true;
7171
}
72+
if (str == "c++17" || str == "C++17") {
73+
cpp = CPP17;
74+
return true;
75+
}
7276
return false;
7377
}
7478
};

lib/tokenize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9040,7 +9040,7 @@ void Tokenizer::findGarbageCode() const
90409040
if (!Token::Match(tok->next(), "( !!)"))
90419041
syntaxError(tok);
90429042
if (tok->str() != "for") {
9043-
if (isGarbageExpr(tok->next(), tok->linkAt(1)))
9043+
if (isGarbageExpr(tok->next(), tok->linkAt(1), mSettings->standards.cpp>=Standards::cppstd_t::CPP17))
90449044
syntaxError(tok);
90459045
}
90469046
}
@@ -9197,12 +9197,12 @@ void Tokenizer::findGarbageCode() const
91979197
}
91989198

91999199

9200-
bool Tokenizer::isGarbageExpr(const Token *start, const Token *end)
9200+
bool Tokenizer::isGarbageExpr(const Token *start, const Token *end, bool allowSemicolon)
92019201
{
92029202
for (const Token *tok = start; tok != end; tok = tok->next()) {
92039203
if (tok->isControlFlowKeyword())
92049204
return true;
9205-
if (tok->str() == ";")
9205+
if (!allowSemicolon && tok->str() == ";")
92069206
return true;
92079207
if (tok->str() == "{")
92089208
tok = tok->link();

lib/tokenize.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ class CPPCHECKLIB Tokenizer {
632632
void findGarbageCode() const;
633633

634634
/** Detect garbage expression */
635-
static bool isGarbageExpr(const Token *start, const Token *end);
635+
static bool isGarbageExpr(const Token *start, const Token *end, bool allowSemicolon);
636636

637637
/**
638638
* Remove __declspec()

0 commit comments

Comments
 (0)