Skip to content

Commit

Permalink
Fixes for C++20 support.
Browse files Browse the repository at this point in the history
* Structs with user-declared constructors are no longer aggregates.
  Delete the declarations.
* u8"" no longer produces const char*.  Change to "", which also accepts
  UTF-8 literals.  This requires a few follow-on conversions/casts.
* Math between disparate enums is deprecated.  Use constexprs.
* Various algorithms' lambdas must fit tighter constraints.  Add consts.
* Remove some unnecessary qualifications in preparations for later
  constexpr changes.
* std::iterator is removed.  Expose the type aliases directly.
* Types on both sides of comparison operators should be the same.

Bug: 1284275
Change-Id: Icaed9c2ec7d914cc5aba156133ea34152d8ca606
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3632589
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Ted Choc <tedchoc@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1001773}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed May 10, 2022
1 parent 12e032c commit 6a1c295
Show file tree
Hide file tree
Showing 22 changed files with 60 additions and 80 deletions.
4 changes: 0 additions & 4 deletions components/autofill/core/browser/form_data_importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ class FormDataImporter {
// Metadata about the import, used for metric collection in
// ProfileImportProcess after the user's decision.
ProfileImportMetadata import_metadata;
AddressProfileImportCandidate(AddressProfileImportCandidate&& other) =
default;
AddressProfileImportCandidate& operator=(
AddressProfileImportCandidate&& other) = default;
};

// Scans the given |form| for importable Autofill data. If the form includes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ enum class CardUnmaskChallengeOptionType {
// The struct used by Autofill components to represent a card unmask challenge
// option.
struct CardUnmaskChallengeOption {
CardUnmaskChallengeOption() = default;
CardUnmaskChallengeOption(const CardUnmaskChallengeOption&) = default;
~CardUnmaskChallengeOption() = default;
CardUnmaskChallengeOption& operator=(const CardUnmaskChallengeOption&) =
default;

// The unique identifier for the challenge option.
std::string id = std::string();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ class CreditCardFIDOAuthenticator
// The response of FIDO authentication, including necessary information needed
// by the subclasses.
struct FidoAuthenticationResponse {
FidoAuthenticationResponse() = default;
~FidoAuthenticationResponse() = default;

// Whether the authentication was successful.
bool did_succeed = false;
// The fetched credit card if the authentication was successful. Can be
Expand Down
3 changes: 2 additions & 1 deletion components/crx_file/crx_creator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ CreatorResult SignArchiveAndCreateHeader(const base::FilePath& output_path,
// through, run ZIP through.
auto signer = crypto::SignatureCreator::Create(
signing_key, crypto::SignatureCreator::HashAlgorithm::SHA256);
signer->Update(kSignatureContext, std::size(kSignatureContext));
signer->Update(reinterpret_cast<const uint8_t*>(kSignatureContext),
std::size(kSignatureContext));
signer->Update(signed_header_size_octets,
std::size(signed_header_size_octets));
signer->Update(
Expand Down
2 changes: 1 addition & 1 deletion components/crx_file/crx_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace crx_file {
constexpr char kCrxFileHeaderMagic[] = "Cr24";
constexpr char kCrxDiffFileHeaderMagic[] = "CrOD";
constexpr int kCrxFileHeaderMagicSize = 4;
constexpr unsigned char kSignatureContext[] = u8"CRX3 SignedData";
constexpr char kSignatureContext[] = "CRX3 SignedData";

} // namespace crx_file

Expand Down
2 changes: 1 addition & 1 deletion components/crx_file/crx_verifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ VerifierResult VerifyCrx3(
base::as_bytes(base::make_span(sig)),
base::as_bytes(base::make_span(key))))
return VerifierResult::ERROR_SIGNATURE_INITIALIZATION_FAILED;
v->VerifyUpdate(kSignatureContext);
v->VerifyUpdate(base::as_bytes(base::make_span(kSignatureContext)));
v->VerifyUpdate(header_size_octets);
v->VerifyUpdate(base::as_bytes(base::make_span(signed_header_data_str)));
verifiers.push_back(std::move(v));
Expand Down
4 changes: 0 additions & 4 deletions components/feed/core/v2/public/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ struct NetworkResponse {
std::string response_bytes;
// HTTP status code if available, or net::Error otherwise.
int status_code;

NetworkResponse() = default;
NetworkResponse(NetworkResponse&& other) = default;
NetworkResponse& operator=(NetworkResponse&& other) = default;
};

// For the snippets-internals page.
Expand Down
6 changes: 2 additions & 4 deletions components/metrics/file_metrics_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ struct SourceOptions {
bool is_read_only;
};

enum : int {
// Opening a file typically requires at least these flags.
STD_OPEN = base::File::FLAG_OPEN | base::File::FLAG_READ,
};
// Opening a file typically requires at least these flags.
constexpr int STD_OPEN = base::File::FLAG_OPEN | base::File::FLAG_READ;

constexpr SourceOptions kSourceOptions[] = {
// SOURCE_HISTOGRAMS_ATOMIC_FILE
Expand Down
4 changes: 0 additions & 4 deletions components/omnibox/browser/history_fuzzy_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ bool Node::FindCorrections(const std::u16string& text,
// TODO(orinj): This should be optimized in final algorithm; stop copying.
Correction correction;

Step(const Step&) = default;
Step(Step&&) = default;
Step& operator=(Step&&) = default;

// std::priority_queue keeps the greatest element on top, so we want this
// operator implementation to make bad steps less than good steps.
// Prioritize minimum distance, with index and length to break ties.
Expand Down
18 changes: 9 additions & 9 deletions components/omnibox/browser/omnibox_edit_model_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,24 @@ TEST_F(OmniboxEditModelTest, AdjustTextForCopy) {

// Verifies that non-ASCII characters are %-escaped for valid copied URLs,
// as long as the host has not been modified from the page URL.
{u8"https://ja.wikipedia.org/wiki/目次", 0, "", false,
u8"https://ja.wikipedia.org/wiki/目次",
{"https://ja.wikipedia.org/wiki/目次", 0, "", false,
"https://ja.wikipedia.org/wiki/目次",
"https://ja.wikipedia.org/wiki/%E7%9B%AE%E6%AC%A1", true,
"https://ja.wikipedia.org/wiki/%E7%9B%AE%E6%AC%A1"},
// Test escaping when part of the path was not copied.
{u8"https://ja.wikipedia.org/wiki/目次", 0, "", false,
u8"https://ja.wikipedia.org/wiki/目",
{"https://ja.wikipedia.org/wiki/目次", 0, "", false,
"https://ja.wikipedia.org/wiki/目",
"https://ja.wikipedia.org/wiki/%E7%9B%AE", true,
"https://ja.wikipedia.org/wiki/%E7%9B%AE"},
// Correctly handle escaping in the scheme-elided case as well.
{u8"https://ja.wikipedia.org/wiki/目次", 0, "", false,
u8"ja.wikipedia.org/wiki/目次",
{"https://ja.wikipedia.org/wiki/目次", 0, "", false,
"ja.wikipedia.org/wiki/目次",
"https://ja.wikipedia.org/wiki/%E7%9B%AE%E6%AC%A1", true,
"https://ja.wikipedia.org/wiki/%E7%9B%AE%E6%AC%A1",
u8"ja.wikipedia.org/wiki/目次"},
"ja.wikipedia.org/wiki/目次"},
// Don't escape when host was modified.
{u8"https://ja.wikipedia.org/wiki/目次", 0, "", false,
u8"https://wikipedia.org/wiki/目次", u8"https://wikipedia.org/wiki/目次",
{"https://ja.wikipedia.org/wiki/目次", 0, "", false,
"https://wikipedia.org/wiki/目次", "https://wikipedia.org/wiki/目次",
false, ""},
};

Expand Down
11 changes: 6 additions & 5 deletions components/omnibox/browser/titled_url_match_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ std::u16string ConcatAncestorsTitles(
std::vector<base::StringPiece16> ancestors) {
return ancestors.empty()
? std::u16string()
: std::accumulate(std::next(ancestors.rbegin()), ancestors.rend(),
std::u16string(*ancestors.rbegin()),
[](std::u16string& a, base::StringPiece16& b) {
return a + u"/" + std::u16string(b);
});
: std::accumulate(
std::next(ancestors.rbegin()), ancestors.rend(),
std::u16string(*ancestors.rbegin()),
[](const std::u16string& a, const base::StringPiece16& b) {
return a + u"/" + std::u16string(b);
});
}

} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ struct PageRenderData {

// Information related to layout shift normalization for different strategies.
struct NormalizedCLSData {
NormalizedCLSData() = default;

// Maximum CLS of session windows. The gap between two consecutive shifts is
// not bigger than 1000ms and the maximum window size is 5000ms.
float session_windows_gap1000ms_max5000ms_max_cls = 0.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using ::testing::ElementsAre;
using ::testing::UnorderedElementsAre;

TEST(AssetLinkData, NonJSON) {
constexpr char json[] = u8R"([trash])";
constexpr char json[] = R"([trash])";
AssetLinkData data;
EXPECT_FALSE(data.Parse(json));
EXPECT_THAT(data.includes(), IsEmpty());
Expand All @@ -24,7 +24,7 @@ TEST(AssetLinkData, NonJSON) {

TEST(AssetLinkData, NotList) {
constexpr char json[] =
u8R"({
R"({
"include": "https://example/.well-known/assetlinks.json"
})";
AssetLinkData data;
Expand All @@ -35,7 +35,7 @@ TEST(AssetLinkData, NotList) {

TEST(AssetLinkData, IncludeWrongValue) {
constexpr char json[] =
u8R"([{
R"([{
"include": 24
}])";
AssetLinkData data;
Expand All @@ -46,7 +46,7 @@ TEST(AssetLinkData, IncludeWrongValue) {

TEST(AssetLinkData, IncludeFile) {
constexpr char json[] =
u8R"([{
R"([{
"include": "https://example/.well-known/assetlinks.json"
}])";
AssetLinkData data;
Expand All @@ -58,7 +58,7 @@ TEST(AssetLinkData, IncludeFile) {

TEST(AssetLinkData, IncludeHTTPFile) {
constexpr char json[] =
u8R"([{
R"([{
"include": "http://example/.well-known/assetlinks.json"
}])";
AssetLinkData data;
Expand All @@ -69,7 +69,7 @@ TEST(AssetLinkData, IncludeHTTPFile) {

TEST(AssetLinkData, IncludeInvalidFile) {
constexpr char json[] =
u8R"([{
R"([{
"include": "www.example/assetlinks.json"
}])";
AssetLinkData data;
Expand All @@ -80,7 +80,7 @@ TEST(AssetLinkData, IncludeInvalidFile) {

TEST(AssetLinkData, HandleURLsPermission) {
constexpr char json[] =
u8R"([{
R"([{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "web",
Expand All @@ -102,7 +102,7 @@ TEST(AssetLinkData, HandleURLsPermission) {

TEST(AssetLinkData, BrokenRelation) {
constexpr char json[] =
u8R"([{
R"([{
"relation": "delegate_permission/common.get_login_creds",
"target": {
"namespace": "web",
Expand All @@ -117,7 +117,7 @@ TEST(AssetLinkData, BrokenRelation) {

TEST(AssetLinkData, GetLoginCredsPermission) {
constexpr char json[] =
u8R"([{
R"([{
"relation": ["delegate_permission/common.get_login_creds"],
"target": {
"namespace": "web",
Expand Down Expand Up @@ -154,7 +154,7 @@ TEST(AssetLinkData, GetLoginCredsPermission) {

TEST(AssetLinkData, MultiplePermissions) {
constexpr char json[] =
u8R"([{
R"([{
"relation": ["something","delegate_permission/common.get_login_creds"],
"target": {
"namespace": "web",
Expand Down Expand Up @@ -191,7 +191,7 @@ TEST(AssetLinkData, MultiplePermissions) {

TEST(AssetLinkData, MixedStatements) {
constexpr char json[] =
u8R"([{
R"([{
"relation": ["delegate_permission/common.get_login_creds"],
"target": {
"namespace": "web",
Expand Down
20 changes: 10 additions & 10 deletions components/prefs/pref_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ class COMPONENTS_PREFS_EXPORT PrefRegistry
// behave or be stored. This will be passed in a bitmask when the pref is
// registered. Subclasses of PrefRegistry can specify their own flags. Care
// must be taken to ensure none of these overlap with the flags below.
enum PrefRegistrationFlags : uint32_t {
// No flags are specified.
NO_REGISTRATION_FLAGS = 0,
using PrefRegistrationFlags = uint32_t;

// The first 8 bits are reserved for subclasses of PrefRegistry to use.
// No flags are specified.
static constexpr PrefRegistrationFlags NO_REGISTRATION_FLAGS = 0;

// This marks the pref as "lossy". There is no strict time guarantee on when
// a lossy pref will be persisted to permanent storage when it is modified.
LOSSY_PREF = 1 << 8,
// The first 8 bits are reserved for subclasses of PrefRegistry to use.

// Registering a pref as public allows other services to access it.
PUBLIC = 1 << 9,
};
// This marks the pref as "lossy". There is no strict time guarantee on when
// a lossy pref will be persisted to permanent storage when it is modified.
static constexpr PrefRegistrationFlags LOSSY_PREF = 1 << 8;

// Registering a pref as public allows other services to access it.
static constexpr PrefRegistrationFlags PUBLIC = 1 << 9;

typedef PrefValueMap::const_iterator const_iterator;
typedef std::unordered_map<std::string, uint32_t> PrefRegistrationFlagsMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ class UkmMetricsTable {

// Represents a row in the metrics table.
struct MetricsRow {
MetricsRow() = default;
~MetricsRow() = default;

// Timestamp of the event, all the metrics in the event will have the same
// timestamp. The timestamp is approximate and generated by the database
// when getting notifications about UKM. Timestamps are required since its
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool DisjointRangeLockManager::AcquireLock(
if (it == level_locks.end()) {
it = level_locks
.emplace(std::piecewise_construct,
std::forward_as_tuple(std::move(request.range)),
std::forward_as_tuple(request.range),
std::forward_as_tuple())
.first;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace content {
// The range is [begin, end). Bytewise comparison is used to determine
// overlapping ranges.
struct COMPONENT_EXPORT(LOCK_MANAGER) LeveledLockRange {
LeveledLockRange() = default;
~LeveledLockRange() = default;
std::string begin;
std::string end;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ enum class SigninOrSyncStatus {
// Provides information relating to the status of profiles in the embedder:
// how many are open, how many are signed in, and how many are syncing.
struct ProfilesStatus {
ProfilesStatus() = default;

size_t num_opened_profiles = 0;
size_t num_signed_in_profiles = 0;
size_t num_syncing_profiles = 0;
Expand Down
8 changes: 7 additions & 1 deletion components/url_pattern_index/ngram_extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ template <size_t N,
class NGramExtractor {
public:
// An STL compatible input iterator over N-grams contained in a string.
class Iterator : public std::iterator<std::input_iterator_tag, NGramType> {
class Iterator {
public:
using iterator_category = std::input_iterator_tag;
using value_type = NGramType;
using difference_type = std::ptrdiff_t;
using pointer = NGramType*;
using reference = NGramType&;

// Creates an iterator, which points to the leftmost valid N-gram within the
// |extractor|'s string, starting from |head|.
Iterator(const NGramExtractor& extractor,
Expand Down
9 changes: 7 additions & 2 deletions components/url_pattern_index/string_splitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ namespace url_pattern_index {
template <typename IsSeparator>
class StringSplitter {
public:
class Iterator
: public std::iterator<std::input_iterator_tag, base::StringPiece> {
class Iterator {
public:
using iterator_category = std::input_iterator_tag;
using value_type = base::StringPiece;
using difference_type = std::ptrdiff_t;
using pointer = base::StringPiece*;
using reference = base::StringPiece&;

// Creates an iterator, which points to the leftmost token within the
// |splitter|'s |text|, starting from |head|.
Iterator(const StringSplitter& splitter,
Expand Down
4 changes: 2 additions & 2 deletions components/viz/service/display/dc_layer_overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ class VIZ_SERVICE_EXPORT DCLayerOverlayProcessor
struct OverlayRect {
gfx::Rect rect;
bool is_overlay; // If false, it's an underlay.
bool operator==(const OverlayRect& b) {
bool operator==(const OverlayRect& b) const {
return rect == b.rect && is_overlay == b.is_overlay;
}
bool operator!=(const OverlayRect& b) { return !(*this == b); }
bool operator!=(const OverlayRect& b) const { return !(*this == b); }
};
std::vector<OverlayRect> previous_frame_overlay_rects_;
std::vector<OverlayRect> current_frame_overlay_rects_;
Expand Down
3 changes: 1 addition & 2 deletions components/web_package/web_bundle_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ cbor::Value WebBundleBuilder::CreateEncodedSigned(

std::vector<uint8_t> WebBundleBuilder::CreateTopLevel() {
cbor::Value::ArrayValue toplevel_array;
toplevel_array.emplace_back(
CreateByteString(u8"\U0001F310\U0001F4E6")); // "🌐📦"
toplevel_array.emplace_back(CreateByteString("🌐📦"));
toplevel_array.emplace_back(CreateByteString(base::StringPiece("b2\0\0", 4)));
toplevel_array.emplace_back(Encode(cbor::Value(section_lengths_)));
toplevel_array.emplace_back(sections_);
Expand Down

0 comments on commit 6a1c295

Please sign in to comment.