Skip to content

Commit 191f339

Browse files
authored
added preliminary support for newer standards / some cleanups (#6423)
1 parent b17a347 commit 191f339

8 files changed

Lines changed: 102 additions & 42 deletions

File tree

gui/mainwindow.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,16 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
264264
mUI->mActionC89->setActionGroup(mCStandardActions);
265265
mUI->mActionC99->setActionGroup(mCStandardActions);
266266
mUI->mActionC11->setActionGroup(mCStandardActions);
267+
//mUI->mActionC17->setActionGroup(mCStandardActions);
268+
//mUI->mActionC23->setActionGroup(mCStandardActions);
267269

268270
mUI->mActionCpp03->setActionGroup(mCppStandardActions);
269271
mUI->mActionCpp11->setActionGroup(mCppStandardActions);
270272
mUI->mActionCpp14->setActionGroup(mCppStandardActions);
271273
mUI->mActionCpp17->setActionGroup(mCppStandardActions);
272274
mUI->mActionCpp20->setActionGroup(mCppStandardActions);
273275
//mUI->mActionCpp23->setActionGroup(mCppStandardActions);
276+
//mUI->mActionCpp26->setActionGroup(mCppStandardActions);
274277

275278
mUI->mActionEnforceC->setActionGroup(mSelectLanguageActions);
276279
mUI->mActionEnforceCpp->setActionGroup(mSelectLanguageActions);
@@ -374,13 +377,16 @@ void MainWindow::loadSettings()
374377
mUI->mActionC89->setChecked(standards.c == Standards::C89);
375378
mUI->mActionC99->setChecked(standards.c == Standards::C99);
376379
mUI->mActionC11->setChecked(standards.c == Standards::C11);
380+
//mUI->mActionC17->setChecked(standards.c == Standards::C17);
381+
//mUI->mActionC23->setChecked(standards.c == Standards::C23);
377382
standards.setCPP(mSettings->value(SETTINGS_STD_CPP, QString()).toString().toStdString());
378383
mUI->mActionCpp03->setChecked(standards.cpp == Standards::CPP03);
379384
mUI->mActionCpp11->setChecked(standards.cpp == Standards::CPP11);
380385
mUI->mActionCpp14->setChecked(standards.cpp == Standards::CPP14);
381386
mUI->mActionCpp17->setChecked(standards.cpp == Standards::CPP17);
382387
mUI->mActionCpp20->setChecked(standards.cpp == Standards::CPP20);
383388
//mUI->mActionCpp23->setChecked(standards.cpp == Standards::CPP23);
389+
//mUI->mActionCpp26->setChecked(standards.cpp == Standards::CPP26);
384390

385391
// Main window settings
386392
const bool showMainToolbar = mSettings->value(SETTINGS_TOOLBARS_MAIN_SHOW, true).toBool();
@@ -452,6 +458,10 @@ void MainWindow::saveSettings() const
452458
mSettings->setValue(SETTINGS_STD_C, "C99");
453459
if (mUI->mActionC11->isChecked())
454460
mSettings->setValue(SETTINGS_STD_C, "C11");
461+
//if (mUI->mActionC17->isChecked())
462+
// mSettings->setValue(SETTINGS_STD_C, "C17");
463+
//if (mUI->mActionC23->isChecked())
464+
// mSettings->setValue(SETTINGS_STD_C, "C23");
455465

456466
if (mUI->mActionCpp03->isChecked())
457467
mSettings->setValue(SETTINGS_STD_CPP, "C++03");
@@ -465,6 +475,8 @@ void MainWindow::saveSettings() const
465475
mSettings->setValue(SETTINGS_STD_CPP, "C++20");
466476
//if (mUI.mActionCpp23->isChecked())
467477
// mSettings->setValue(SETTINGS_STD_CPP, "C++23");
478+
//if (mUI.mActionCpp26->isChecked())
479+
// mSettings->setValue(SETTINGS_STD_CPP, "C++26");
468480

469481
// Main window settings
470482
mSettings->setValue(SETTINGS_TOOLBARS_MAIN_SHOW, mUI->mToolBarMain->isVisible());

gui/mainwindow.ui

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
<addaction name="mActionCpp17"/>
204204
<addaction name="mActionCpp20"/>
205205
<!--addaction name="mActionCpp23"/-->
206+
<!--addaction name="mActionCpp26"/-->
206207
</widget>
207208
<widget class="QMenu" name="menuC_standard">
208209
<property name="title">
@@ -211,6 +212,8 @@
211212
<addaction name="mActionC89"/>
212213
<addaction name="mActionC99"/>
213214
<addaction name="mActionC11"/>
215+
<!--addaction name="mActionC17"/-->
216+
<!--addaction name="mActionC23"/-->
214217
</widget>
215218
<addaction name="mActionAnalyzeFiles"/>
216219
<addaction name="mActionAnalyzeDirectory"/>
@@ -794,6 +797,22 @@
794797
<string>C&amp;11</string>
795798
</property>
796799
</action>
800+
<!--action name="mActionC17">
801+
<property name="checkable">
802+
<bool>true</bool>
803+
</property>
804+
<property name="text">
805+
<string>C&amp;17</string>
806+
</property>
807+
</action-->
808+
<!--action name="mActionC23">
809+
<property name="checkable">
810+
<bool>true</bool>
811+
</property>
812+
<property name="text">
813+
<string>C&amp;23</string>
814+
</property>
815+
</action-->
797816
<action name="mActionC89">
798817
<property name="checkable">
799818
<bool>true</bool>
@@ -915,6 +934,17 @@
915934
<string>C++23</string>
916935
</property>
917936
</action-->
937+
<!--action name="mActionCpp26">
938+
<property name="checkable">
939+
<bool>true</bool>
940+
</property>
941+
<property name="checked">
942+
<bool>true</bool>
943+
</property>
944+
<property name="text">
945+
<string>C++26</string>
946+
</property>
947+
</action-->
918948
<action name="mActionComplianceReport">
919949
<property name="text">
920950
<string>Compliance report...</string>

lib/keywords.cpp

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,17 @@
3434
#define C11_KEYWORDS \
3535
"_Alignas", "_Alignof", "_Atomic", "_Generic", "_Noreturn", "_Static_assert", "_Thread_local"
3636

37-
#ifdef __clang__
38-
#pragma clang diagnostic push
39-
#pragma clang diagnostic ignored "-Wunused-macros"
40-
#endif
41-
4237
#define C23_KEYWORDS \
4338
"alignas", "alignof", "bool", "constexpr", "false", "nullptr", "static_assert", "thread_local", "true", "typeof", "typeof_unqual", \
4439
"_BitInt", "_Decimal128", "_Decimal32", "_Decimal64"
4540

46-
#ifdef __clang__
47-
#pragma clang diagnostic pop
48-
#endif
49-
5041
static const std::unordered_set<std::string> c89_keywords_all = {
5142
C90_KEYWORDS
5243
};
5344

54-
static const std::unordered_set<std::string> c89_keywords = c89_keywords_all;
45+
static const std::unordered_set<std::string> c89_keywords = {
46+
C90_KEYWORDS
47+
};
5548

5649
static const std::unordered_set<std::string> c99_keywords_all = {
5750
C90_KEYWORDS, C99_KEYWORDS
@@ -69,6 +62,13 @@ static const std::unordered_set<std::string> c11_keywords = {
6962
C11_KEYWORDS
7063
};
7164

65+
static const std::unordered_set<std::string> c17_keywords_all = {
66+
C90_KEYWORDS, C99_KEYWORDS, C11_KEYWORDS
67+
};
68+
69+
static const std::unordered_set<std::string> c17_keywords = {
70+
};
71+
7272
static const std::unordered_set<std::string> c23_keywords_all = {
7373
C90_KEYWORDS, C99_KEYWORDS, C11_KEYWORDS, C23_KEYWORDS
7474
};
@@ -118,7 +118,9 @@ static const std::unordered_set<std::string> cpp03_keywords_all = {
118118
CPP03_KEYWORDS
119119
};
120120

121-
static const std::unordered_set<std::string> cpp03_keywords = cpp03_keywords_all;
121+
static const std::unordered_set<std::string> cpp03_keywords = {
122+
CPP03_KEYWORDS
123+
};
122124

123125
static const std::unordered_set<std::string> cpp11_keywords_all = {
124126
CPP03_KEYWORDS, CPP11_KEYWORDS
@@ -128,13 +130,19 @@ static const std::unordered_set<std::string> cpp11_keywords = {
128130
CPP11_KEYWORDS
129131
};
130132

131-
static const std::unordered_set<std::string> cpp14_keywords_all = cpp11_keywords_all;
133+
static const std::unordered_set<std::string> cpp14_keywords_all = {
134+
CPP03_KEYWORDS, CPP11_KEYWORDS
135+
};
132136

133-
static const std::unordered_set<std::string> cpp14_keywords;
137+
static const std::unordered_set<std::string> cpp14_keywords = {
138+
};
134139

135-
static const std::unordered_set<std::string> cpp17_keywords_all = cpp11_keywords_all;
140+
static const std::unordered_set<std::string> cpp17_keywords_all = {
141+
CPP03_KEYWORDS, CPP11_KEYWORDS
142+
};
136143

137-
static const std::unordered_set<std::string> cpp17_keywords;
144+
static const std::unordered_set<std::string> cpp17_keywords = {
145+
};
138146

139147
static const std::unordered_set<std::string> cpp20_keywords_all = {
140148
CPP03_KEYWORDS, CPP11_KEYWORDS, CPP20_KEYWORDS
@@ -144,9 +152,19 @@ static const std::unordered_set<std::string> cpp20_keywords = {
144152
CPP20_KEYWORDS
145153
};
146154

147-
static const std::unordered_set<std::string> cpp23_keywords;
155+
static const std::unordered_set<std::string> cpp23_keywords = {
156+
};
157+
158+
static const std::unordered_set<std::string> cpp23_keywords_all = {
159+
CPP03_KEYWORDS, CPP11_KEYWORDS, CPP20_KEYWORDS
160+
};
161+
162+
static const std::unordered_set<std::string> cpp26_keywords = {
163+
};
148164

149-
static const std::unordered_set<std::string> cpp23_keywords_all = cpp20_keywords_all;
165+
static const std::unordered_set<std::string> cpp26_keywords_all = {
166+
CPP03_KEYWORDS, CPP11_KEYWORDS, CPP20_KEYWORDS
167+
};
150168

151169
// cppcheck-suppress unusedFunction
152170
const std::unordered_set<std::string>& Keywords::getAll(Standards::cstd_t cStd)
@@ -158,8 +176,9 @@ const std::unordered_set<std::string>& Keywords::getAll(Standards::cstd_t cStd)
158176
case Standards::cstd_t::C99:
159177
return c99_keywords_all;
160178
case Standards::cstd_t::C11:
161-
case Standards::cstd_t::C17:
162179
return c11_keywords_all;
180+
case Standards::cstd_t::C17:
181+
return c17_keywords_all;
163182
case Standards::cstd_t::C23:
164183
return c23_keywords_all;
165184
}
@@ -182,6 +201,8 @@ const std::unordered_set<std::string>& Keywords::getAll(Standards::cppstd_t cppS
182201
return cpp20_keywords_all;
183202
case Standards::cppstd_t::CPP23:
184203
return cpp23_keywords_all;
204+
case Standards::cppstd_t::CPP26:
205+
return cpp26_keywords_all;
185206
}
186207
cppcheck::unreachable();
187208
}
@@ -196,10 +217,11 @@ const std::unordered_set<std::string>& Keywords::getOnly(Standards::cstd_t cStd)
196217
case Standards::cstd_t::C99:
197218
return c99_keywords;
198219
case Standards::cstd_t::C11:
199-
case Standards::cstd_t::C17:
200220
return c11_keywords;
221+
case Standards::cstd_t::C17:
222+
return c17_keywords;
201223
case Standards::cstd_t::C23:
202-
return c23_keywords_all;
224+
return c23_keywords;
203225
}
204226
cppcheck::unreachable();
205227
}
@@ -221,6 +243,8 @@ const std::unordered_set<std::string>& Keywords::getOnly(Standards::cppstd_t cpp
221243
return cpp20_keywords;
222244
case Standards::cppstd_t::CPP23:
223245
return cpp23_keywords;
246+
case Standards::cppstd_t::CPP26:
247+
return cpp26_keywords;
224248
}
225249
cppcheck::unreachable();
226250
}

lib/standards.h

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,16 @@ struct Standards {
4040
enum cstd_t { C89, C99, C11, C17, C23, CLatest = C23 } c = CLatest;
4141

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

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

48-
bool setC(const std::string& str) {
48+
bool setC(std::string str) {
4949
stdValue = str;
50-
if (str == "c89" || str == "C89") {
51-
c = C89;
52-
return true;
53-
}
54-
if (str == "c99" || str == "C99") {
55-
c = C99;
56-
return true;
57-
}
58-
if (str == "c11" || str == "C11") {
59-
c = C11;
60-
return true;
61-
}
62-
return false;
50+
strTolower(str);
51+
c = getC(str);
52+
return !stdValue.empty() && str == getC();
6353
}
6454
std::string getC() const {
6555
switch (c) {
@@ -117,6 +107,8 @@ struct Standards {
117107
return "c++20";
118108
case CPP23:
119109
return "c++23";
110+
case CPP26:
111+
return "c++26";
120112
}
121113
return "";
122114
}
@@ -139,6 +131,9 @@ struct Standards {
139131
if (std == "c++23") {
140132
return Standards::CPP23;
141133
}
134+
if (std == "c++26") {
135+
return Standards::CPP26;
136+
}
142137
return Standards::CPPLatest;
143138
}
144139
};

test/fixture.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ class TestFixture : public ErrorLogger {
193193
}
194194

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

203203
SettingsBuilder& cpp(Standards::cppstd_t std) {
204-
// TODO: CPPLatest and CPP20 are the same - handle differently
204+
// TODO: CPPLatest and CPP26 are the same - handle differently?
205205
//if (REDUNDANT_CHECK && settings.standards.cpp == std)
206206
// throw std::runtime_error("redundant setting: standards.cpp");
207207
settings.standards.cpp = std;

test/testbufferoverrun.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ class TestBufferOverrun : public TestFixture {
7777
#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)
7878
void checkP_(const char* file, int line, const char code[], const char* filename = "test.cpp")
7979
{
80-
const Settings settings = settingsBuilder(settings0).severity(Severity::performance)
81-
.c(Standards::CLatest).cpp(Standards::CPPLatest).certainty(Certainty::inconclusive).build();
80+
const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();
8281

8382
std::vector<std::string> files(1, filename);
8483
Tokenizer tokenizer(settings, *this);

test/testtokenize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,12 +887,12 @@ class TestTokenizer : public TestFixture {
887887
const char code[] = "_Pragma(\"abc\") int x;";
888888
const Settings s_c89 = settingsBuilder().c(Standards::C89).build();
889889
ASSERT_EQUALS("_Pragma ( \"abc\" ) int x ;", tokenizeAndStringify(code, s_c89, false));
890-
const Settings s_clatest = settingsBuilder().c(Standards::CLatest).build();
890+
const Settings s_clatest;
891891
ASSERT_EQUALS("int x ;", tokenizeAndStringify(code, s_clatest, false));
892892

893893
const Settings s_cpp03 = settingsBuilder().cpp(Standards::CPP03).build();
894894
ASSERT_EQUALS("_Pragma ( \"abc\" ) int x ;", tokenizeAndStringify(code, s_cpp03, true));
895-
const Settings s_cpplatest = settingsBuilder().cpp(Standards::CPPLatest).build();
895+
const Settings s_cpplatest;
896896
ASSERT_EQUALS("int x ;", tokenizeAndStringify(code, s_cpplatest, true));
897897
}
898898

test/testvarid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class TestVarID : public TestFixture {
3535
TestVarID() : TestFixture("TestVarID") {}
3636

3737
private:
38-
const Settings settings = settingsBuilder().c(Standards::C89).cpp(Standards::CPPLatest).platform(Platform::Type::Unix64).build();
38+
const Settings settings = settingsBuilder().c(Standards::C89).platform(Platform::Type::Unix64).build();
3939
void run() override {
4040
TEST_CASE(varid1);
4141
TEST_CASE(varid2);

0 commit comments

Comments
 (0)