Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,16 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
mUI->mActionC89->setActionGroup(mCStandardActions);
mUI->mActionC99->setActionGroup(mCStandardActions);
mUI->mActionC11->setActionGroup(mCStandardActions);
//mUI->mActionC17->setActionGroup(mCStandardActions);
//mUI->mActionC23->setActionGroup(mCStandardActions);

mUI->mActionCpp03->setActionGroup(mCppStandardActions);
mUI->mActionCpp11->setActionGroup(mCppStandardActions);
mUI->mActionCpp14->setActionGroup(mCppStandardActions);
mUI->mActionCpp17->setActionGroup(mCppStandardActions);
mUI->mActionCpp20->setActionGroup(mCppStandardActions);
//mUI->mActionCpp23->setActionGroup(mCppStandardActions);
//mUI->mActionCpp26->setActionGroup(mCppStandardActions);

mUI->mActionEnforceC->setActionGroup(mSelectLanguageActions);
mUI->mActionEnforceCpp->setActionGroup(mSelectLanguageActions);
Expand Down Expand Up @@ -374,13 +377,16 @@ void MainWindow::loadSettings()
mUI->mActionC89->setChecked(standards.c == Standards::C89);
mUI->mActionC99->setChecked(standards.c == Standards::C99);
mUI->mActionC11->setChecked(standards.c == Standards::C11);
//mUI->mActionC17->setChecked(standards.c == Standards::C17);
//mUI->mActionC23->setChecked(standards.c == Standards::C23);
standards.setCPP(mSettings->value(SETTINGS_STD_CPP, QString()).toString().toStdString());
mUI->mActionCpp03->setChecked(standards.cpp == Standards::CPP03);
mUI->mActionCpp11->setChecked(standards.cpp == Standards::CPP11);
mUI->mActionCpp14->setChecked(standards.cpp == Standards::CPP14);
mUI->mActionCpp17->setChecked(standards.cpp == Standards::CPP17);
mUI->mActionCpp20->setChecked(standards.cpp == Standards::CPP20);
//mUI->mActionCpp23->setChecked(standards.cpp == Standards::CPP23);
//mUI->mActionCpp26->setChecked(standards.cpp == Standards::CPP26);

// Main window settings
const bool showMainToolbar = mSettings->value(SETTINGS_TOOLBARS_MAIN_SHOW, true).toBool();
Expand Down Expand Up @@ -452,6 +458,10 @@ void MainWindow::saveSettings() const
mSettings->setValue(SETTINGS_STD_C, "C99");
if (mUI->mActionC11->isChecked())
mSettings->setValue(SETTINGS_STD_C, "C11");
//if (mUI->mActionC17->isChecked())
// mSettings->setValue(SETTINGS_STD_C, "C17");
//if (mUI->mActionC23->isChecked())
// mSettings->setValue(SETTINGS_STD_C, "C23");

if (mUI->mActionCpp03->isChecked())
mSettings->setValue(SETTINGS_STD_CPP, "C++03");
Expand All @@ -465,6 +475,8 @@ void MainWindow::saveSettings() const
mSettings->setValue(SETTINGS_STD_CPP, "C++20");
//if (mUI.mActionCpp23->isChecked())
// mSettings->setValue(SETTINGS_STD_CPP, "C++23");
//if (mUI.mActionCpp26->isChecked())
// mSettings->setValue(SETTINGS_STD_CPP, "C++26");

// Main window settings
mSettings->setValue(SETTINGS_TOOLBARS_MAIN_SHOW, mUI->mToolBarMain->isVisible());
Expand Down
30 changes: 30 additions & 0 deletions gui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
<addaction name="mActionCpp17"/>
<addaction name="mActionCpp20"/>
<!--addaction name="mActionCpp23"/-->
<!--addaction name="mActionCpp26"/-->
</widget>
<widget class="QMenu" name="menuC_standard">
<property name="title">
Expand All @@ -211,6 +212,8 @@
<addaction name="mActionC89"/>
<addaction name="mActionC99"/>
<addaction name="mActionC11"/>
<!--addaction name="mActionC17"/-->
<!--addaction name="mActionC23"/-->
</widget>
<addaction name="mActionAnalyzeFiles"/>
<addaction name="mActionAnalyzeDirectory"/>
Expand Down Expand Up @@ -794,6 +797,22 @@
<string>C&amp;11</string>
</property>
</action>
<!--action name="mActionC17">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>C&amp;17</string>
</property>
</action-->
<!--action name="mActionC23">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>C&amp;23</string>
</property>
</action-->
<action name="mActionC89">
<property name="checkable">
<bool>true</bool>
Expand Down Expand Up @@ -915,6 +934,17 @@
<string>C++23</string>
</property>
</action-->
<!--action name="mActionCpp26">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>C++26</string>
</property>
</action-->
<action name="mActionComplianceReport">
<property name="text">
<string>Compliance report...</string>
Expand Down
64 changes: 44 additions & 20 deletions lib/keywords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,17 @@
#define C11_KEYWORDS \
"_Alignas", "_Alignof", "_Atomic", "_Generic", "_Noreturn", "_Static_assert", "_Thread_local"

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-macros"
#endif

