0

Formally ban absl::optional.

It has been superseded by std::optional.

(Also removes some PRESUBMITs against StringPiece while I'm touching
that block, since that's gone too.)

Bug: 40288126
Change-Id: I8941f1bb75652a4bbb50e95026ea9b6d0ea5ecda
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5805666
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Owners-Override: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1345168}
This commit is contained in:
Peter Kasting
2024-08-22 00:22:26 +00:00
committed by Chromium LUCI CQ
parent 651fc14186
commit 3b77a0cc23
21 changed files with 47 additions and 27 deletions
DEPSPRESUBMIT.py
ash
assistant
constants
chrome/installer/setup
chromeos
ash
components
attestation
audio
cryptohome
dbus
login
auth
integrity
session
network
tpm
services
recording
components
onc
dbus
components/cronet/tools/generators
sandbox/linux
styleguide/c++
ui/events/keycodes

1
DEPS

@ -5036,6 +5036,7 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]

@ -1010,6 +1010,14 @@ _BANNED_CPP_FUNCTIONS: Sequence[BanRule] = (
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
),
BanRule(
pattern=
r'/\babsl::(optional|nullopt|make_optional)\b',
explanation=('absl::optional is banned. Use std::optional instead.', ),
treat_as_error=True,
excluded_paths=[
_THIRD_PARTY_EXCEPT_BLINK,
]),
BanRule(
r'/(\babsl::Span\b|#include <span>|\bstd::span\b)',
(
@ -1981,27 +1989,6 @@ _BANNED_CPP_FUNCTIONS: Sequence[BanRule] = (
'^chrome/browser/about_flags.cc',
'^chrome/browser/web_applications/isolated_web_apps/isolated_web_app_features.cc',
)),
BanRule(
pattern=
r'/\babsl::(optional|nullopt|make_optional|in_place|in_place_t)\b',
explanation=('Don\'t use `absl::optional`. Use `std::optional`.', ),
# TODO(b/40288126): Enforce after completing the rewrite.
treat_as_error=False,
excluded_paths=[
_THIRD_PARTY_EXCEPT_BLINK,
]),
BanRule(
pattern=r'(base::)?\bStringPiece\b',
explanation=(
'Don\'t use `base::StringPiece`. Use `std::string_view`.', ),
treat_as_error=False,
),
BanRule(
pattern=r'(base::)?\bStringPiece16\b',
explanation=(
'Don\'t use `base::StringPiece16`. Use `std::u16string_view`.', ),
treat_as_error=False,
),
BanRule(
pattern='/(CUIAutomation|AccessibleObjectFromWindow)',
explanation=

@ -48,6 +48,7 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]

@ -29,6 +29,7 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]

@ -348,9 +348,7 @@ bool CreateVisualElementsManifest(const base::FilePath& src_path,
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Returns a CommandLine to run if os_update_handler.exe should be run,
// i.e.. a Windows update has been detected, absl::nullopt otherwise.
// Use the Windows version update string set by Omaha on the command line
// as the version update string to pass to os_update_handler.exe.
// i.e. a Windows update has been detected; null otherwise.
std::optional<base::CommandLine> GetOsUpdateHandlerCommand(
const base::FilePath& target_path,
const std::wstring& installed_version,
@ -359,6 +357,8 @@ std::optional<base::CommandLine> GetOsUpdateHandlerCommand(
if (args.size() != 1) {
return std::nullopt;
}
// Use the Windows version update string set by Omaha on the command line
// as the version update string to pass to os_update_handler.exe.
base::CommandLine os_update_handler_cmd(
target_path.Append(installed_version).Append(kOsUpdateHandlerExe));
InstallUtil::AppendModeAndChannelSwitches(&os_update_handler_cmd);

@ -31,6 +31,7 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]

@ -39,5 +39,6 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]

@ -32,6 +32,7 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]

@ -42,5 +42,6 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]

@ -46,5 +46,6 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]

@ -33,5 +33,6 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]

@ -30,6 +30,7 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]

@ -59,6 +59,7 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]

@ -30,6 +30,7 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]

@ -40,6 +40,7 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]

@ -31,5 +31,6 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]

@ -35,5 +35,6 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]

@ -543,7 +543,7 @@ class Generator(generator.Generator):
def _GetCppWrapperType(self, kind, add_same_module_namespaces=False):
def _AddOptional(type_name):
return "absl::optional<%s>" % type_name
return "std::optional<%s>" % type_name
if self._IsTypemappedKind(kind):
type_name = self._GetNativeTypeName(kind)

@ -22,5 +22,4 @@ include_rules = [
"+sandbox/sandbox_export.h",
# Everyone can use tests/
"+sandbox/linux/tests",
'+third_party/abseil-cpp/absl/types/optional.h',
]

@ -1753,7 +1753,8 @@ Banned since workaround for lack of RTTI
absl::bind_front
```
**Description:** Binds the first N arguments of an invocable object and stores them by value.
**Description:** Binds the first N arguments of an invocable object and stores
them by value.
**Documentation:**
* [bind_front.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/functional/bind_front.h)
@ -1859,6 +1860,23 @@ invocable type.
[Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/JVN4E4IIYA0)
***
### Optional <sup>[banned]</sup>
```c++
absl::optional<int> Func(bool b) {
return b ? absl::make_optional(1) : abl::nullopt;
}
```
**Description:** Early adaptation of C++17 `std::optional`.
**Documentation:** [std::optional](https://en.cppreference.com/w/cpp/utility/optional)
**Notes:**
*** promo
Superseded by `std::optional`. Use `std::optional` instead.
***
### Random <sup>[banned]</sup>
```c++

@ -32,5 +32,6 @@ include_rules = [
'-third_party/abseil-cpp/absl/synchronization',
'-third_party/abseil-cpp/absl/time',
'-third_party/abseil-cpp/absl/types/any.h',
'-third_party/abseil-cpp/absl/types/optional.h',
'-third_party/abseil-cpp/absl/types/span.h',
]