Skip to content

Commit cca158f

Browse files
authored
Fix #14467 (Premium: unusedLabel is not activated as expected by --premium=misra-c-20xx) (danmar#8186)
1 parent fac75a1 commit cca158f

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3692,7 +3692,7 @@ void CheckOther::checkUnusedLabel()
36923692

36933693
void CheckOther::unusedLabelError(const Token* tok, bool inSwitch, bool hasIfdef)
36943694
{
3695-
if (tok && !mSettings->severity.isEnabled(inSwitch ? Severity::warning : Severity::style))
3695+
if (tok && !mSettings->severity.isEnabled(inSwitch ? Severity::warning : Severity::style) && !mSettings->isPremiumEnabled("unusedLabel"))
36963696
return;
36973697

36983698
std::string id = "unusedLabel";

test/testother.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ class TestOther : public TestFixture {
261261
TEST_CASE(testUnusedLabel);
262262
TEST_CASE(testUnusedLabelConfiguration);
263263
TEST_CASE(testUnusedLabelSwitchConfiguration);
264+
TEST_CASE(testUnusedLabelPremiumMisra);
264265

265266
TEST_CASE(testEvaluationOrder);
266267
TEST_CASE(testEvaluationOrderSelfAssignment);
@@ -352,10 +353,6 @@ class TestOther : public TestFixture {
352353
}
353354
else {
354355
settings = opt.settings;
355-
settings->severity.enable(Severity::style);
356-
settings->severity.enable(Severity::warning);
357-
settings->severity.enable(Severity::portability);
358-
settings->severity.enable(Severity::performance);
359356
}
360357
settings->certainty.setEnabled(Certainty::inconclusive, opt.inconclusive);
361358
settings->verbose = opt.verbose;
@@ -2784,11 +2781,11 @@ class TestOther : public TestFixture {
27842781
"};\n"
27852782
"void f(X x) {}";
27862783

2787-
/*const*/ Settings s32 = settingsBuilder(settings0).platform(Platform::Type::Unix32).build();
2784+
/*const*/ Settings s32 = settingsBuilder(settings1).platform(Platform::Type::Unix32).build();
27882785
check(code, dinit(CheckOptions, $.settings = &s32));
27892786
ASSERT_EQUALS("[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\n", errout_str());
27902787

2791-
/*const*/ Settings s64 = settingsBuilder(settings0).platform(Platform::Type::Unix64).build();
2788+
/*const*/ Settings s64 = settingsBuilder(settings1).platform(Platform::Type::Unix64).build();
27922789
check(code, dinit(CheckOptions, $.settings = &s64));
27932790
ASSERT_EQUALS("", errout_str());
27942791
}
@@ -5562,7 +5559,7 @@ class TestOther : public TestFixture {
55625559
" <arg nr=\"1\"/>\n"
55635560
" </function>\n"
55645561
"</def>";
5565-
/*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();
5562+
/*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).severity(Severity::style).build();
55665563

55675564
check("void foo() {\n"
55685565
" exit(0);\n"
@@ -7456,7 +7453,7 @@ class TestOther : public TestFixture {
74567453
" <arg nr=\"2\"/>\n"
74577454
" </function>\n"
74587455
"</def>";
7459-
/*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).build();
7456+
/*const*/ Settings settings = settingsBuilder().libraryxml(xmldata).severity(Severity::style).build();
74607457

74617458
check("void foo() {\n"
74627459
" if (x() || x()) {}\n"
@@ -8164,7 +8161,7 @@ class TestOther : public TestFixture {
81648161
const char code[] = "void foo(bool flag) {\n"
81658162
" bar( (flag) ? ~0u : ~0ul);\n"
81668163
"}";
8167-
/*const*/ Settings settings = settings0;
8164+
/*const*/ Settings settings = settings1;
81688165
settings.platform.sizeof_int = 4;
81698166
settings.platform.int_bit = 32;
81708167

@@ -11932,6 +11929,19 @@ class TestOther : public TestFixture {
1193211929
errout_str());
1193311930
}
1193411931

11932+
void testUnusedLabelPremiumMisra() { // #14467 - enable unusedLabel with --premium=misra-c-20xx flag
11933+
Settings s;
11934+
check("void f() {\n"
11935+
" label:\n"
11936+
"}", dinit(CheckOptions, $.settings = &s));
11937+
ASSERT_EQUALS("", errout_str());
11938+
s.premiumArgs = "--premium=misra-c-2012"; // <- activates unusedLabel checking
11939+
check("void f() {\n"
11940+
" label:\n"
11941+
"}", dinit(CheckOptions, $.settings = &s));
11942+
ASSERT_EQUALS("[test.cpp:2:5]: (style) Label 'label' is not used. [unusedLabel]\n", errout_str());
11943+
}
11944+
1193511945
// TODO: only used in a single place
1193611946
#define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)
1193711947
template<size_t size>

0 commit comments

Comments
 (0)