MCPcopy Index your code
hub / github.com/cpplint/cpplint / CheckForNonStandardConstructs

Function CheckForNonStandardConstructs

cpplint.py:3652–3875  ·  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 c

(filename, clean_lines, linenum, nesting_state, error)

Source from the content-addressed store, hash-verified

3650
3651
3652def CheckForNonStandardConstructs(filename, clean_lines, linenum, nesting_state, error):
3653 r"""Logs an error if we see certain non-ANSI constructs ignored by gcc-2.
3654
3655 Complain about several constructs which gcc-2 accepts, but which are
3656 not standard C++. Warning about these in lint is one way to ease the
3657 transition to new compilers.
3658 - put storage class first (e.g. "static const" instead of "const static").
3659 - "%lld" instead of %qd" in printf-type functions.
3660 - "%1$d" is non-standard in printf-type functions.
3661 - "\%" is an undefined character escape sequence.
3662 - text after #endif is not allowed.
3663 - invalid inner-style forward declaration.
3664 - >? and <? operators, and their >?= and <?= cousins.
3665
3666 Additionally, check for constructor/destructor style violations and reference
3667 members, as it is very convenient to do so while checking for
3668 gcc-2 compliance.
3669
3670 Args:
3671 filename: The name of the current file.
3672 clean_lines: A CleansedLines instance containing the file.
3673 linenum: The number of the line to check.
3674 nesting_state: A NestingState instance which maintains information about
3675 the current stack of nested blocks being parsed.
3676 error: A callable to which errors are reported, which takes 4 arguments:
3677 filename, line number, error level, and message
3678 """
3679
3680 # Remove comments from the line, but leave in strings for now.
3681 line = clean_lines.lines[linenum]
3682
3683 if re.search(r'printf\s*\(.*".*%[-+ ]?\d*q', line):
3684 error(
3685 filename,
3686 linenum,
3687 "runtime/printf_format",
3688 3,
3689 "%q in format strings is deprecated. Use %ll instead.",
3690 )
3691
3692 if re.search(r'printf\s*\(.*".*%\d+\$', line):
3693 error(
3694 filename,
3695 linenum,
3696 "runtime/printf_format",
3697 2,
3698 "%N$ formats are unconventional. Try rewriting to avoid them.",
3699 )
3700
3701 # Remove escaped backslashes before looking for undefined escapes.
3702 line = line.replace("\\\\", "")
3703
3704 if re.search(r'("|\').*\\(%|\[|\(|{)&#x27;, line):
3705 error(
3706 filename,
3707 linenum,
3708 "build/printf_format",
3709 3,

Callers 1

ProcessLineFunction · 0.85

Calls 1

InnermostClassMethod · 0.80

Tested by

no test coverage detected