Skip to content

Commit

Permalink
cmdline: use existing logic to validate --std option
Browse files Browse the repository at this point in the history
  • Loading branch information
ludviggunne committed Aug 30, 2024
1 parent ca754f8 commit 745f0ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
28 changes: 11 additions & 17 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,14 +1257,23 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
// --std
else if (std::strncmp(argv[i], "--std=", 6) == 0) {
const std::string std = argv[i] + 6;
// TODO: print error when standard is unknown
bool unknown = false;
if (std::strncmp(std.c_str(), "c++", 3) == 0) {
mSettings.standards.cpp = Standards::getCPP(std);
if (mSettings.standards.getCPP() != std) {
unknown = true;
}
}
else if (std::strncmp(std.c_str(), "c", 1) == 0) {
mSettings.standards.c = Standards::getC(std);
if (mSettings.standards.getC() != std) {
unknown = true;
}
}
else {
unknown = true;
}
if (!validateStandard(std)) {
if (unknown) {
mLogger.printError("unknown --std value '" + std + "'");
return Result::Fail;
}
Expand Down Expand Up @@ -1943,18 +1952,3 @@ bool CmdLineParser::loadCppcheckCfg()
return true;
}

bool CmdLineParser::validateStandard(const std::string &std)
{
return std == "c++03"
|| std == "c++11"
|| std == "c++14"
|| std == "c++17"
|| std == "c++20"
|| std == "c++23"
|| std == "c++26"
|| std == "c89"
|| std == "c99"
|| std == "c11"
|| std == "c17"
|| std == "c23";
}
2 changes: 0 additions & 2 deletions cli/cmdlineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ class CmdLineParser {

bool loadCppcheckCfg();

static bool validateStandard(const std::string &std);

CmdLineLogger &mLogger;

std::vector<std::string> mPathNames;
Expand Down

0 comments on commit 745f0ff

Please sign in to comment.