forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow most of <ranges> but explicitly ban views
Change-Id: I67befc6d5cc18ab3ce43e6e3a1ad68f8dba878fd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5668999 Commit-Queue: Daniel Cheng <[email protected]> Reviewed-by: Peter Kasting <[email protected]> Cr-Commit-Position: refs/heads/main@{#1323174}
- Loading branch information
1 parent
e437f89
commit 8971922
Showing
3 changed files
with
274 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1301,11 +1301,196 @@ class BanRule: | |
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders. | ||
), | ||
BanRule( | ||
r'/#include <ranges>', | ||
('<ranges> is not yet allowed. Use base/ranges/algorithm.h instead.', | ||
), | ||
True, | ||
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders. | ||
pattern='std::views', | ||
explanation=( | ||
'Use of std::views is banned in Chrome. If you need this ' | ||
'functionality, please contact [email protected].', | ||
), | ||
treat_as_error=True, | ||
excluded_paths=[ | ||
# Don't warn in third_party folders. | ||
_THIRD_PARTY_EXCEPT_BLINK | ||
], | ||
), | ||
BanRule( | ||
# Ban everything except specifically allowlisted constructs. | ||
pattern=r'/std::ranges::(?!' + '|'.join(( | ||
# From https://en.cppreference.com/w/cpp/ranges: | ||
# Range access | ||
'begin', | ||
'end', | ||
'cbegin', | ||
'cend', | ||
'rbegin', | ||
'rend', | ||
'crbegin', | ||
'crend', | ||
'size', | ||
'ssize', | ||
'empty', | ||
'data', | ||
'cdata', | ||
# Range primitives | ||
'iterator_t', | ||
'const_iterator_t', | ||
'sentinel_t', | ||
'const_sentinel_t', | ||
'range_difference_t', | ||
'range_size_t', | ||
'range_value_t', | ||
'range_reference_t', | ||
'range_const_reference_t', | ||
'range_rvalue_reference_t', | ||
'range_common_reference_t', | ||
# Dangling iterator handling | ||
'dangling', | ||
'borrowed_iterator_t', | ||
# Banned: borrowed_subrange_t | ||
# Range concepts | ||
'range', | ||
'borrowed_range', | ||
'sized_range', | ||
'view', | ||
'input_range', | ||
'output_range', | ||
'forward_range', | ||
'bidirectional_range', | ||
'random_access_range', | ||
'contiguous_range', | ||
'common_range', | ||
'viewable_range', | ||
'constant_range', | ||
# Banned: Views | ||
# Banned: Range factories | ||
# Banned: Range adaptors | ||
# From https://en.cppreference.com/w/cpp/algorithm/ranges: | ||
# Constrained algorithms: non-modifying sequence operations | ||
'all_of', | ||
'any_of', | ||
'none_of', | ||
'for_each', | ||
'for_each_n', | ||
'count', | ||
'count_if', | ||
'mismatch', | ||
'equal', | ||
'lexicographical_compare', | ||
'find', | ||
'find_if', | ||
'find_if_not', | ||
'find_end', | ||
'find_first_of', | ||
'adjacent_find', | ||
'search', | ||
'search_n', | ||
# Constrained algorithms: modifying sequence operations | ||
'copy', | ||
'copy_if', | ||
'copy_n', | ||
'copy_backward', | ||
'move', | ||
'move_backward', | ||
'fill', | ||
'fill_n', | ||
'transform', | ||
'generate', | ||
'generate_n', | ||
'remove', | ||
'remove_if', | ||
'remove_copy', | ||
'remove_copy_if', | ||
'replace', | ||
'replace_if', | ||
'replace_copy', | ||
'replace_copy_if', | ||
'swap_ranges', | ||
'reverse', | ||
'reverse_copy', | ||
'rotate', | ||
'rotate_copy', | ||
'shuffle', | ||
'sample', | ||
'unique', | ||
'unique_copy', | ||
# Constrained algorithms: partitioning operations | ||
'is_partitioned', | ||
'partition', | ||
'partition_copy', | ||
'stable_partition', | ||
'partition_point', | ||
# Constrained algorithms: sorting operations | ||
'is_sorted', | ||
'is_sorted_until', | ||
'sort', | ||
'partial_sort', | ||
'partial_sort_copy', | ||
'stable_sort', | ||
'nth_element', | ||
# Constrained algorithms: binary search operations (on sorted ranges) | ||
'lower_bound', | ||
'upper_bound', | ||
'binary_search', | ||
'equal_range', | ||
# Constrained algorithms: set operations (on sorted ranges) | ||
'merge', | ||
'inplace_merge', | ||
'includes', | ||
'set_difference', | ||
'set_intersection', | ||
'set_symmetric_difference', | ||
'set_union', | ||
# Constrained algorithms: heap operations | ||
'is_heap', | ||
'is_heap_until', | ||
'make_heap', | ||
'push_heap', | ||
'pop_heap', | ||
'sort_heap', | ||
# Constrained algorithms: minimum/maximum operations | ||
'max', | ||
'max_element', | ||
'min', | ||
'min_element', | ||
'minmax', | ||
'minmax_element', | ||
'clamp', | ||
# Constrained algorithms: permutation operations | ||
'is_permutation', | ||
'next_permutation', | ||
'prev_premutation', | ||
# Constrained uninitialized memory algorithms | ||
'uninitialized_copy', | ||
'uninitialized_copy_n', | ||
'uninitialized_fill', | ||
'uninitialized_fill_n', | ||
'uninitialized_move', | ||
'uninitialized_move_n', | ||
'uninitialized_default_construct', | ||
'uninitialized_default_construct_n', | ||
'uninitialized_value_construct', | ||
'uninitialized_value_construct_n', | ||
'destroy', | ||
'destroy_n', | ||
'destroy_at', | ||
'construct_at', | ||
# Return types | ||
'in_fun_result', | ||
'in_in_result', | ||
'in_out_result', | ||
'in_in_out_result', | ||
'in_out_out_result', | ||
'min_max_result', | ||
'in_found_result', | ||
)) + r')\w+', | ||
explanation=( | ||
'Use of range views and associated helpers is banned in Chrome. ' | ||
'If you need this functionality, please contact [email protected].', | ||
), | ||
treat_as_error=True, | ||
excluded_paths=[ | ||
# Don't warn in third_party folders. | ||
_THIRD_PARTY_EXCEPT_BLINK | ||
], | ||
), | ||
BanRule( | ||
r'/#include <source_location>', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters