Skip to content

Commit 840e71f

Browse files
committed
test+fix
1 parent 803fdfe commit 840e71f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
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/cli/premium_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,16 @@ def test_hash(tmpdir):
199199

200200
_, _, stderr = cppcheck(args)
201201
assert '<error id="a-id" severity="error" msg="bug" verbose="bug" hash="123" ' in stderr
202+
203+
204+
def test_misra_unusedLabel(tmpdir):
205+
""" #14467 - unusedLabel should be activated by --premium=misra-c-20xx """
206+
test_file = os.path.join(tmpdir, 'test.c')
207+
with open(test_file, 'wt') as f:
208+
f.write('void foo() {\n'
209+
'L1:\n'
210+
'}\n')
211+
212+
exe = __copy_cppcheck_premium(tmpdir)
213+
_, _, stderr = cppcheck(['--premium=misra-c-2012', 'test.c'], cppcheck_exe=exe, cwd=tmpdir)
214+
assert "test.c:2:1: style: Label 'L1' is not used. [unusedLabel]" in stderr

0 commit comments

Comments
 (0)