0

Add PRESUBMIT ban for user-defined literals from the standard library

Though provide an escape hatch for code that wants to define string
or string_view literals with embedded NULs, since the alternatives are
generally worse.

Bug: 364348894
Change-Id: Id94373d671dd85b467aef1de3a76a923e1419355
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5839557
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1351687}
This commit is contained in:
Daniel Cheng
2024-09-05 21:39:28 +00:00
committed by Chromium LUCI CQ
parent b8a39c6944
commit ddde13afff

@ -2105,6 +2105,33 @@ _BANNED_CPP_FUNCTIONS: Sequence[BanRule] = (
),
treat_as_error=False,
),
BanRule(
pattern=r'/\bstd::(literals|string_literals|string_view_literals)\b',
explanation = (
'User-defined literals are banned by the Google C++ style guide. '
'Exceptions are provided in Chrome for string and string_view '
'literals that embed \\0.',
),
treat_as_error=True,
excluded_paths=(
# Various tests or test helpers that embed NUL in strings or
# string_views.
r'^ash/components/arc/session/serial_number_util_unittest\.cc',
r'^base/strings/string_util_unittest\.cc',
r'^base/strings/utf_string_conversions_unittest\.cc',
r'^chrome/browser/ash/crosapi/browser_data_back_migrator_unittest\.cc',
r'^chrome/browser/ash/crosapi/browser_data_migrator_util_unittest\.cc',
r'^chrome/browser/ash/crosapi/move_migrator_unittest\.cc',
r'^components/history/core/browser/visit_annotations_database\.cc',
r'^components/history/core/browser/visit_annotations_database_unittest\.cc',
r'^components/os_crypt/sync/os_crypt_unittest\.cc',
r'^components/password_manager/core/browser/credentials_cleaner_unittest\.cc',
r'^content/browser/file_system_access/file_system_access_file_writer_impl_unittest\.cc',
r'^net/cookies/parsed_cookie_unittest\.cc',
r'^third_party/blink/renderer/modules/webcodecs/test_helpers\.cc',
r'^third_party/blink/renderer/modules/websockets/websocket_channel_impl_test\.cc',
),
)
)
_DEPRECATED_SYNC_CONSENT_FUNCTION_WARNING = (