MCPcopy Create free account
hub / github.com/apache/mesos / CheckForNonStandardConstructs

Function CheckForNonStandardConstructs

support/cpplint.py:2783–2940  ·  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

2781
2782
2783def CheckForNonStandardConstructs(filename, clean_lines, linenum,
2784 nesting_state, error):
2785 r"""Logs an error if we see certain non-ANSI constructs ignored by gcc-2.
2786
2787 Complain about several constructs which gcc-2 accepts, but which are
2788 not standard C++. Warning about these in lint is one way to ease the
2789 transition to new compilers.
2790 - put storage class first (e.g. "static const" instead of "const static").
2791 - "%lld" instead of %qd" in printf-type functions.
2792 - "%1$d" is non-standard in printf-type functions.
2793 - "\%" is an undefined character escape sequence.
2794 - text after #endif is not allowed.
2795 - invalid inner-style forward declaration.
2796 - >? and <? operators, and their >?= and <?= cousins.
2797
2798 Additionally, check for constructor/destructor style violations and reference
2799 members, as it is very convenient to do so while checking for
2800 gcc-2 compliance.
2801
2802 Args:
2803 filename: The name of the current file.
2804 clean_lines: A CleansedLines instance containing the file.
2805 linenum: The number of the line to check.
2806 nesting_state: A NestingState instance which maintains information about
2807 the current stack of nested blocks being parsed.
2808 error: A callable to which errors are reported, which takes 4 arguments:
2809 filename, line number, error level, and message
2810 """
2811
2812 # Remove comments from the line, but leave in strings for now.
2813 line = clean_lines.lines[linenum]
2814
2815 if Search(r'printf\s*\(.*".*%[-+ ]?\d*q', line):
2816 error(filename, linenum, 'runtime/printf_format', 3,
2817 '%q in format strings is deprecated. Use %ll instead.')
2818
2819 if Search(r'printf\s*\(.*".*%\d+\$', line):
2820 error(filename, linenum, 'runtime/printf_format', 2,
2821 '%N$ formats are unconventional. Try rewriting to avoid them.')
2822
2823 # Remove escaped backslashes before looking for undefined escapes.
2824 line = line.replace('\\\\', '')
2825
2826 if Search(r'("|\').*\\(%|\[|\(|{)&#x27;, line):
2827 error(filename, linenum, 'build/printf_format', 3,
2828 '%, [, (, and { are undefined character escapes. Unescape them.')
2829
2830 # For the rest, work with both comments and strings removed.
2831 line = clean_lines.elided[linenum]
2832
2833 if Search(r'\b(const|volatile|void|char|short|int|long'
2834 r'|float|double|signed|unsigned'
2835 r'|schar|u?int8|u?int16|u?int32|u?int64)'
2836 r'\s+(register|static|extern|typedef)\b',
2837 line):
2838 error(filename, linenum, 'build/storage_class', 5,
2839 'Storage-class specifier (static, extern, typedef, etc) should be '
2840 'at the beginning of the declaration.')

Callers 1

ProcessLineFunction · 0.85

Calls 5

SearchFunction · 0.85
errorFunction · 0.85
MatchFunction · 0.85
InnermostClassMethod · 0.80
countMethod · 0.45

Tested by

no test coverage detected