Skip to content

cpplint.py: disable obsolete warnings for c++11 and c++14 features #14320

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 18 commits into from
Jan 13, 2025
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b55ee13
cpplint.py: remove c++11 lint checks, as the floor is c++14 (and has …
dconeybe Jan 8, 2025
aebe23e
also remove c++14 warnings
dconeybe Jan 8, 2025
7800770
Merge remote-tracking branch 'origin/main' into RemoveCpp11LintChecks
dconeybe Jan 10, 2025
e3aa90f
cpplint.py: actually remove the c++11 and C++14 checks.
dconeybe Jan 10, 2025
e2031c7
cpplint.py: remove usages of the deprecated sre_compile Python module.
dconeybe Jan 10, 2025
73e74cf
cpplint.py: relax checks for "using namespace" declarations for impor…
dconeybe Jan 10, 2025
bb3b0f3
.github/workflows/firestore.yml: run Firestore tests when cpplint.py …
dconeybe Jan 10, 2025
0b737db
Revert ".github/workflows/firestore.yml: run Firestore tests when cpp…
dconeybe Jan 10, 2025
fb7df47
scripts/check.sh: run lint on _ALL_ files if cpplint.py itself changed.
dconeybe Jan 10, 2025
bd0a6d8
scripts/check.sh: fix check of base branch
dconeybe Jan 10, 2025
7435976
scripts/check.sh: more fixes
dconeybe Jan 10, 2025
1685499
scripts/check.sh: try again
dconeybe Jan 10, 2025
a1bf8c0
scripts/check.sh: also check for changes to cpplint.py
dconeybe Jan 10, 2025
4c80660
Merge remote-tracking branch 'origin/main' into RemoveCpp11LintChecks
dconeybe Jan 10, 2025
167b427
cpplint.py: add back error categories: build/c++11, build/c++14, buil…
dconeybe Jan 10, 2025
a209bd4
scripts/check.sh: remove my changes since I'm not entirely convinced …
dconeybe Jan 13, 2025
d2f0c10
Merge remote-tracking branch 'origin/main' into RemoveCpp11LintChecks
dconeybe Jan 13, 2025
6a5c600
scripts/cpplint.py: add back build/namespaces_literals so that cpplin…
dconeybe Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 7 additions & 96 deletions scripts/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import math # for log
import os
import re
import sre_compile
import string
import sys
import sysconfig
Expand Down Expand Up @@ -1028,7 +1027,7 @@ def Match(pattern, s):
# performance reasons; factoring it out into a separate function turns out
# to be noticeably expensive.
if pattern not in _regexp_compile_cache:
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
_regexp_compile_cache[pattern] = re.compile(pattern)
return _regexp_compile_cache[pattern].match(s)


Expand All @@ -1046,14 +1045,14 @@ def ReplaceAll(pattern, rep, s):
string with replacements made (or original string if no replacements)
"""
if pattern not in _regexp_compile_cache:
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
_regexp_compile_cache[pattern] = re.compile(pattern)
return _regexp_compile_cache[pattern].sub(rep, s)


def Search(pattern, s):
"""Searches the string for the pattern, caching the compiled regexp."""
if pattern not in _regexp_compile_cache:
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
_regexp_compile_cache[pattern] = re.compile(pattern)
return _regexp_compile_cache[pattern].search(s)


Expand Down Expand Up @@ -5356,15 +5355,10 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
'Did you mean "memset(%s, 0, %s)"?'
% (match.group(1), match.group(2)))

if Search(r'\busing namespace\b', line):
if Search(r'\bliterals\b', line):
error(filename, linenum, 'build/namespaces_literals', 5,
'Do not use namespace using-directives. '
'Use using-declarations instead.')
else:
error(filename, linenum, 'build/namespaces', 5,
'Do not use namespace using-directives. '
'Use using-declarations instead.')
if Search(r'\busing namespace\b', line) and not Search(r'\b::\w+_literals\b', line):
error(filename, linenum, 'build/namespaces', 5,
'Do not use namespace using-directives. '
'Use using-declarations instead.')

# Detect variable-length arrays.
match = Match(r'\s*(.+::)?(\w+) [a-z]\w*\[(.+)];', line)
Expand Down Expand Up @@ -6320,87 +6314,6 @@ def ProcessLine(filename, file_extension, clean_lines, line,
for check_fn in extra_check_functions:
check_fn(filename, clean_lines, line, error)

def FlagCxx11Features(filename, clean_lines, linenum, error):
"""Flag those c++11 features that we only allow in certain places.

Args:
filename: The name of the current file.
clean_lines: A CleansedLines instance containing the file.
linenum: The number of the line to check.
error: The function to call with any errors found.
"""
line = clean_lines.elided[linenum]

include = Match(r'\s*#\s*include\s+[<"]([^<"]+)[">]', line)

# Flag unapproved C++ TR1 headers.
if include and include.group(1).startswith('tr1/'):
error(filename, linenum, 'build/c++tr1', 5,
('C++ TR1 headers such as <%s> are unapproved.') % include.group(1))

# Flag unapproved C++11 headers.
if include and include.group(1) in ('cfenv',
'condition_variable',
'fenv.h',
'future',
'mutex',
'thread',
'chrono',
'ratio',
'regex',
'system_error',
):
error(filename, linenum, 'build/c++11', 5,
('<%s> is an unapproved C++11 header.') % include.group(1))

# The only place where we need to worry about C++11 keywords and library
# features in preprocessor directives is in macro definitions.
if Match(r'\s*#', line) and not Match(r'\s*#\s*define\b', line): return

# These are classes and free functions. The classes are always
# mentioned as std::*, but we only catch the free functions if
# they're not found by ADL. They're alphabetical by header.
for top_name in (
# type_traits
'alignment_of',
'aligned_union',
):
if Search(r'\bstd::%s\b' % top_name, line):
error(filename, linenum, 'build/c++11', 5,
('std::%s is an unapproved C++11 class or function. Send c-style '
'an example of where it would make your code more readable, and '
'they may let you use it.') % top_name)


def FlagCxx14Features(filename, clean_lines, linenum, error):
"""Flag those C++14 features that we restrict.

Args:
filename: The name of the current file.
clean_lines: A CleansedLines instance containing the file.
linenum: The number of the line to check.
error: The function to call with any errors found.
"""
line = clean_lines.elided[linenum]

include = Match(r'\s*#\s*include\s+[<"]([^<"]+)[">]', line)

# Flag unapproved C++14 headers.
if include and include.group(1) in ('scoped_allocator', 'shared_mutex'):
error(filename, linenum, 'build/c++14', 5,
('<%s> is an unapproved C++14 header.') % include.group(1))

# These are classes and free functions with abseil equivalents.
for top_name in (
# memory
'make_unique',
):
if Search(r'\bstd::%s\b' % top_name, line):
error(filename, linenum, 'build/c++14', 5,
'std::%s does not exist in C++11. Use absl::%s instead.' %
(top_name, top_name))


def ProcessFileData(filename, file_extension, lines, error,
extra_check_functions=None):
"""Performs lint checks and reports any errors to the given error function.
Expand Down Expand Up @@ -6437,8 +6350,6 @@ def ProcessFileData(filename, file_extension, lines, error,
ProcessLine(filename, file_extension, clean_lines, line,
include_state, function_state, nesting_state, error,
extra_check_functions)
FlagCxx11Features(filename, clean_lines, line, error)
FlagCxx14Features(filename, clean_lines, line, error)
nesting_state.CheckCompletedBlocks(filename, error)

CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error)
Expand Down
Loading