Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Unified Diff: third_party/WebKit/Tools/Scripts/webkitpy/style/checkers/cpp.py

Issue 2200053002: Add TypeTraits template for checking safe bitfields (WIP) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@_make_visibility_enum_class_rebase
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/TypeTraits.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Tools/Scripts/webkitpy/style/checkers/cpp.py
diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/style/checkers/cpp.py b/third_party/WebKit/Tools/Scripts/webkitpy/style/checkers/cpp.py
index c5fda9168636112c7124549b5cda3057896c9446..cfe3302ec2ea733a1ea9e6d26183ecc1d7422368 100644
--- a/third_party/WebKit/Tools/Scripts/webkitpy/style/checkers/cpp.py
+++ b/third_party/WebKit/Tools/Scripts/webkitpy/style/checkers/cpp.py
@@ -1493,10 +1493,22 @@ def check_for_non_standard_constructs(clean_lines, line_number,
classinfo.name.startswith('Expected')):
args = match(r'\s*(\S+)\s+(\S+)\s*:\s*\d+\s*;', line)
if args:
- error(line_number, 'runtime/bitfields', 4,
- 'Member %s of class %s defined as a bitfield of type %s. '
- 'Please declare all bitfields as unsigned.'
- % (args.group(2), classinfo.name, args.group(1)))
+ field_type = args.group(1)
+ field_name = args.group(2)
+
+ # Look for an unsigned assert for this type in this file.
+ has_assert = False
+ for other_line in clean_lines.lines:
+ if match(r'\bstatic_assert(\s*IsEnumSafeToStoreInBitfield\s*<\s*(\S+)?' + field_type + r'>::value\s*);', other_line):
+ has_assert = True
+ break
+
+ if not has_assert:
+ error(line_number, 'runtime/bitfields', 4,
+ 'Member %s of class %s defined as a bitfield of type %s. '
+ 'Please declare all bitfields as unsigned, or add '
+ 'static_assert(IsEnumSafeToStoreInBitfield<%s>::value).'
+ % (field_name, classinfo.name, field_type, field_type))
def check_spacing_for_function_call(line, line_number, error):
« no previous file with comments | « third_party/WebKit/Source/wtf/TypeTraits.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698