Skip to content

Commit 4f1db90

Browse files
authored
naming.py: Fix FP for constructors/destructors (#2375)
1 parent 0dd180d commit 4f1db90

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ matrix:
140140
- cd addons/test
141141
- ${CPPCHECK} --dump naming_test.c
142142
- python3 ../naming.py --var='[a-z].*' --function='[a-z].*' naming_test.c.dump
143+
- ${CPPCHECK} --dump naming_test.cpp
144+
- python3 ../naming.py --var='[a-z].*' --function='[a-z].*' naming_test.cpp.dump
143145
- cd ../..
144146
# check addons/namingng.py
145147
- cd addons/test

addons/naming.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ def validate_regex(expr):
3434
RE_FUNCTIONNAME = arg[11:]
3535
validate_regex(RE_FUNCTIONNAME)
3636

37+
3738
def reportError(token, severity, msg, errorId):
3839
cppcheckdata.reportError(token, severity, msg, 'naming', errorId)
3940

41+
4042
for arg in sys.argv[1:]:
4143
if not arg.endswith('.dump'):
4244
continue
@@ -63,6 +65,9 @@ def reportError(token, severity, msg, errorId):
6365
if RE_FUNCTIONNAME:
6466
for scope in cfg.scopes:
6567
if scope.type == 'Function':
68+
function = scope.function
69+
if function is not None and function.type in ('Constructor', 'Destructor'):
70+
continue
6671
res = re.match(RE_FUNCTIONNAME, scope.className)
6772
if not res:
6873
reportError(

addons/test/naming_test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// To test:
2+
// ~/cppcheck/cppcheck --dump naming_test.cpp && python ../naming.py --var='[a-z].*' --function='[a-z].*' naming_test.cpp.dump
3+
4+
// No error for mismatching Constructor/Destructor names should be issued, they can not be changed.
5+
class TestClass1
6+
{
7+
TestClass1() {}
8+
~TestClass1() {}
9+
};

0 commit comments

Comments
 (0)