Description
cpplint allows shifting integer literals without spaces around << (for example 10<<20), and to support suffixed literals it strips a trailing integer-literal suffix in CheckOperatorSpacing (cpplint.py:4536):
match = re.search(r"(operator|[^\s(<])(?:L|UL|LL|ULL|l|ul|ll|ull)?<<([^\s,=<])", line)
The suffix alternation includes UL, LL, ULL, ul, ll, ull but omits the standalone unsigned suffix U/u. So 10U<<20 and 10u<<20 are reported as whitespace/operators "Missing spaces around <<", while 10UL<<20, 10LL<<20, 10ULL<<20, 10L<<20, and 10<<20 are all accepted. This is a false positive. The existing tests for 10LL<<20 and 10ULL<<20 (cpplint_unittest.py) confirm the intent is to accept suffixed integer-literal shifts.
Steps to Reproduce
shift.cc:
unsigned a = 10U<<2;
unsigned b = 10UL<<2;
unsigned c = 10<<2;
unsigned d = 10u<<2;
python cpplint.py --filter=-legal/copyright shift.cc
Observed:
shift.cc:1: Missing spaces around << [whitespace/operators] [3]
shift.cc:4: Missing spaces around << [whitespace/operators] [3]
Only the U/u variants are flagged.
Expected Behavior
No whitespace/operators warning for any of these literal-on-literal shifts.
Fix
Add U and u to the suffix alternation.
Description
cpplint allows shifting integer literals without spaces around
<<(for example10<<20), and to support suffixed literals it strips a trailing integer-literal suffix inCheckOperatorSpacing(cpplint.py:4536):The suffix alternation includes
UL,LL,ULL,ul,ll,ullbut omits the standalone unsigned suffixU/u. So10U<<20and10u<<20are reported aswhitespace/operators"Missing spaces around <<", while10UL<<20,10LL<<20,10ULL<<20,10L<<20, and10<<20are all accepted. This is a false positive. The existing tests for10LL<<20and10ULL<<20(cpplint_unittest.py) confirm the intent is to accept suffixed integer-literal shifts.Steps to Reproduce
shift.cc:Observed:
Only the
U/uvariants are flagged.Expected Behavior
No
whitespace/operatorswarning for any of these literal-on-literal shifts.Fix
Add
Uanduto the suffix alternation.