Added C++14 option

This commit is contained in:
Daniel Marjamäki 2017-09-22 22:00:00 +02:00
parent 791f6ecbec
commit 9f306cf3aa
6 changed files with 51 additions and 10 deletions

View File

@ -523,6 +523,8 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
_settings->standards.cpp = Standards::CPP03; _settings->standards.cpp = Standards::CPP03;
} else if (std::strcmp(argv[i], "--std=c++11") == 0) { } else if (std::strcmp(argv[i], "--std=c++11") == 0) {
_settings->standards.cpp = Standards::CPP11; _settings->standards.cpp = Standards::CPP11;
} else if (std::strcmp(argv[i], "--std=c++14") == 0) {
_settings->standards.cpp = Standards::CPP14;
} }
// Output formatter // Output formatter
@ -985,7 +987,9 @@ void CmdLineParser::PrintHelp()
" * c++03\n" " * c++03\n"
" C++ code is C++03 compatible\n" " C++ code is C++03 compatible\n"
" * c++11\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" " More than one --std can be used:\n"
" 'cppcheck --std=c99 --std=posix file.c'\n" " 'cppcheck --std=c99 --std=posix file.c'\n"
" --suppress=<spec> Suppress warnings that match <spec>. The format of\n" " --suppress=<spec> Suppress warnings that match <spec>. The format of\n"

View File

@ -155,8 +155,19 @@ void CheckThread::runAddonsAndTools(const QString &addonPath, const ImportProjec
if (!fileSettings->standard.empty()) if (!fileSettings->standard.empty())
args << ("-std=" + QString::fromStdString(fileSettings->standard)); args << ("-std=" + QString::fromStdString(fileSettings->standard));
else 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"; args << "-std=c++14";
break;
};
}
QString analyzerInfoFile; QString analyzerInfoFile;

View File

@ -60,6 +60,7 @@
// Standards support // Standards support
#define SETTINGS_STD_CPP03 "Platform CPP03" #define SETTINGS_STD_CPP03 "Platform CPP03"
#define SETTINGS_STD_CPP11 "Platform CPP11" #define SETTINGS_STD_CPP11 "Platform CPP11"
#define SETTINGS_STD_CPP14 "Platform CPP14"
#define SETTINGS_STD_C89 "Platform C89" #define SETTINGS_STD_C89 "Platform C89"
#define SETTINGS_STD_C99 "Platform C99" #define SETTINGS_STD_C99 "Platform C99"
#define SETTINGS_STD_C11 "Platform C11" #define SETTINGS_STD_C11 "Platform C11"

View File

@ -199,6 +199,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
mUI.mActionCpp03->setActionGroup(mCppStandardActions); mUI.mActionCpp03->setActionGroup(mCppStandardActions);
mUI.mActionCpp11->setActionGroup(mCppStandardActions); mUI.mActionCpp11->setActionGroup(mCppStandardActions);
mUI.mActionCpp14->setActionGroup(mCppStandardActions);
mUI.mActionEnforceC->setActionGroup(mSelectLanguageActions); mUI.mActionEnforceC->setActionGroup(mSelectLanguageActions);
mUI.mActionEnforceCpp->setActionGroup(mSelectLanguageActions); mUI.mActionEnforceCpp->setActionGroup(mSelectLanguageActions);
@ -276,7 +277,9 @@ void MainWindow::loadSettings()
const bool stdCpp03 = mSettings->value(SETTINGS_STD_CPP03, false).toBool(); const bool stdCpp03 = mSettings->value(SETTINGS_STD_CPP03, false).toBool();
mUI.mActionCpp03->setChecked(stdCpp03); mUI.mActionCpp03->setChecked(stdCpp03);
const bool stdCpp11 = mSettings->value(SETTINGS_STD_CPP11, true).toBool(); 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(); const bool stdC89 = mSettings->value(SETTINGS_STD_C89, false).toBool();
mUI.mActionC89->setChecked(stdC89); mUI.mActionC89->setChecked(stdC89);
const bool stdC11 = mSettings->value(SETTINGS_STD_C11, false).toBool(); 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_CPP03, mUI.mActionCpp03->isChecked());
mSettings->setValue(SETTINGS_STD_CPP11, mUI.mActionCpp11->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_C89, mUI.mActionC89->isChecked());
mSettings->setValue(SETTINGS_STD_C99, mUI.mActionC99->isChecked()); mSettings->setValue(SETTINGS_STD_C99, mUI.mActionC99->isChecked());
mSettings->setValue(SETTINGS_STD_C11, mUI.mActionC11->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()); mThread->setPythonPath(mSettings->value(SETTINGS_PYTHON_PATH).toString());
QString clangHeaders = mSettings->value(SETTINGS_VS_INCLUDE_PATHS).toString(); QString clangHeaders = mSettings->value(SETTINGS_VS_INCLUDE_PATHS).toString();
mThread->setClangIncludePaths(clangHeaders.split(";")); mThread->setClangIncludePaths(clangHeaders.split(";"));
#ifdef Q_OS_WIN
QString clangPath = mSettings->value(SETTINGS_CLANG_PATH,QString()).toString(); QString clangPath = mSettings->value(SETTINGS_CLANG_PATH,QString()).toString();
#ifdef Q_OS_WIN
if (clangPath.isEmpty()) { if (clangPath.isEmpty()) {
// Try to autodetect clang // Try to autodetect clang
if (QFileInfo("C:/Program Files/LLVM/bin/clang.exe").exists()) if (QFileInfo("C:/Program Files/LLVM/bin/clang.exe").exists())
clangPath = "C:/Program Files/LLVM/bin"; clangPath = "C:/Program Files/LLVM/bin";
} }
#endif
mThread->setClangPath(clangPath); mThread->setClangPath(clangPath);
mThread->setSuppressions(mProjectFile->getSuppressions()); mThread->setSuppressions(mProjectFile->getSuppressions());
#endif
} }
mThread->setProject(p); mThread->setProject(p);
mThread->check(checkSettings); mThread->check(checkSettings);
@ -868,7 +872,12 @@ Settings MainWindow::getCppcheckSettings()
result.inlineSuppressions = mSettings->value(SETTINGS_INLINE_SUPPRESSIONS, false).toBool(); result.inlineSuppressions = mSettings->value(SETTINGS_INLINE_SUPPRESSIONS, false).toBool();
result.inconclusive = mSettings->value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool(); result.inconclusive = mSettings->value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool();
result.platformType = (Settings::PlatformType) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt(); 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.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.standards.posix = mSettings->value(SETTINGS_STD_POSIX, false).toBool();
result.enforcedLang = (Settings::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt(); result.enforcedLang = (Settings::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt();

View File

@ -136,6 +136,7 @@
</property> </property>
<addaction name="mActionCpp03"/> <addaction name="mActionCpp03"/>
<addaction name="mActionCpp11"/> <addaction name="mActionCpp11"/>
<addaction name="mActionCpp14"/>
</widget> </widget>
<widget class="QMenu" name="menuC_standard"> <widget class="QMenu" name="menuC_standard">
<property name="title"> <property name="title">
@ -681,7 +682,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="text"> <property name="text">
<string>C++&amp;11</string> <string>C++&amp;11</string>
@ -778,6 +779,17 @@
<string>E&amp;nforce C</string> <string>E&amp;nforce C</string>
</property> </property>
</action> </action>
<action name="mActionCpp14">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>C++14</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -36,13 +36,13 @@ struct Standards {
enum cstd_t { C89, C99, C11, CLatest=C11 } c; enum cstd_t { C89, C99, C11, CLatest=C11 } c;
/** C++ code standard */ /** C++ code standard */
enum cppstd_t { CPP03, CPP11, CPPLatest=CPP11 } cpp; enum cppstd_t { CPP03, CPP11, CPP14, CPPLatest=CPP14 } cpp;
/** Code is posix */ /** Code is posix */
bool posix; bool posix;
/** This constructor clear all the variables **/ /** 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) { bool setC(const std::string& str) {
if (str == "c89" || str == "C89") { if (str == "c89" || str == "C89") {
@ -68,6 +68,10 @@ struct Standards {
cpp = CPP11; cpp = CPP11;
return true; return true;
} }
if (str == "c++14" || str == "C++14") {
cpp = CPP14;
return true;
}
return false; return false;
} }
}; };