misra: When checking C++ code only activate certain misra c++ compliant rules. It will be supported to run the addon on C++ code.

This commit is contained in:
Daniel Marjamäki 2022-06-06 22:22:52 +02:00
parent 52453947c8
commit ec13f5fe5c
2 changed files with 7 additions and 3 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3
#
# MISRA C 2012 checkers
# Partially reused for "MISRA C++ 2008" checking
#
# Example usage of this addon (scan a sourcefile main.cpp)
# cppcheck --dump main.cpp
@ -4208,6 +4209,7 @@ class MisraChecker:
:param args: Check function arguments
"""
if not self.isRuleGloballySuppressed(rule_num):
if (not self.is_cpp) or rule_num in (202,203,1901):
check_function(*args)
def parseDump(self, dumpfile):
@ -4249,6 +4251,8 @@ class MisraChecker:
else:
self.printStatus('Checking ' + dumpfile + '...')
self.is_cpp = data.files and data.files[0].endswith('.cpp')
for cfgNumber, cfg in enumerate(data.iterconfigurations()):
if not self.settings.quiet:
self.printStatus('Checking %s, config %s...' % (dumpfile, cfg.name))

View File

@ -7,7 +7,7 @@ class C {
class misra_21_1_C {
public:
misra_21_1_C operator=(const misra_21_1_C &); // 8.2
misra_21_1_C operator=(const misra_21_1_C &);
};
class C2 {
@ -20,6 +20,6 @@ C2::C2(void) : f(NULL) {}
static void test_misra_21_1_crash(void)
{
auto misra_21_1_C a, b; // 12.3
auto misra_21_1_C a, b;
a = b;
}