From 4f1db90367bf5cbd360fc65779cc4895d36632f3 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 18 Nov 2019 18:41:57 +0100 Subject: [PATCH] naming.py: Fix FP for constructors/destructors (#2375) --- .travis.yml | 2 ++ addons/naming.py | 5 +++++ addons/test/naming_test.cpp | 9 +++++++++ 3 files changed, 16 insertions(+) create mode 100644 addons/test/naming_test.cpp diff --git a/.travis.yml b/.travis.yml index ef3120e2b..eb1706c47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/addons/naming.py b/addons/naming.py index 6037fab66..6322c95f8 100755 --- a/addons/naming.py +++ b/addons/naming.py @@ -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( diff --git a/addons/test/naming_test.cpp b/addons/test/naming_test.cpp new file mode 100644 index 000000000..1c5bf3826 --- /dev/null +++ b/addons/test/naming_test.cpp @@ -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() {} +};