MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / CheckForNonStandardConstructs

Function CheckForNonStandardConstructs

steps/cpplint.py:3285–3447  ·  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

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

Callers 1

ProcessLineFunction · 0.85

Calls 3

SearchFunction · 0.85
MatchFunction · 0.85
InnermostClassMethod · 0.80

Tested by

no test coverage detected