0

Misc. styleguide/PRESUBMIT updates.

The styleguide updates are mostly for consistency. The PRESUBMIT
updates are for both consistency and to ban various
won't-be-allowed-when-we-enable-C++20 constructs (we should ban in
advance of announcing C++20 availability, since all platforms now build
in C++20 mode and it's easy for people to sneak these in).

Bug: 1284275
Change-Id: I8b90c4bbd14dd2202486688220166225eb44cbec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4246721
Owners-Override: danakj <danakj@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1105710}
This commit is contained in:
Peter Kasting
2023-02-15 17:23:08 +00:00
committed by Chromium LUCI CQ
parent 1335117309
commit e2c5ee8cfd
2 changed files with 349 additions and 359 deletions

@ -665,76 +665,18 @@ _BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
['third_party/abseil-cpp/.*_benchmark.cc'],
),
BanRule(
r'/\bstd::stoi\b',
r'/\bstd::sto(i|l|ul|ll|ull)\b',
(
'std::stoi uses exceptions to communicate results. ',
'Use base::StringToInt() instead.',
'std::sto{i,l,ul,ll,ull}() use exceptions to communicate results. ',
'Use base::StringTo[U]Int[64]() instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\bstd::stol\b',
r'/\bstd::sto(f|d|ld)\b',
(
'std::stol uses exceptions to communicate results. ',
'Use base::StringToInt() instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\bstd::stoul\b',
(
'std::stoul uses exceptions to communicate results. ',
'Use base::StringToUint() instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\bstd::stoll\b',
(
'std::stoll uses exceptions to communicate results. ',
'Use base::StringToInt64() instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\bstd::stoull\b',
(
'std::stoull uses exceptions to communicate results. ',
'Use base::StringToUint64() instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\bstd::stof\b',
(
'std::stof uses exceptions to communicate results. ',
'For locale-independent values, e.g. reading numbers from disk',
'profiles, use base::StringToDouble().',
'For user-visible values, parse using ICU.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\bstd::stod\b',
(
'std::stod uses exceptions to communicate results. ',
'For locale-independent values, e.g. reading numbers from disk',
'profiles, use base::StringToDouble().',
'For user-visible values, parse using ICU.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\bstd::stold\b',
(
'std::stold uses exceptions to communicate results. ',
'std::sto{f,d,ld}() use exceptions to communicate results. ',
'For locale-independent values, e.g. reading numbers from disk',
'profiles, use base::StringToDouble().',
'For user-visible values, parse using ICU.',
@ -745,7 +687,7 @@ _BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
BanRule(
r'/\bstd::to_string\b',
(
'std::to_string is locale dependent and slower than alternatives.',
'std::to_string() is locale dependent and slower than alternatives.',
'For locale-independent strings, e.g. writing numbers to disk',
'profiles, use base::NumberToString().',
'For user-visible strings, use base::FormatNumber() and',
@ -757,7 +699,7 @@ _BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
BanRule(
r'/\bstd::shared_ptr\b',
(
'std::shared_ptr should not be used. Use scoped_refptr instead.',
'std::shared_ptr is banned. Use scoped_refptr instead.',
),
True,
[
@ -792,7 +734,7 @@ _BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
BanRule(
r'/\bstd::weak_ptr\b',
(
'std::weak_ptr should not be used. Use base::WeakPtr instead.',
'std::weak_ptr is banned. Use base::WeakPtr instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
@ -800,7 +742,7 @@ _BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
BanRule(
r'/\blong long\b',
(
'long long is banned. Use stdint.h if you need a 64 bit number.',
'long long is banned. Use [u]int64_t instead.',
),
False, # Only a warning since it is already used.
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
@ -808,7 +750,8 @@ _BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
BanRule(
r'/\b(absl|std)::any\b',
(
'absl::any / std::any are not safe to use in a component build.',
'{absl,std}::any are banned due to incompatibility with the component ',
'build.',
),
True,
# Not an error in third party folders, though it probably should be :)
@ -817,8 +760,8 @@ _BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
BanRule(
r'/\bstd::bind\b',
(
'std::bind is banned because of lifetime risks.',
'Use base::BindOnce or base::BindRepeating instead.',
'std::bind() is banned because of lifetime risks. Use ',
'base::Bind{Once,Repeating}() instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
@ -884,10 +827,10 @@ _BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
],
),
BanRule(
r'/\babsl::bind_front\b',
r'/\b(absl,std)::bind_front\b',
(
'absl::bind_front is banned. Use base::BindOnce() or '
'base::BindRepeating() instead.',
'{absl,std}::bind_front() are banned. Use base::Bind{Once,Repeating}() '
'instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
@ -903,7 +846,7 @@ _BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
BanRule(
r'/\babsl::c_',
(
'Abseil container utilities are banned. Use base/ranges/algorithm.h',
'Abseil container utilities are banned. Use base/ranges/algorithm.h ',
'instead.',
),
True,
@ -936,9 +879,10 @@ _BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
),
BanRule(
r'/\babsl::Span\b',
r'/(\babsl::Span\b|#include <span>)',
(
'absl::Span is banned. Use base::span instead.',
'absl::Span is banned and <span> is not allowed yet ',
'(https://crbug.com/1414652). Use base::span instead.',
),
True,
[
@ -964,15 +908,17 @@ _BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
BanRule(
r'/\babsl::StrFormat\b',
(
'absl::StrFormat is banned for now. Use base::StringPrintf instead.',
'absl::StrFormat() is not allowed yet (https://crbug.com/1371963). ',
'Use base::StringPrintf() instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
),
BanRule(
r'/\babsl::string_view\b',
r'/\b(absl|std)::(u16)?string_view\b',
(
'absl::string_view is banned. Use base::StringPiece instead.',
'absl::string_view is banned and std::[u16]string_view are not allowed',
' yet (https://crbug.com/691162). Use base::StringPiece[16] instead.',
),
True,
[
@ -1016,22 +962,22 @@ _BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
BanRule(
r'/\bstd::optional\b',
(
'std::optional is banned. Use absl::optional instead.',
'std::optional is not allowed yet (https://crbug.com/1373619). Use ',
'absl::optional instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
),
BanRule(
r'/\b#include <chrono>\b',
r'/#include <chrono>',
(
'<chrono> overlaps with Time APIs in base. Keep using',
'base classes.',
'<chrono> is banned. Use base/time instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
),
BanRule(
r'/\b#include <exception>\b',
r'/#include <exception>',
(
'Exceptions are banned and disabled in Chromium.',
),
@ -1041,9 +987,7 @@ _BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
BanRule(
r'/\bstd::function\b',
(
'std::function is banned. Instead use base::OnceCallback or ',
'base::RepeatingCallback, which directly support Chromium\'s weak ',
'pointers, ref counting and more.',
'std::function is banned. Use base::{Once,Repeating}Callback instead.',
),
True,
[
@ -1127,16 +1071,15 @@ _BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
],
),
BanRule(
r'/\b#include <random>\b',
r'/#include <random>',
(
'Do not use any random number engines from <random>. Instead',
'use base::RandomBitGenerator.',
'<random> is banned. Use base::RandomBitGenerator instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
),
BanRule(
r'/\b#include <X11/',
r'/#include <X11/',
(
'Do not use Xlib. Use xproto (from //ui/gfx/x:xproto) instead.',
),
@ -1154,44 +1097,92 @@ _BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
BanRule(
r'/\bstd::aligned_alloc\b',
(
'std::aligned_alloc() is not yet approved for use (crbug.com/1412818).',
' Use base::AlignedAlloc() instead.',
'std::aligned_alloc() is not yet allowed (crbug.com/1412818). Use ',
'base::AlignedAlloc() instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\bstd::invoke\b',
r'/\bstd::(u16)?string_view\b',
(
'std::invoke() is not yet approved for use (crbug.com/1412520). Use ',
'base::invoke() instead.',
'std::[u16]string_view is not yet allowed (crbug.com/691162). Use ',
'base::StringPiece[16] instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\bstd::not_fn\b',
r'/#include <(barrier|latch|semaphore|stop_token)>',
(
'std::not_fn() is not yet approved for use (crbug.com/1412529). Use ',
'base::not_fn() instead.',
'The thread support library is banned. Use base/synchronization '
'instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\bstd::string_view\b',
r'/\bstd::(c8rtomb|mbrtoc8)\b',
(
'std::string_view is not yet approved for use (crbug.com/691162). Use ',
'base::StringPiece instead.',
'std::c8rtomb() and std::mbrtoc8() are banned.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\bstd::u16string_view\b',
r'/\bchar8_t|std::u8string\b',
(
'std::u16string_view is not yet approved for use (crbug.com/691162). ',
'Use base::StringPiece16 instead.',
'char8_t and std::u8string are not yet allowed. Can you use [unsigned]',
' char and std::string instead?',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/(\b(co_await|co_return|co_yield)\b|#include <coroutine>)',
(
'Coroutines are not yet allowed (https://crbug.com/1403840).',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\[\[(un)?likely\]\]',
(
'[[likely]] and [[unlikely]] are not yet allowed ',
'(https://crbug.com/1414620). Use [UN]LIKELY instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/#include <format>',
(
'<format> is not yet allowed. Use base::StringPrintf() instead.',
),
True,
[_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.
),
BanRule(
r'/#include <source_location>',
(
'<source_location> is not yet allowed. Use base/location.h instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/#include <syncstream>',
(
'<syncstream> is banned.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.

File diff suppressed because it is too large Load Diff