Skip to content

Commit b756d39

Browse files
authored
cpplint.py: disable obsolete warnings for c++11 and c++14 features (#14320)
1 parent 7184d4b commit b756d39

File tree

1 file changed

+7
-96
lines changed

1 file changed

+7
-96
lines changed

scripts/cpplint.py

Lines changed: 7 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import math # for log
3636
import os
3737
import re
38-
import sre_compile
3938
import string
4039
import sys
4140
import sysconfig
@@ -1028,7 +1027,7 @@ def Match(pattern, s):
10281027
# performance reasons; factoring it out into a separate function turns out
10291028
# to be noticeably expensive.
10301029
if pattern not in _regexp_compile_cache:
1031-
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
1030+
_regexp_compile_cache[pattern] = re.compile(pattern)
10321031
return _regexp_compile_cache[pattern].match(s)
10331032

10341033

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

10521051

10531052
def Search(pattern, s):
10541053
"""Searches the string for the pattern, caching the compiled regexp."""
10551054
if pattern not in _regexp_compile_cache:
1056-
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
1055+
_regexp_compile_cache[pattern] = re.compile(pattern)
10571056
return _regexp_compile_cache[pattern].search(s)
10581057

10591058

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

5359-
if Search(r'\busing namespace\b', line):
5360-
if Search(r'\bliterals\b', line):
5361-
error(filename, linenum, 'build/namespaces_literals', 5,
5362-
'Do not use namespace using-directives. '
5363-
'Use using-declarations instead.')
5364-
else:
5365-
error(filename, linenum, 'build/namespaces', 5,
5366-
'Do not use namespace using-directives. '
5367-
'Use using-declarations instead.')
5358+
if Search(r'\busing namespace\b', line) and not Search(r'\b::\w+_literals\b', line):
5359+
error(filename, linenum, 'build/namespaces', 5,
5360+
'Do not use namespace using-directives. '
5361+
'Use using-declarations instead.')
53685362

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

6323-
def FlagCxx11Features(filename, clean_lines, linenum, error):
6324-
"""Flag those c++11 features that we only allow in certain places.
6325-
6326-
Args:
6327-
filename: The name of the current file.
6328-
clean_lines: A CleansedLines instance containing the file.
6329-
linenum: The number of the line to check.
6330-
error: The function to call with any errors found.
6331-
"""
6332-
line = clean_lines.elided[linenum]
6333-
6334-
include = Match(r'\s*#\s*include\s+[<"]([^<"]+)[">]', line)
6335-
6336-
# Flag unapproved C++ TR1 headers.
6337-
if include and include.group(1).startswith('tr1/'):
6338-
error(filename, linenum, 'build/c++tr1', 5,
6339-
('C++ TR1 headers such as <%s> are unapproved.') % include.group(1))
6340-
6341-
# Flag unapproved C++11 headers.
6342-
if include and include.group(1) in ('cfenv',
6343-
'condition_variable',
6344-
'fenv.h',
6345-
'future',
6346-
'mutex',
6347-
'thread',
6348-
'chrono',
6349-
'ratio',
6350-
'regex',
6351-
'system_error',
6352-
):
6353-
error(filename, linenum, 'build/c++11', 5,
6354-
('<%s> is an unapproved C++11 header.') % include.group(1))
6355-
6356-
# The only place where we need to worry about C++11 keywords and library
6357-
# features in preprocessor directives is in macro definitions.
6358-
if Match(r'\s*#', line) and not Match(r'\s*#\s*define\b', line): return
6359-
6360-
# These are classes and free functions. The classes are always
6361-
# mentioned as std::*, but we only catch the free functions if
6362-
# they're not found by ADL. They're alphabetical by header.
6363-
for top_name in (
6364-
# type_traits
6365-
'alignment_of',
6366-
'aligned_union',
6367-
):
6368-
if Search(r'\bstd::%s\b' % top_name, line):
6369-
error(filename, linenum, 'build/c++11', 5,
6370-
('std::%s is an unapproved C++11 class or function. Send c-style '
6371-
'an example of where it would make your code more readable, and '
6372-
'they may let you use it.') % top_name)
6373-
6374-
6375-
def FlagCxx14Features(filename, clean_lines, linenum, error):
6376-
"""Flag those C++14 features that we restrict.
6377-
6378-
Args:
6379-
filename: The name of the current file.
6380-
clean_lines: A CleansedLines instance containing the file.
6381-
linenum: The number of the line to check.
6382-
error: The function to call with any errors found.
6383-
"""
6384-
line = clean_lines.elided[linenum]
6385-
6386-
include = Match(r'\s*#\s*include\s+[<"]([^<"]+)[">]', line)
6387-
6388-
# Flag unapproved C++14 headers.
6389-
if include and include.group(1) in ('scoped_allocator', 'shared_mutex'):
6390-
error(filename, linenum, 'build/c++14', 5,
6391-
('<%s> is an unapproved C++14 header.') % include.group(1))
6392-
6393-
# These are classes and free functions with abseil equivalents.
6394-
for top_name in (
6395-
# memory
6396-
'make_unique',
6397-
):
6398-
if Search(r'\bstd::%s\b' % top_name, line):
6399-
error(filename, linenum, 'build/c++14', 5,
6400-
'std::%s does not exist in C++11. Use absl::%s instead.' %
6401-
(top_name, top_name))
6402-
6403-
64046317
def ProcessFileData(filename, file_extension, lines, error,
64056318
extra_check_functions=None):
64066319
"""Performs lint checks and reports any errors to the given error function.
@@ -6437,8 +6350,6 @@ def ProcessFileData(filename, file_extension, lines, error,
64376350
ProcessLine(filename, file_extension, clean_lines, line,
64386351
include_state, function_state, nesting_state, error,
64396352
extra_check_functions)
6440-
FlagCxx11Features(filename, clean_lines, line, error)
6441-
FlagCxx14Features(filename, clean_lines, line, error)
64426353
nesting_state.CheckCompletedBlocks(filename, error)
64436354

64446355
CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error)

0 commit comments

Comments
 (0)