MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / CheckForNonStandardConstructs

Function CheckForNonStandardConstructs

src/tests/coding/cpplint.py:3271–3433  ·  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

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

Callers 1

ProcessLineFunction · 0.85

Calls 7

SearchFunction · 0.85
InnermostClassMethod · 0.80
countMethod · 0.80
MatchFunction · 0.70
replaceMethod · 0.45
splitMethod · 0.45
groupMethod · 0.45

Tested by

no test coverage detected