diff options
author | Daniel Moody <daniel.moody@mongodb.com> | 2023-01-17 10:56:30 -0600 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-01-20 23:56:24 +0000 |
commit | f295f411cfa181bef2792909e32fe857d7f1c2ce (patch) | |
tree | bd25bbd4c74bb15bef3ef2719aaca48867e40e49 /buildscripts | |
parent | 3ba868bd5c52de01872fa8d9ee128bb13e18c0f7 (diff) | |
download | mongo-f295f411cfa181bef2792909e32fe857d7f1c2ce.tar.gz |
SERVER-72935 switch c stdlib headers to cpp compat stdlib headers
Diffstat (limited to 'buildscripts')
-rw-r--r-- | buildscripts/linter/simplecpplint.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/buildscripts/linter/simplecpplint.py b/buildscripts/linter/simplecpplint.py index 1cea1f59e92..e3c3685a6c1 100644 --- a/buildscripts/linter/simplecpplint.py +++ b/buildscripts/linter/simplecpplint.py @@ -80,6 +80,16 @@ GENERIC_FCV = [ _RE_GENERIC_FCV_REF = re.compile(r'(' + '|'.join(GENERIC_FCV) + r')\b') _RE_HEADER = re.compile(r'\.(h|hpp)$') +_CXX_COMPAT_HEADERS = [ + "assert", "ctype", "errno", "fenv", "float", "inttypes", "limits", "locale", "math", "setjmp", + "signal", "stdarg", "stddef", "stdint", "stdio", "stdlib", "string", "time", "uchar", "wchar", + "wctype" +] + +# Successful matches `m` have a `m["base"]`, the basename of the file that was included. +_RE_CXX_COMPAT_HEADERS = re.compile( + rf'# *include *((<)|("))(?P<base>{"|".join(_CXX_COMPAT_HEADERS)})\.h(?(2)>|")') + class Linter: """Simple C++ Linter.""" @@ -159,6 +169,7 @@ class Linter: self._check_for_collection_sharding_runtime(linenum) self._check_for_uninterruptible_lock_guard(linenum) self._check_for_rand(linenum) + self._check_for_c_stdlib_headers(linenum) # Relax the rule of commenting generic FCV references for files directly related to FCV # implementations. @@ -375,6 +386,15 @@ class Linter: 'Please add a comment containing "(Generic FCV reference):" within 10 lines ' + 'before the generic FCV reference.') + def _check_for_c_stdlib_headers(self, linenum): + line = self.clean_lines[linenum] + + if match := _RE_CXX_COMPAT_HEADERS.match(line): + self._error( + linenum, 'mongodb/headers', + f"Prohibited include of C header '<{match['base']}.h>'. " \ + f"Include C++ header '<c{match['base']}>' instead.") + def _error(self, linenum, category, message): if linenum in self.nolint_suppression: return |