naming.py: Fix FP for constructors/destructors (#2375)

This commit is contained in:
Sebastian 2019-11-18 18:41:57 +01:00 committed by GitHub
parent 0dd180d5a2
commit 4f1db90367
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -140,6 +140,8 @@ matrix:
- cd addons/test
- ${CPPCHECK} --dump naming_test.c
- python3 ../naming.py --var='[a-z].*' --function='[a-z].*' naming_test.c.dump
- ${CPPCHECK} --dump naming_test.cpp
- python3 ../naming.py --var='[a-z].*' --function='[a-z].*' naming_test.cpp.dump
- cd ../..
# check addons/namingng.py
- cd addons/test

View File

@ -34,9 +34,11 @@ for arg in sys.argv[1:]:
RE_FUNCTIONNAME = arg[11:]
validate_regex(RE_FUNCTIONNAME)
def reportError(token, severity, msg, errorId):
cppcheckdata.reportError(token, severity, msg, 'naming', errorId)
for arg in sys.argv[1:]:
if not arg.endswith('.dump'):
continue
@ -63,6 +65,9 @@ for arg in sys.argv[1:]:
if RE_FUNCTIONNAME:
for scope in cfg.scopes:
if scope.type == 'Function':
function = scope.function
if function is not None and function.type in ('Constructor', 'Destructor'):
continue
res = re.match(RE_FUNCTIONNAME, scope.className)
if not res:
reportError(

View File

@ -0,0 +1,9 @@
// To test:
// ~/cppcheck/cppcheck --dump naming_test.cpp && python ../naming.py --var='[a-z].*' --function='[a-z].*' naming_test.cpp.dump
// No error for mismatching Constructor/Destructor names should be issued, they can not be changed.
class TestClass1
{
TestClass1() {}
~TestClass1() {}
};