Commit 693f5ad9 authored by Vladimir Levin's avatar Vladimir Levin Committed by Commit Bot

Remove blink style presubmit check about mixing unsigned and bool bitfields.

Since we don't support MSVC, and since it seems that's the only compiler
that causes inefficient packing, I think we can remove the presubmit check
that enforces no mixing of unsigned and bool bitfields.

R=pdr@chromium.org, wangxianzhu@chromium.org

Change-Id: I176bded0da8fe5430029044ff96ec497ee28b999
Reviewed-on: https://chromium-review.googlesource.com/1250051Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Reviewed-by: default avatarXianzhu Wang <wangxianzhu@chromium.org>
Commit-Queue: vmpstr <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594901}
parent 9803c0eb
...@@ -1123,16 +1123,6 @@ def check_for_non_standard_constructs(clean_lines, line_number, ...@@ -1123,16 +1123,6 @@ def check_for_non_standard_constructs(clean_lines, line_number,
'The class %s probably needs a virtual destructor due to ' 'The class %s probably needs a virtual destructor due to '
'having virtual method(s), one declared at line %d.' 'having virtual method(s), one declared at line %d.'
% (classinfo.name, classinfo.virtual_method_line_number)) % (classinfo.name, classinfo.virtual_method_line_number))
# Look for mixed bool and unsigned bitfields.
if classinfo.bool_bitfields and classinfo.unsigned_bitfields:
bool_list = ', '.join(classinfo.bool_bitfields)
unsigned_list = ', '.join(classinfo.unsigned_bitfields)
error(classinfo.line_number, 'runtime/bitfields', 5,
'The class %s contains mixed unsigned and bool bitfields, '
'which will pack into separate words on the MSVC compiler.\n'
'Bool bitfields are [%s].\nUnsigned bitfields are [%s].\n'
'Consider converting bool bitfields to unsigned.'
% (classinfo.name, bool_list, unsigned_list))
else: else:
classinfo.brace_depth = brace_depth classinfo.brace_depth = brace_depth
......
...@@ -1506,51 +1506,6 @@ class CppStyleTest(CppStyleTestBase): ...@@ -1506,51 +1506,6 @@ class CppStyleTest(CppStyleTestBase):
self.assert_lint('long int a : 30;', errmsg) self.assert_lint('long int a : 30;', errmsg)
self.assert_lint('int a = 1 ? 0 : 30;', '') self.assert_lint('int a = 1 ? 0 : 30;', '')
# A mixture of unsigned and bool bitfields in a class will generate a warning.
def test_mixing_unsigned_bool_bitfields(self):
def errmsg(bool_bitfields, unsigned_bitfields, name):
bool_list = ', '.join(bool_bitfields)
unsigned_list = ', '.join(unsigned_bitfields)
return ('The class %s contains mixed unsigned and bool bitfields, '
'which will pack into separate words on the MSVC compiler.\n'
'Bool bitfields are [%s].\nUnsigned bitfields are [%s].\n'
'Consider converting bool bitfields to unsigned. [runtime/bitfields] [5]'
% (name, bool_list, unsigned_list))
def build_test_case(bitfields, name, will_warn, extra_warnings=None):
bool_bitfields = []
unsigned_bitfields = []
test_string = 'class %s {\n' % (name,)
line = 2
for bitfield in bitfields:
test_string += ' %s %s : %d;\n' % bitfield
if bitfield[0] == 'bool':
bool_bitfields.append('%d: %s' % (line, bitfield[1]))
elif bitfield[0].startswith('unsigned'):
unsigned_bitfields.append('%d: %s' % (line, bitfield[1]))
line += 1
test_string += '}\n'
error = ''
if will_warn:
error = errmsg(bool_bitfields, unsigned_bitfields, name)
if extra_warnings and error:
error = extra_warnings + [error]
self.assert_multi_line_lint(test_string, error)
build_test_case([('bool', 'm_boolMember', 4), ('unsigned', 'm_unsignedMember', 3)],
'MyClass', True)
build_test_case([('bool', 'm_boolMember', 4), ('bool', 'm_anotherBool', 3)],
'MyClass', False)
build_test_case([('unsigned', 'm_unsignedMember', 4), ('unsigned', 'm_anotherUnsigned', 3)],
'MyClass', False)
self.assert_multi_line_lint('class NoProblemsHere {\n'
' bool m_boolMember;\n'
' unsigned m_unsignedMember;\n'
' unsigned m_bitField1 : 1;\n'
' unsigned m_bitField4 : 4;\n'
'}\n', '')
# Bitfields which are not declared unsigned or bool will generate a warning. # Bitfields which are not declared unsigned or bool will generate a warning.
def test_unsigned_bool_bitfields(self): def test_unsigned_bool_bitfields(self):
def errmsg(member, name, bit_type): def errmsg(member, name, bit_type):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment