MCPcopy Create free account
hub / github.com/BVLC/caffe / CheckForNonStandardConstructs

Function CheckForNonStandardConstructs

scripts/cpp_lint.py:2198–2302  ·  view source on GitHub ↗

r"""Logs an error if we see certain non-ANSI constructs ignored by gcc-2. Complain about several constructs which gcc-2 accepts, but which are not standard C++. Warning about these in lint is one way to ease the transition to new compilers. - put storage class first (e.g. "static const" in

(filename, clean_lines, linenum,
                                  nesting_state, error)

Source from the content-addressed store, hash-verified

2196
2197
2198def CheckForNonStandardConstructs(filename, clean_lines, linenum,
2199 nesting_state, error):
2200 r"""Logs an error if we see certain non-ANSI constructs ignored by gcc-2.
2201
2202 Complain about several constructs which gcc-2 accepts, but which are
2203 not standard C++. Warning about these in lint is one way to ease the
2204 transition to new compilers.
2205 - put storage class first (e.g. "static const" instead of "const static").
2206 - "%lld" instead of %qd" in printf-type functions.
2207 - "%1$d" is non-standard in printf-type functions.
2208 - "\%" is an undefined character escape sequence.
2209 - text after #endif is not allowed.
2210 - invalid inner-style forward declaration.
2211 - >? and <? operators, and their >?= and <?= cousins.
2212
2213 Additionally, check for constructor/destructor style violations and reference
2214 members, as it is very convenient to do so while checking for
2215 gcc-2 compliance.
2216
2217 Args:
2218 filename: The name of the current file.
2219 clean_lines: A CleansedLines instance containing the file.
2220 linenum: The number of the line to check.
2221 nesting_state: A _NestingState instance which maintains information about
2222 the current stack of nested blocks being parsed.
2223 error: A callable to which errors are reported, which takes 4 arguments:
2224 filename, line number, error level, and message
2225 """
2226
2227 # Remove comments from the line, but leave in strings for now.
2228 line = clean_lines.lines[linenum]
2229
2230 if Search(r'printf\s*\(.*".*%[-+ ]?\d*q', line):
2231 error(filename, linenum, 'runtime/printf_format', 3,
2232 '%q in format strings is deprecated. Use %ll instead.')
2233
2234 if Search(r'printf\s*\(.*".*%\d+\$', line):
2235 error(filename, linenum, 'runtime/printf_format', 2,
2236 '%N$ formats are unconventional. Try rewriting to avoid them.')
2237
2238 # Remove escaped backslashes before looking for undefined escapes.
2239 line = line.replace('\\\\', '')
2240
2241 if Search(r'("|\').*\\(%|\[|\(|{)&#x27;, line):
2242 error(filename, linenum, 'build/printf_format', 3,
2243 '%, [, (, and { are undefined character escapes. Unescape them.')
2244
2245 # For the rest, work with both comments and strings removed.
2246 line = clean_lines.elided[linenum]
2247
2248 if Search(r'\b(const|volatile|void|char|short|int|long'
2249 r'|float|double|signed|unsigned'
2250 r'|schar|u?int8|u?int16|u?int32|u?int64)'
2251 r'\s+(register|static|extern|typedef)\b',
2252 line):
2253 error(filename, linenum, 'build/storage_class', 5,
2254 'Storage class (static, extern, typedef, etc) should be first.')
2255

Callers 1

ProcessLineFunction · 0.85

Calls 3

SearchFunction · 0.85
MatchFunction · 0.85
InnermostClassMethod · 0.80

Tested by

no test coverage detected