From 745f0ff13ad1ee202286c3b19cda92289e648796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Fri, 30 Aug 2024 15:21:51 +0200 Subject: [PATCH] cmdline: use existing logic to validate --std option --- cli/cmdlineparser.cpp | 28 +++++++++++----------------- cli/cmdlineparser.h | 2 -- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 6e01cd10116..fc8656b394a 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -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; } @@ -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"; -} diff --git a/cli/cmdlineparser.h b/cli/cmdlineparser.h index f8023bfd6f9..b1abdd1222b 100644 --- a/cli/cmdlineparser.h +++ b/cli/cmdlineparser.h @@ -156,8 +156,6 @@ class CmdLineParser { bool loadCppcheckCfg(); - static bool validateStandard(const std::string &std); - CmdLineLogger &mLogger; std::vector mPathNames;