#define C23_KEYWORDS \
"alignas", "alignof", "bool", "constexpr", "false", "nullptr", "static_assert", "thread_local", "true", "typeof", "typeof_unqual", \
"_BitInt", "_Decimal128", "_Decimal32", "_Decimal64"

#ifdef __clang__
#pragma clang diagnostic pop
#endif

static const std::unordered_set<std::string> c89_keywords_all = {
C90_KEYWORDS
};

static const std::unordered_set<std::string> c89_keywords = c89_keywords_all;
static const std::unordered_set<std::string> c89_keywords = {
C90_KEYWORDS
};

static const std::unordered_set<std::string> c99_keywords_all = {
C90_KEYWORDS, C99_KEYWORDS
Expand All @@ -69,6 +62,13 @@ static const std::unordered_set<std::string> c11_keywords = {
C11_KEYWORDS
};

static const std::unordered_set<std::string> c17_keywords_all = {
C90_KEYWORDS, C99_KEYWORDS, C11_KEYWORDS
};

static const std::unordered_set<std::string> c17_keywords = {
};

static const std::unordered_set<std::string> c23_keywords_all = {
C90_KEYWORDS, C99_KEYWORDS, C11_KEYWORDS, C23_KEYWORDS
};
Expand Down Expand Up @@ -118,7 +118,9 @@ static const std::unordered_set<std::string> cpp03_keywords_all = {
CPP03_KEYWORDS
};

static const std::unordered_set<std::string> cpp03_keywords = cpp03_keywords_all;
static const std::unordered_set<std::string> cpp03_keywords = {
CPP03_KEYWORDS
};

static const std::unordered_set<std::string> cpp11_keywords_all = {
CPP03_KEYWORDS, CPP11_KEYWORDS
Expand All @@ -128,13 +130,19 @@ static const std::unordered_set<std::string> cpp11_keywords = {
CPP11_KEYWORDS
};

static const std::unordered_set<std::string> cpp14_keywords_all = cpp11_keywords_all;
static const std::unordered_set<std::string> cpp14_keywords_all = {
CPP03_KEYWORDS, CPP11_KEYWORDS
};

static const std::unordered_set<std::string> cpp14_keywords;
static const std::unordered_set<std::string> cpp14_keywords = {
};

static const std::unordered_set<std::string> cpp17_keywords_all = cpp11_keywords_all;
static const std::unordered_set<std::string> cpp17_keywords_all = {
CPP03_KEYWORDS, CPP11_KEYWORDS
};

static const std::unordered_set<std::string> cpp17_keywords;
static const std::unordered_set<std::string> cpp17_keywords = {
};

static const std::unordered_set<std::string> cpp20_keywords_all = {
CPP03_KEYWORDS, CPP11_KEYWORDS, CPP20_KEYWORDS
Expand All @@ -144,9 +152,19 @@ static const std::unordered_set<std::string> cpp20_keywords = {
CPP20_KEYWORDS
};

static const std::unordered_set<std::string> cpp23_keywords;
static const std::unordered_set<std::string> cpp23_keywords = {
};

static const std::unordered_set<std::string> cpp23_keywords_all = {
CPP03_KEYWORDS, CPP11_KEYWORDS, CPP20_KEYWORDS
};

static const std::unordered_set<std::string> cpp26_keywords = {
};

static const std::unordered_set<std::string> cpp23_keywords_all = cpp20_keywords_all;
static const std::unordered_set<std::string> cpp26_keywords_all = {
CPP03_KEYWORDS, CPP11_KEYWORDS, CPP20_KEYWORDS
};

// cppcheck-suppress unusedFunction
const std::unordered_set<std::string>& Keywords::getAll(Standards::cstd_t cStd)
Expand All @@ -158,8 +176,9 @@ const std::unordered_set<std::string>& Keywords::getAll(Standards::cstd_t cStd)
case Standards::cstd_t::C99:
return c99_keywords_all;
case Standards::cstd_t::C11:
case Standards::cstd_t::C17:
return c11_keywords_all;
case Standards::cstd_t::C17:
return c17_keywords_all;
case Standards::cstd_t::C23:
return c23_keywords_all;
}
Expand All @@ -182,6 +201,8 @@ const std::unordered_set<std::string>& Keywords::getAll(Standards::cppstd_t cppS
return cpp20_keywords_all;
case Standards::cppstd_t::CPP23:
return cpp23_keywords_all;
case Standards::cppstd_t::CPP26:
return cpp26_keywords_all;
}
cppcheck::unreachable();
}
Expand All @@ -196,10 +217,11 @@ const std::unordered_set<std::string>& Keywords::getOnly(Standards::cstd_t cStd)
case Standards::cstd_t::C99:
return c99_keywords;
case Standards::cstd_t::C11:
case Standards::cstd_t::C17:
return c11_keywords;
case Standards::cstd_t::C17:
return c17_keywords;
case Standards::cstd_t::C23:
return c23_keywords_all;
return c23_keywords;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returned the wrong container but I think it is still unused.

}
cppcheck::unreachable();
}
Expand All @@ -221,6 +243,8 @@ const std::unordered_set<std::string>& Keywords::getOnly(Standards::cppstd_t cpp
return cpp20_keywords;
case Standards::cppstd_t::CPP23:
return cpp23_keywords;
case Standards::cppstd_t::CPP26:
return cpp26_keywords;
}
cppcheck::unreachable();
}
Expand Down
25 changes: 10 additions & 15 deletions lib/standards.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,16 @@ struct Standards {
enum cstd_t { C89, C99, C11, C17, C23, CLatest = C23 } c = CLatest;

/** C++ code standard */
enum cppstd_t { CPP03, CPP11, CPP14, CPP17, CPP20, CPP23, CPPLatest = CPP23 } cpp = CPPLatest;
enum cppstd_t { CPP03, CPP11, CPP14, CPP17, CPP20, CPP23, CPP26, CPPLatest = CPP26 } cpp = CPPLatest;

/** --std value given on command line */
std::string stdValue;

bool setC(const std::string& str) {
bool setC(std::string str) {
stdValue = str;
if (str == "c89" || str == "C89") {
c = C89;
return true;
}
if (str == "c99" || str == "C99") {
c = C99;
return true;
}
if (str == "c11" || str == "C11") {
c = C11;
return true;
}
return false;
strTolower(str);
c = getC(str);
return !stdValue.empty() && str == getC();
}
std::string getC() const {
switch (c) {
Expand Down Expand Up @@ -117,6 +107,8 @@ struct Standards {
return "c++20";
case CPP23:
return "c++23";
case CPP26:
return "c++26";
}
return "";
}
Expand All @@ -139,6 +131,9 @@ struct Standards {
if (std == "c++23") {
return Standards::CPP23;
}
if (std == "c++26") {
return Standards::CPP26;
}
return Standards::CPPLatest;
}
};
Expand Down
4 changes: 2 additions & 2 deletions test/fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ class TestFixture : public ErrorLogger {
}

SettingsBuilder& c(Standards::cstd_t std) {
// TODO: CLatest and C11 are the same - handle differently
// TODO: CLatest and C23 are the same - handle differently?
//if (REDUNDANT_CHECK && settings.standards.c == std)
// throw std::runtime_error("redundant setting: standards.c");
settings.standards.c = std;
return *this;
}

SettingsBuilder& cpp(Standards::cppstd_t std) {
// TODO: CPPLatest and CPP20 are the same - handle differently
// TODO: CPPLatest and CPP26 are the same - handle differently?
//if (REDUNDANT_CHECK && settings.standards.cpp == std)
// throw std::runtime_error("redundant setting: standards.cpp");
settings.standards.cpp = std;
Expand Down
3 changes: 1 addition & 2 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ class TestBufferOverrun : public TestFixture {
#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)
void checkP_(const char* file, int line, const char code[], const char* filename = "test.cpp")
{
const Settings settings = settingsBuilder(settings0).severity(Severity::performance)
.c(Standards::CLatest).cpp(Standards::CPPLatest).certainty(Certainty::inconclusive).build();
const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();

std::vector<std::string> files(1, filename);
Tokenizer tokenizer(settings, *this);
Expand Down
4 changes: 2 additions & 2 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,12 +887,12 @@ class TestTokenizer : public TestFixture {
const char code[] = "_Pragma(\"abc\") int x;";
const Settings s_c89 = settingsBuilder().c(Standards::C89).build();
ASSERT_EQUALS("_Pragma ( \"abc\" ) int x ;", tokenizeAndStringify(code, s_c89, false));
const Settings s_clatest = settingsBuilder().c(Standards::CLatest).build();
const Settings s_clatest;
ASSERT_EQUALS("int x ;", tokenizeAndStringify(code, s_clatest, false));

const Settings s_cpp03 = settingsBuilder().cpp(Standards::CPP03).build();
ASSERT_EQUALS("_Pragma ( \"abc\" ) int x ;", tokenizeAndStringify(code, s_cpp03, true));
const Settings s_cpplatest = settingsBuilder().cpp(Standards::CPPLatest).build();
const Settings s_cpplatest;
ASSERT_EQUALS("int x ;", tokenizeAndStringify(code, s_cpplatest, true));
}

Expand Down
2 changes: 1 addition & 1 deletion test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TestVarID : public TestFixture {
TestVarID() : TestFixture("TestVarID") {}

private:
const Settings settings = settingsBuilder().c(Standards::C89).cpp(Standards::CPPLatest).platform(Platform::Type::Unix64).build();
const Settings settings = settingsBuilder().c(Standards::C89).platform(Platform::Type::Unix64).build();
void run() override {
TEST_CASE(varid1);
TEST_CASE(varid2);
Expand Down