Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/common/common/fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace fmt {

// Provide an implementation of formatter for fmt::format that allows absl::string_view to be
// formatted with the same format specifiers available to std::string.
// TODO(zuercher): Once absl::string_view is replaced with std::string_view, this can be removed
// as fmtlib handles std::string_view natively.
// TODO(zuercher): Once absl::string_view is replaced with the std type, this can be removed
// as fmtlib handles string_view natively.
// NOLINTNEXTLINE(readability-identifier-naming)
template <> struct formatter<absl::string_view> : formatter<string_view> {
auto format(absl::string_view absl_string_view, fmt::format_context& ctx) -> decltype(ctx.out()) {
Expand Down
4 changes: 2 additions & 2 deletions source/extensions/filters/http/cache/cache_headers_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ namespace {
// https://tools.ietf.org/html/rfc2616#section-4.2.

// Used to separate the values of different headers.
constexpr std::string_view header_separator = "\n";
constexpr absl::string_view header_separator = "\n";
// Used to separate multiple values of a same header.
constexpr std::string_view in_value_separator = "\r";
constexpr absl::string_view in_value_separator = "\r";
}; // namespace

std::string VaryHeader::createVaryKey(const Http::HeaderEntry* vary_header,
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/quic_listeners/quiche/envoy_quic_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ template <class T>
std::unique_ptr<T> spdyHeaderBlockToEnvoyHeaders(const spdy::SpdyHeaderBlock& header_block) {
auto headers = T::create();
for (auto entry : header_block) {
// TODO(danzh): Avoid temporary strings and addCopy() with std::string_view.
// TODO(danzh): Avoid temporary strings and addCopy() with string_view.
std::string key(entry.first);
std::string value(entry.second);
headers->addCopy(Http::LowerCaseString(key), value);
Expand Down
14 changes: 12 additions & 2 deletions tools/code_format/check_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,17 +687,27 @@ def checkSourceLine(line, file_path, reportError):
# The std::atomic_* free functions are functionally equivalent to calling
# operations on std::atomic<T> objects, so prefer to use that instead.
reportError("Don't use free std::atomic_* functions, use std::atomic<T> members instead.")
# Blocking the use of std::any, std::optional, std::variant for now as iOS 11/macOS 10.13
# does not support these functions at runtime.
# Block usage of certain std types/functions as iOS 11 and macOS 10.13
# do not support these at runtime.
# 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::get_if", line):
reportError("Don't use std::get_if; use absl::get_if instead")
if tokenInLine("std::holds_alternative", line):
reportError("Don't use std::holds_alternative; use absl::holds_alternative instead")
if tokenInLine("std::make_optional", line):
reportError("Don't use std::make_optional; use absl::make_optional instead")
if tokenInLine("std::monostate", line):
reportError("Don't use std::monostate; use absl::monostate instead")
if tokenInLine("std::optional", line):
reportError("Don't use std::optional; use absl::optional instead")
if tokenInLine("std::string_view", line):
reportError("Don't use std::string_view; use absl::string_view 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
Expand Down
9 changes: 9 additions & 0 deletions tools/code_format/check_format_test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,21 @@ 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_get_if.cc", "Don't use std::get_if; use absl::get_if instead")
errors += checkUnfixableError(
"std_holds_alternative.cc",
"Don't use std::holds_alternative; use absl::holds_alternative instead")
errors += checkUnfixableError("std_make_optional.cc",
"Don't use std::make_optional; use absl::make_optional instead")
errors += checkUnfixableError("std_monostate.cc",
"Don't use std::monostate; use absl::monostate instead")
errors += checkUnfixableError("std_optional.cc",
"Don't use std::optional; use absl::optional instead")
errors += checkUnfixableError("std_string_view.cc",
"Don't use std::string_view; use absl::string_view instead")
errors += checkUnfixableError("std_variant.cc",
"Don't use std::variant; use absl::variant instead")
errors += checkUnfixableError("std_visit.cc", "Don't use std::visit; use absl::visit instead")
errors += checkUnfixableError(
"throw.cc", "Don't introduce throws into exception-free files, use error statuses instead.")
errors += checkFileExpectingOK("commented_throw.cc")
Expand Down
Binary file added tools/testdata/.DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions tools/testdata/check_format/std_get_if.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <variant>

namespace Envoy {
void foo() {
absl::variant<int, float> x{12};
auto y = std::get_if<int>(&x);
}
} // namespace Envoy
8 changes: 8 additions & 0 deletions tools/testdata/check_format/std_holds_alternative.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <variant>

namespace Envoy {
void foo() {
absl::variant<int, double> x{12};
auto y = std::holds_alternative<double>(x);
}
} // namespace Envoy
12 changes: 12 additions & 0 deletions tools/testdata/check_format/std_monostate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <variant>

namespace Envoy {
struct S {
S(int i) : i(i) {}
int i;
};

void foo() {
absl::variant<std::monostate, S> x;
}
} // namespace Envoy
7 changes: 7 additions & 0 deletions tools/testdata/check_format/std_string_view.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <string>

namespace Envoy {
void foo() {
std::string_view x("a string literal");
}
} // namespace Envoy
14 changes: 14 additions & 0 deletions tools/testdata/check_format/std_visit.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <variant>

namespace Envoy {
struct SomeVisitorFunctor {
template<typename T>
void operator()(const T& i) const {}
};

void foo() {
absl::variant<int, double> x{12};
SomeVisitorFunctor visitor;
std::visit(visitor, x);
}
} // namespace Envoy