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
2 changes: 1 addition & 1 deletion test/mocks/upstream/cluster_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ MockClusterInfo::MockClusterInfo()
.WillByDefault(Invoke([this]() -> const Envoy::Config::TypedMetadata& {
if (typed_metadata_ == nullptr) {
typed_metadata_ =
absl::make_unique<Config::TypedMetadataImpl<ClusterTypedMetadataFactory>>(metadata_);
std::make_unique<Config::TypedMetadataImpl<ClusterTypedMetadataFactory>>(metadata_);
}
return *typed_metadata_;
}));
Expand Down
11 changes: 11 additions & 0 deletions tools/check_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
"ProtobufWkt::MapPair": "Protobuf::MapPair",
"ProtobufUtil::MessageDifferencer": "Protobuf::util::MessageDifferencer"
}
LIBCXX_REPLACEMENTS = {
"absl::make_unique<": "std::make_unique<",
}
# yapf: enable


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tools/check_format_test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
11 changes: 11 additions & 0 deletions tools/testdata/check_format/cpp_std.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <memory>

#include "absl/memory/memory.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw this file (and the gold) is not actually compiled, so you don't need the includes. You do need the 'namespace Envoy' as the presence of that is one of the formatting rules that is checked.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaning those out is totally optional IMO.


namespace Envoy {

std::unique_ptr<int> to_be_fix = absl::make_unique<int>(0);

// Awesome stuff goes here.

} // namespace Envoy
11 changes: 11 additions & 0 deletions tools/testdata/check_format/cpp_std.cc.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <memory>

#include "absl/memory/memory.h"

namespace Envoy {

std::unique_ptr<int> to_be_fix = std::make_unique<int>(0);

// Awesome stuff goes here.

} // namespace Envoy