diff --git a/test/mocks/upstream/cluster_info.cc b/test/mocks/upstream/cluster_info.cc index 9e1e07a52c890..8196db8bd98d9 100644 --- a/test/mocks/upstream/cluster_info.cc +++ b/test/mocks/upstream/cluster_info.cc @@ -71,7 +71,7 @@ MockClusterInfo::MockClusterInfo() .WillByDefault(Invoke([this]() -> const Envoy::Config::TypedMetadata& { if (typed_metadata_ == nullptr) { typed_metadata_ = - absl::make_unique>(metadata_); + std::make_unique>(metadata_); } return *typed_metadata_; })); diff --git a/tools/check_format.py b/tools/check_format.py index 4d53d5e8f4acd..b73a26fb0fe84 100755 --- a/tools/check_format.py +++ b/tools/check_format.py @@ -75,6 +75,9 @@ "ProtobufWkt::MapPair": "Protobuf::MapPair", "ProtobufUtil::MessageDifferencer": "Protobuf::util::MessageDifferencer" } +LIBCXX_REPLACEMENTS = { + "absl::make_unique<": "std::make_unique<", +} # yapf: enable @@ -341,6 +344,10 @@ def fixSourceLine(line): for invalid_construct, valid_construct in PROTOBUF_TYPE_ERRORS.items(): line = line.replace(invalid_construct, valid_construct) + # Use recommended cpp stdlib + for invalid_construct, valid_construct in LIBCXX_REPLACEMENTS.items(): + line = line.replace(invalid_construct, valid_construct) + return line @@ -370,6 +377,10 @@ def checkSourceLine(line, file_path, reportError): if invalid_construct in line: reportError("incorrect protobuf type reference %s; " "should be %s" % (invalid_construct, valid_construct)) + for invalid_construct, valid_construct in LIBCXX_REPLACEMENTS.items(): + if invalid_construct in line: + reportError("term %s should be replaced with standard library term %s" % (invalid_construct, + valid_construct)) # Some errors cannot be fixed automatically, and actionable, consistent, # navigable messages should be emitted to make it easy to find and fix diff --git a/tools/check_format_test_helper.py b/tools/check_format_test_helper.py index 395c0de3e7da9..45b36d149c95c 100755 --- a/tools/check_format_test_helper.py +++ b/tools/check_format_test_helper.py @@ -229,6 +229,9 @@ def checkFileExpectingOK(filename): errors += checkAndFixError("bad_envoy_build_sys_ref.BUILD", "Superfluous '@envoy//' prefix") errors += checkAndFixError("proto_format.proto", "clang-format check failed") errors += checkAndFixError("api/java_options.proto", "Java proto option") + errors += checkAndFixError( + "cpp_std.cc", + "term absl::make_unique< should be replaced with standard library term std::make_unique<") errors += checkFileExpectingOK("real_time_source_override.cc") errors += checkFileExpectingOK("time_system_wait_for.cc") diff --git a/tools/testdata/check_format/cpp_std.cc b/tools/testdata/check_format/cpp_std.cc new file mode 100644 index 0000000000000..8342a139f26a3 --- /dev/null +++ b/tools/testdata/check_format/cpp_std.cc @@ -0,0 +1,11 @@ +#include + +#include "absl/memory/memory.h" + +namespace Envoy { + +std::unique_ptr to_be_fix = absl::make_unique(0); + +// Awesome stuff goes here. + +} // namespace Envoy diff --git a/tools/testdata/check_format/cpp_std.cc.gold b/tools/testdata/check_format/cpp_std.cc.gold new file mode 100644 index 0000000000000..8414a46360327 --- /dev/null +++ b/tools/testdata/check_format/cpp_std.cc.gold @@ -0,0 +1,11 @@ +#include + +#include "absl/memory/memory.h" + +namespace Envoy { + +std::unique_ptr to_be_fix = std::make_unique(0); + +// Awesome stuff goes here. + +} // namespace Envoy