From 9f306cf3aa9cd3c2c76d0fb0eb6ad6351bdd5c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 22 Sep 2017 22:00:00 +0200 Subject: [PATCH] Added C++14 option --- cli/cmdlineparser.cpp | 6 +++++- gui/checkthread.cpp | 15 +++++++++++++-- gui/common.h | 1 + gui/mainwindow.cpp | 17 +++++++++++++---- gui/mainwindow.ui | 14 +++++++++++++- lib/standards.h | 8 ++++++-- 6 files changed, 51 insertions(+), 10 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 17cd51590..b3b514a54 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -523,6 +523,8 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) _settings->standards.cpp = Standards::CPP03; } else if (std::strcmp(argv[i], "--std=c++11") == 0) { _settings->standards.cpp = Standards::CPP11; + } else if (std::strcmp(argv[i], "--std=c++14") == 0) { + _settings->standards.cpp = Standards::CPP14; } // Output formatter @@ -985,7 +987,9 @@ void CmdLineParser::PrintHelp() " * c++03\n" " C++ code is C++03 compatible\n" " * c++11\n" - " C++ code is C++11 compatible (default)\n" + " C++ code is C++11 compatible\n" + " * c++14\n" + " C++ code is C++14 compatible (default)\n" " More than one --std can be used:\n" " 'cppcheck --std=c99 --std=posix file.c'\n" " --suppress= Suppress warnings that match . The format of\n" diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp index be008543d..e32f927f7 100644 --- a/gui/checkthread.cpp +++ b/gui/checkthread.cpp @@ -155,8 +155,19 @@ void CheckThread::runAddonsAndTools(const QString &addonPath, const ImportProjec if (!fileSettings->standard.empty()) args << ("-std=" + QString::fromStdString(fileSettings->standard)); - else - args << "-std=c++14"; + else { + switch (mCppcheck.settings().standards.cpp) { + case Standards::CPP03: + args << "-std=c++03"; + break; + case Standards::CPP11: + args << "-std=c++11"; + break; + case Standards::CPP14: + args << "-std=c++14"; + break; + }; + } QString analyzerInfoFile; diff --git a/gui/common.h b/gui/common.h index 1de0fb306..d79f64fe9 100644 --- a/gui/common.h +++ b/gui/common.h @@ -60,6 +60,7 @@ // Standards support #define SETTINGS_STD_CPP03 "Platform CPP03" #define SETTINGS_STD_CPP11 "Platform CPP11" +#define SETTINGS_STD_CPP14 "Platform CPP14" #define SETTINGS_STD_C89 "Platform C89" #define SETTINGS_STD_C99 "Platform C99" #define SETTINGS_STD_C11 "Platform C11" diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 15e5283ae..1928810a5 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -199,6 +199,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : mUI.mActionCpp03->setActionGroup(mCppStandardActions); mUI.mActionCpp11->setActionGroup(mCppStandardActions); + mUI.mActionCpp14->setActionGroup(mCppStandardActions); mUI.mActionEnforceC->setActionGroup(mSelectLanguageActions); mUI.mActionEnforceCpp->setActionGroup(mSelectLanguageActions); @@ -276,7 +277,9 @@ void MainWindow::loadSettings() const bool stdCpp03 = mSettings->value(SETTINGS_STD_CPP03, false).toBool(); mUI.mActionCpp03->setChecked(stdCpp03); const bool stdCpp11 = mSettings->value(SETTINGS_STD_CPP11, true).toBool(); - mUI.mActionCpp11->setChecked(stdCpp11 || !stdCpp03); + mUI.mActionCpp11->setChecked(stdCpp11 && !stdCpp03); + const bool stdCpp14 = mSettings->value(SETTINGS_STD_CPP14, true).toBool(); + mUI.mActionCpp14->setChecked(stdCpp14 && !stdCpp03 && !stdCpp11); const bool stdC89 = mSettings->value(SETTINGS_STD_C89, false).toBool(); mUI.mActionC89->setChecked(stdC89); const bool stdC11 = mSettings->value(SETTINGS_STD_C11, false).toBool(); @@ -350,6 +353,7 @@ void MainWindow::saveSettings() const mSettings->setValue(SETTINGS_STD_CPP03, mUI.mActionCpp03->isChecked()); mSettings->setValue(SETTINGS_STD_CPP11, mUI.mActionCpp11->isChecked()); + mSettings->setValue(SETTINGS_STD_CPP14, mUI.mActionCpp14->isChecked()); mSettings->setValue(SETTINGS_STD_C89, mUI.mActionC89->isChecked()); mSettings->setValue(SETTINGS_STD_C99, mUI.mActionC99->isChecked()); mSettings->setValue(SETTINGS_STD_C11, mUI.mActionC11->isChecked()); @@ -449,16 +453,16 @@ void MainWindow::doAnalyzeProject(ImportProject p) mThread->setPythonPath(mSettings->value(SETTINGS_PYTHON_PATH).toString()); QString clangHeaders = mSettings->value(SETTINGS_VS_INCLUDE_PATHS).toString(); mThread->setClangIncludePaths(clangHeaders.split(";")); -#ifdef Q_OS_WIN QString clangPath = mSettings->value(SETTINGS_CLANG_PATH,QString()).toString(); +#ifdef Q_OS_WIN if (clangPath.isEmpty()) { // Try to autodetect clang if (QFileInfo("C:/Program Files/LLVM/bin/clang.exe").exists()) clangPath = "C:/Program Files/LLVM/bin"; } +#endif mThread->setClangPath(clangPath); mThread->setSuppressions(mProjectFile->getSuppressions()); -#endif } mThread->setProject(p); mThread->check(checkSettings); @@ -868,7 +872,12 @@ Settings MainWindow::getCppcheckSettings() result.inlineSuppressions = mSettings->value(SETTINGS_INLINE_SUPPRESSIONS, false).toBool(); result.inconclusive = mSettings->value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool(); result.platformType = (Settings::PlatformType) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt(); - result.standards.cpp = mSettings->value(SETTINGS_STD_CPP11, true).toBool() ? Standards::CPP11 : Standards::CPP03; + if (mSettings->value(SETTINGS_STD_CPP03, false).toBool()) + result.standards.cpp = Standards::CPP03; + else if (mSettings->value(SETTINGS_STD_CPP11, false).toBool()) + result.standards.cpp = Standards::CPP11; + else if (mSettings->value(SETTINGS_STD_CPP14, true).toBool()) + result.standards.cpp = Standards::CPP14; result.standards.c = mSettings->value(SETTINGS_STD_C99, true).toBool() ? Standards::C99 : (mSettings->value(SETTINGS_STD_C11, false).toBool() ? Standards::C11 : Standards::C89); result.standards.posix = mSettings->value(SETTINGS_STD_POSIX, false).toBool(); result.enforcedLang = (Settings::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt(); diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index 1782cdf44..d569eca7c 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -136,6 +136,7 @@ + @@ -681,7 +682,7 @@ true - true + false C++&11 @@ -778,6 +779,17 @@ E&nforce C + + + true + + + true + + + C++14 + + diff --git a/lib/standards.h b/lib/standards.h index 8b04cf6ca..6d7faca7f 100644 --- a/lib/standards.h +++ b/lib/standards.h @@ -36,13 +36,13 @@ struct Standards { enum cstd_t { C89, C99, C11, CLatest=C11 } c; /** C++ code standard */ - enum cppstd_t { CPP03, CPP11, CPPLatest=CPP11 } cpp; + enum cppstd_t { CPP03, CPP11, CPP14, CPPLatest=CPP14 } cpp; /** Code is posix */ bool posix; /** This constructor clear all the variables **/ - Standards() : c(C11), cpp(CPP11), posix(false) {} + Standards() : c(C11), cpp(CPP14), posix(false) {} bool setC(const std::string& str) { if (str == "c89" || str == "C89") { @@ -68,6 +68,10 @@ struct Standards { cpp = CPP11; return true; } + if (str == "c++14" || str == "C++14") { + cpp = CPP14; + return true; + } return false; } };