Skip to content

Commit

Permalink
clang-tidy: modernize-return-braced-init-list (envoyproxy#7447)
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Argueta <dereka@pinterest.com>
  • Loading branch information
derekargueta authored and mattklein123 committed Jul 2, 2019
1 parent c9a2c32 commit c0a1ded
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 72 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ WarningsAsErrors: 'abseil-duration-*,
bugprone-use-after-move,
modernize-make-shared,
modernize-make-unique,
modernize-return-braced-init-list,
modernize-use-using,
performance-faster-string-find,
performance-for-range-copy,
Expand Down
4 changes: 2 additions & 2 deletions source/common/buffer/buffer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ class SliceDeque {
size_t index_;
};

ConstIterator begin() const noexcept { return ConstIterator(*this, 0); }
ConstIterator begin() const noexcept { return {*this, 0}; }

ConstIterator end() const noexcept { return ConstIterator(*this, size_); }
ConstIterator end() const noexcept { return {*this, size_}; }

private:
constexpr static size_t InlineRingCapacity = 8;
Expand Down
4 changes: 2 additions & 2 deletions source/common/grpc/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ absl::optional<Status::GrpcStatus> Common::getGrpcStatus(const Http::HeaderMap&
}
if (!absl::SimpleAtoi(grpc_status_header->value().getStringView(), &grpc_status_code) ||
grpc_status_code > Status::GrpcStatus::MaximumValid) {
return absl::optional<Status::GrpcStatus>(Status::GrpcStatus::InvalidCode);
return {Status::GrpcStatus::InvalidCode};
}
return absl::optional<Status::GrpcStatus>(static_cast<Status::GrpcStatus>(grpc_status_code));
return {static_cast<Status::GrpcStatus>(grpc_status_code)};
}

std::string Common::getGrpcMessage(const Http::HeaderMap& trailers) {
Expand Down
11 changes: 5 additions & 6 deletions source/common/network/addr_family_aware_socket_option_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ absl::optional<Address::IpVersion> getVersionFromSocket(const Socket& socket) {
// TODO(htuch): Figure out a way to obtain a consistent interface for IP
// version from socket.
if (socket.localAddress()) {
return absl::optional<Address::IpVersion>(getVersionFromAddress(socket.localAddress()));
return {getVersionFromAddress(socket.localAddress())};
} else {
return absl::optional<Address::IpVersion>(
getVersionFromAddress(Address::addressFromFd(socket.ioHandle().fd())));
return {getVersionFromAddress(Address::addressFromFd(socket.ioHandle().fd()))};
}
} catch (const EnvoyException&) {
// Ignore, we get here because we failed in getsockname().
Expand All @@ -48,15 +47,15 @@ getOptionForSocket(const Socket& socket, SocketOptionImpl& ipv4_option,

// If the FD is v4, we can only try the IPv4 variant.
if (*version == Network::Address::IpVersion::v4) {
return absl::optional<std::reference_wrapper<SocketOptionImpl>>(ipv4_option);
return {ipv4_option};
}
// If the FD is v6, we first try the IPv6 variant if the platform supports it and fallback to the
// IPv4 variant otherwise.
ASSERT(*version == Network::Address::IpVersion::v6);
if (ipv6_option.isSupported()) {
return absl::optional<std::reference_wrapper<SocketOptionImpl>>(ipv6_option);
return {ipv6_option};
}
return absl::optional<std::reference_wrapper<SocketOptionImpl>>(ipv4_option);
return {ipv4_option};
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion source/common/router/config_utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ConfigUtility::parseDirectResponseCode(const envoy::api::v2::route::Route& route
} else if (route.has_direct_response()) {
return static_cast<Http::Code>(route.direct_response().status());
}
return absl::optional<Http::Code>();
return {};
}

std::string ConfigUtility::parseDirectResponseBody(const envoy::api::v2::route::Route& route,
Expand Down
6 changes: 3 additions & 3 deletions source/common/upstream/outlier_detection_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ absl::optional<Http::Code> DetectorHostMonitorImpl::resultToHttpCode(Result resu
return absl::nullopt;
}

return absl::optional<Http::Code>(http_code);
return {http_code};
}

// Method is called by putResult when external and local origin errors
Expand Down Expand Up @@ -713,8 +713,8 @@ SuccessRateAccumulator::getSuccessRate(uint64_t success_rate_request_volume) {
return absl::optional<double>();
}

return absl::optional<double>(backup_success_rate_bucket_->success_request_counter_ * 100.0 /
backup_success_rate_bucket_->total_request_counter_);
return {backup_success_rate_bucket_->success_request_counter_ * 100.0 /
backup_success_rate_bucket_->total_request_counter_};
}

} // namespace Outlier
Expand Down
22 changes: 11 additions & 11 deletions source/extensions/filters/network/dubbo_proxy/decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,45 @@ DecoderStateMachine::DecoderStatus
DecoderStateMachine::onTransportBegin(Buffer::Instance& buffer, Protocol::Context& context) {
if (!protocol_.decode(buffer, &context, metadata_)) {
ENVOY_LOG(debug, "dubbo decoder: need more data for {} protocol", protocol_.name());
return DecoderStatus(ProtocolState::WaitForData);
return {ProtocolState::WaitForData};
}

if (context.is_heartbeat_) {
ENVOY_LOG(debug, "dubbo decoder: this is the {} heartbeat message", protocol_.name());
buffer.drain(context.header_size_);
decoder_callbacks_.onHeartbeat(metadata_);
return DecoderStatus(ProtocolState::Done, Network::FilterStatus::Continue);
return {ProtocolState::Done, Network::FilterStatus::Continue};
} else {
handler_ = decoder_callbacks_.newDecoderEventHandler();
}
return DecoderStatus(ProtocolState::OnTransferHeaderTo, handler_->transportBegin());
return {ProtocolState::OnTransferHeaderTo, handler_->transportBegin()};
}

DecoderStateMachine::DecoderStatus DecoderStateMachine::onTransportEnd() {
ENVOY_LOG(debug, "dubbo decoder: complete protocol processing");
return DecoderStatus(ProtocolState::Done, handler_->transportEnd());
return {ProtocolState::Done, handler_->transportEnd()};
}

DecoderStateMachine::DecoderStatus DecoderStateMachine::onTransferHeaderTo(Buffer::Instance& buffer,
size_t length) {
ENVOY_LOG(debug, "dubbo decoder: transfer protocol header, buffer size {}, header size {}",
buffer.length(), length);
return DecoderStatus(ProtocolState::OnMessageBegin, handler_->transferHeaderTo(buffer, length));
return {ProtocolState::OnMessageBegin, handler_->transferHeaderTo(buffer, length)};
}

DecoderStateMachine::DecoderStatus DecoderStateMachine::onTransferBodyTo(Buffer::Instance& buffer,
int32_t length) {
ENVOY_LOG(debug, "dubbo decoder: transfer protocol body, buffer size {}, body size {}",
buffer.length(), length);
return DecoderStatus(ProtocolState::OnTransportEnd, handler_->transferBodyTo(buffer, length));
return {ProtocolState::OnTransportEnd, handler_->transferBodyTo(buffer, length)};
}

DecoderStateMachine::DecoderStatus DecoderStateMachine::onMessageBegin() {
ENVOY_LOG(debug, "dubbo decoder: start deserializing messages, deserializer name {}",
deserializer_.name());
return DecoderStatus(ProtocolState::OnMessageEnd,
handler_->messageBegin(metadata_->message_type(), metadata_->request_id(),
metadata_->serialization_type()));
return {ProtocolState::OnMessageEnd,
handler_->messageBegin(metadata_->message_type(), metadata_->request_id(),
metadata_->serialization_type())};
}

DecoderStateMachine::DecoderStatus DecoderStateMachine::onMessageEnd(Buffer::Instance& buffer,
Expand All @@ -61,7 +61,7 @@ DecoderStateMachine::DecoderStatus DecoderStateMachine::onMessageEnd(Buffer::Ins
if (buffer.length() < static_cast<uint64_t>(message_size)) {
ENVOY_LOG(debug, "dubbo decoder: need more data for {} deserialization, current size {}",
deserializer_.name(), buffer.length());
return DecoderStatus(ProtocolState::WaitForData);
return {ProtocolState::WaitForData};
}

switch (metadata_->message_type()) {
Expand All @@ -81,7 +81,7 @@ DecoderStateMachine::DecoderStatus DecoderStateMachine::onMessageEnd(Buffer::Ins
}

ENVOY_LOG(debug, "dubbo decoder: ends the deserialization of the message");
return DecoderStatus(ProtocolState::OnTransferBodyTo, handler_->messageEnd(metadata_));
return {ProtocolState::OnTransferBodyTo, handler_->messageEnd(metadata_)};
}

DecoderStateMachine::DecoderStatus DecoderStateMachine::handleState(Buffer::Instance& buffer) {
Expand Down
Loading

0 comments on commit c0a1ded

Please sign in to comment.