Commit fa323b77 authored by lukasza's avatar lukasza Committed by Commit bot

Blacklisting of method names coming from std library.

BUG=672902

Review-Url: https://codereview.chromium.org/2601063002
Cr-Commit-Position: refs/heads/master@{#440879}
parent 1b4b746a
......@@ -208,6 +208,12 @@ bool IsMethodOverrideOf(const clang::CXXMethodDecl& decl,
}
bool IsBlacklistedFunctionName(llvm::StringRef name) {
// https://crbug.com/672902: Method names with an underscore are typically
// mimicked after std library / are typically not originating from Blink.
// Do not rewrite such names (like push_back, emplace_back, etc.).
if (name.find('_') != llvm::StringRef::npos)
return true;
// https://crbug.com/677166: Have to avoid renaming |hash| -> |Hash| to avoid
// colliding with a struct already named |Hash|.
return name == "hash";
......@@ -225,6 +231,10 @@ bool IsBlacklistedInstanceMethodName(llvm::StringRef name) {
// 2. They (begin+end) are used in range-based for syntax sugar
// - for (auto x : foo) { ... } // <- foo.begin() will be called.
"begin", "end", "rbegin", "rend", "lock", "unlock", "try_lock",
// https://crbug.com/672902: Should not rewrite names that mimick methods
// from std library.
"back", "empty", "erase", "front", "insert",
};
for (const auto& b : kBlacklistedNames) {
if (name == b)
......
......@@ -36,7 +36,7 @@ class Checked {
};
template <typename To, typename From>
To Bitwise_cast(From from) {
To bitwise_cast(From from) {
static_assert(sizeof(To) == sizeof(From), "msg");
return reinterpret_cast<To>(from);
}
......@@ -60,5 +60,5 @@ struct ArrayTraits<WTF::Checked<U, int>> {
} // namespace mojo
using WTF::Bitwise_cast;
using WTF::bitwise_cast;
using WTF::SafeCast;
......@@ -258,6 +258,15 @@ class Foo {
// and should cover both instance and static methods as well as functions.
int hash() const { return 123; }
static int hash(const Foo& x) { return x.hash(); }
// https://crbug.com672902: std-like names should not be rewritten.
void emplace_back(int x) {}
void insert(int x) {}
void push_back(int x) {}
int* back() { return nullptr; }
int* front() { return nullptr; }
void erase() {}
bool empty() { return true; }
};
void Begin(int x) {}
......
......@@ -262,6 +262,15 @@ class Foo {
// and should cover both instance and static methods as well as functions.
int hash() const { return 123; }
static int hash(const Foo& x) { return x.hash(); }
// https://crbug.com672902: std-like names should not be rewritten.
void emplace_back(int x) {}
void insert(int x) {}
void push_back(int x) {}
int* back() { return nullptr; }
int* front() { return nullptr; }
void erase() {}
bool empty() { return true; }
};
void begin(int x) {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment