From 8ab195ae6210268072fc59fb7403464af805dcda Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Wed, 9 Sep 2020 14:16:25 -0700 Subject: [PATCH 1/4] http connection manager: use absl instead of std Signed-off-by: Michael Rebello --- source/common/http/conn_manager_impl.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/common/http/conn_manager_impl.h b/source/common/http/conn_manager_impl.h index b84a814120f14..bebe5244fdab9 100644 --- a/source/common/http/conn_manager_impl.h +++ b/source/common/http/conn_manager_impl.h @@ -231,19 +231,19 @@ class ConnectionManagerImpl : Logger::Loggable, // TODO(snowp): Create shared OptRef/OptConstRef helpers Http::RequestHeaderMapOptRef requestHeaders() override { - return request_headers_ ? std::make_optional(std::ref(*request_headers_)) : absl::nullopt; + return request_headers_ ? absl::make_optional(std::ref(*request_headers_)) : absl::nullopt; } Http::RequestTrailerMapOptRef requestTrailers() override { - return request_trailers_ ? std::make_optional(std::ref(*request_trailers_)) : absl::nullopt; + return request_trailers_ ? absl::make_optional(std::ref(*request_trailers_)) : absl::nullopt; } Http::ResponseHeaderMapOptRef continueHeaders() override { - return continue_headers_ ? std::make_optional(std::ref(*continue_headers_)) : absl::nullopt; + return continue_headers_ ? absl::make_optional(std::ref(*continue_headers_)) : absl::nullopt; } Http::ResponseHeaderMapOptRef responseHeaders() override { - return response_headers_ ? std::make_optional(std::ref(*response_headers_)) : absl::nullopt; + return response_headers_ ? absl::make_optional(std::ref(*response_headers_)) : absl::nullopt; } Http::ResponseTrailerMapOptRef responseTrailers() override { - return response_trailers_ ? std::make_optional(std::ref(*response_trailers_)) : absl::nullopt; + return response_trailers_ ? absl::make_optional(std::ref(*response_trailers_)) : absl::nullopt; } void endStream() override { From 8208ad783904e4e895805c4a78b926ac607b345c Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Wed, 9 Sep 2020 14:47:29 -0700 Subject: [PATCH 2/4] lint: add rule to use absl::make_optional over std::make_optional Signed-off-by: Michael Rebello --- tools/code_format/check_format.py | 2 ++ tools/code_format/check_format_test_helper.py | 2 ++ tools/testdata/check_format/std_make_optional.cc | 8 ++++++++ 3 files changed, 12 insertions(+) create mode 100644 tools/testdata/check_format/std_make_optional.cc diff --git a/tools/code_format/check_format.py b/tools/code_format/check_format.py index 5ac0e628bdcc3..be2c77ad99277 100755 --- a/tools/code_format/check_format.py +++ b/tools/code_format/check_format.py @@ -695,6 +695,8 @@ def checkSourceLine(line, file_path, reportError): reportError("Don't use std::optional; use absl::optional instead") if tokenInLine("std::variant", line): reportError("Don't use std::variant; use absl::variant instead") + if tokenInLine("std::visit", line): + reportError("Don't use std::visit; use absl::visit instead") if "__attribute__((packed))" in line and file_path != "./include/envoy/common/platform.h": # __attribute__((packed)) is not supported by MSVC, we have a PACKED_STRUCT macro that # can be used instead diff --git a/tools/code_format/check_format_test_helper.py b/tools/code_format/check_format_test_helper.py index da3f576605aa1..fcfaf8b9218ef 100755 --- a/tools/code_format/check_format_test_helper.py +++ b/tools/code_format/check_format_test_helper.py @@ -243,6 +243,8 @@ def runChecks(): "std_unordered_set.cc", "Don't use std::unordered_set; use absl::flat_hash_set instead " + "or absl::node_hash_set if pointer stability of keys/values is required") errors += checkUnfixableError("std_any.cc", "Don't use std::any; use absl::any instead") + errors += checkUnfixableError("std_make_optional.cc", + "Don't use std::make_optional; use absl::make_optional instead") errors += checkUnfixableError("std_optional.cc", "Don't use std::optional; use absl::optional instead") errors += checkUnfixableError("std_variant.cc", diff --git a/tools/testdata/check_format/std_make_optional.cc b/tools/testdata/check_format/std_make_optional.cc new file mode 100644 index 0000000000000..b629835d62496 --- /dev/null +++ b/tools/testdata/check_format/std_make_optional.cc @@ -0,0 +1,8 @@ +#include + +namespace Envoy { + void foo() { + uint64_t value = 1; + uint64_t optional_value = std::make_optional(value); + } +} // namespace Envoy From 891be1330b829627515808b6fb22664c08d214a9 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Wed, 9 Sep 2020 14:50:32 -0700 Subject: [PATCH 3/4] format Signed-off-by: Michael Rebello --- tools/code_format/check_format.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/code_format/check_format.py b/tools/code_format/check_format.py index be2c77ad99277..f7fb92f319bb0 100755 --- a/tools/code_format/check_format.py +++ b/tools/code_format/check_format.py @@ -691,12 +691,12 @@ def checkSourceLine(line, file_path, reportError): # See: https://github.com/envoyproxy/envoy/issues/12341 if tokenInLine("std::any", line): reportError("Don't use std::any; use absl::any instead") + if tokenInLine("std::make_optional", line): + reportError("Don't use std::make_optional; use absl::make_optional instead") if tokenInLine("std::optional", line): reportError("Don't use std::optional; use absl::optional instead") if tokenInLine("std::variant", line): reportError("Don't use std::variant; use absl::variant instead") - if tokenInLine("std::visit", line): - reportError("Don't use std::visit; use absl::visit instead") if "__attribute__((packed))" in line and file_path != "./include/envoy/common/platform.h": # __attribute__((packed)) is not supported by MSVC, we have a PACKED_STRUCT macro that # can be used instead From 603702acfab6b865a73939b8596ebbf356f46352 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Wed, 9 Sep 2020 14:56:09 -0700 Subject: [PATCH 4/4] clang format Signed-off-by: Michael Rebello --- source/common/http/conn_manager_impl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/common/http/conn_manager_impl.h b/source/common/http/conn_manager_impl.h index bebe5244fdab9..df172dac16b2e 100644 --- a/source/common/http/conn_manager_impl.h +++ b/source/common/http/conn_manager_impl.h @@ -243,7 +243,8 @@ class ConnectionManagerImpl : Logger::Loggable, return response_headers_ ? absl::make_optional(std::ref(*response_headers_)) : absl::nullopt; } Http::ResponseTrailerMapOptRef responseTrailers() override { - return response_trailers_ ? absl::make_optional(std::ref(*response_trailers_)) : absl::nullopt; + return response_trailers_ ? absl::make_optional(std::ref(*response_trailers_)) + : absl::nullopt; } void endStream() override {