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)
| 3272 | |
| 3273 | |
| 3274 | def CheckForNonStandardConstructs(filename, clean_lines, linenum, |
| 3275 | nesting_state, error): |
| 3276 | r"""Logs an error if we see certain non-ANSI constructs ignored by gcc-2. |
| 3277 | |
| 3278 | Complain about several constructs which gcc-2 accepts, but which are |
| 3279 | not standard C++. Warning about these in lint is one way to ease the |
| 3280 | transition to new compilers. |
| 3281 | - put storage class first (e.g. "static const" instead of "const static"). |
| 3282 | - "%lld" instead of %qd" in printf-type functions. |
| 3283 | - "%1$d" is non-standard in printf-type functions. |
| 3284 | - "\%" is an undefined character escape sequence. |
| 3285 | - text after #endif is not allowed. |
| 3286 | - invalid inner-style forward declaration. |
| 3287 | - >? and <? operators, and their >?= and <?= cousins. |
| 3288 | |
| 3289 | Additionally, check for constructor/destructor style violations and reference |
| 3290 | members, as it is very convenient to do so while checking for |
| 3291 | gcc-2 compliance. |
| 3292 | |
| 3293 | Args: |
| 3294 | filename: The name of the current file. |
| 3295 | clean_lines: A CleansedLines instance containing the file. |
| 3296 | linenum: The number of the line to check. |
| 3297 | nesting_state: A NestingState instance which maintains information about |
| 3298 | the current stack of nested blocks being parsed. |
| 3299 | error: A callable to which errors are reported, which takes 4 arguments: |
| 3300 | filename, line number, error level, and message |
| 3301 | """ |
| 3302 | |
| 3303 | # Remove comments from the line, but leave in strings for now. |
| 3304 | line = clean_lines.lines[linenum] |
| 3305 | |
| 3306 | if Search(r'printf\s*\(.*".*%[-+ ]?\d*q', line): |
| 3307 | error(filename, linenum, 'runtime/printf_format', 3, |
| 3308 | '%q in format strings is deprecated. Use %ll instead.') |
| 3309 | |
| 3310 | if Search(r'printf\s*\(.*".*%\d+\$', line): |
| 3311 | error(filename, linenum, 'runtime/printf_format', 2, |
| 3312 | '%N$ formats are unconventional. Try rewriting to avoid them.') |
| 3313 | |
| 3314 | # Remove escaped backslashes before looking for undefined escapes. |
| 3315 | line = line.replace('\\\\', '') |
| 3316 | |
| 3317 | if Search(r'("|\').*\\(%|\[|\(|{)', line): |
| 3318 | error(filename, linenum, 'build/printf_format', 3, |
| 3319 | '%, [, (, and { are undefined character escapes. Unescape them.') |
| 3320 | |
| 3321 | # For the rest, work with both comments and strings removed. |
| 3322 | line = clean_lines.elided[linenum] |
| 3323 | |
| 3324 | if Search(r'\b(const|volatile|void|char|short|int|long' |
| 3325 | r'|float|double|signed|unsigned' |
| 3326 | r'|schar|u?int8|u?int16|u?int32|u?int64)' |
| 3327 | r'\s+(register|static|extern|typedef)\b', |
| 3328 | line): |
| 3329 | error(filename, linenum, 'build/storage_class', 5, |
| 3330 | 'Storage-class specifier (static, extern, typedef, etc) should be ' |
| 3331 | 'at the beginning of the declaration.') |
no test coverage detected