summaryrefslogtreecommitdiffstats
path: root/tools/clang
diff options
context:
space:
mode:
authordanakj <danakj@chromium.org>2016-02-05 13:10:39 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-05 21:13:42 +0000
commit749b2fa80cd51830dbd376a4cb00a6087e7d2629 (patch)
treec54f4ffa52719a2d29e7185105e14a5181ddc13c /tools/clang
parented0a3fbd38fdcc85b6d935331f05b88b5e81be83 (diff)
downloadchromium_src-749b2fa80cd51830dbd376a4cb00a6087e7d2629.zip
chromium_src-749b2fa80cd51830dbd376a4cb00a6087e7d2629.tar.gz
chromium_src-749b2fa80cd51830dbd376a4cb00a6087e7d2629.tar.bz2
rewrite_to_chrome_style: Don't rename swap() functions.
These are used for ADL tricks with std::swap, and need to stay lowercase. R=dcheng BUG=584526 Review URL: https://codereview.chromium.org/1676463004 Cr-Commit-Position: refs/heads/master@{#373911}
Diffstat (limited to 'tools/clang')
-rw-r--r--tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp12
-rw-r--r--tools/clang/rewrite_to_chrome_style/tests/functions-expected.cc8
-rw-r--r--tools/clang/rewrite_to_chrome_style/tests/functions-original.cc8
3 files changed, 27 insertions, 1 deletions
diff --git a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
index b69732b..6df3096 100644
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
@@ -178,7 +178,17 @@ bool IsProbablyConst(const clang::VarDecl& decl,
bool GetNameForDecl(const clang::FunctionDecl& decl,
const clang::ASTContext& context,
std::string& name) {
- name = decl.getName().str();
+ StringRef original_name = decl.getName();
+
+ // Some functions shouldn't be renamed because reasons.
+ // - swap() methods should match the signature of std::swap for ADL tricks.
+ static const char* kBlacklist[] = {"swap"};
+ for (const auto& b : kBlacklist) {
+ if (original_name == b)
+ return false;
+ }
+
+ name = original_name.str();
name[0] = clang::toUppercase(name[0]);
return true;
}
diff --git a/tools/clang/rewrite_to_chrome_style/tests/functions-expected.cc b/tools/clang/rewrite_to_chrome_style/tests/functions-expected.cc
index b218840d..ed8928b 100644
--- a/tools/clang/rewrite_to_chrome_style/tests/functions-expected.cc
+++ b/tools/clang/rewrite_to_chrome_style/tests/functions-expected.cc
@@ -25,6 +25,11 @@ void Begin() {}
void Trace() {}
void Lock() {}
+class SwapType {};
+
+// swap() functions are not renamed.
+void swap(SwapType& a, SwapType& b) {}
+
// Note: F is already Google style and should not change.
void F() {
// Test referencing a function without calling it.
@@ -37,4 +42,7 @@ using blink::TestFunctionThatTakesTwoInts;
void G() {
TestFunctionThatTakesTwoInts(1, 2);
+
+ blink::SwapType a, b;
+ swap(a, b);
}
diff --git a/tools/clang/rewrite_to_chrome_style/tests/functions-original.cc b/tools/clang/rewrite_to_chrome_style/tests/functions-original.cc
index c416d38..14530c6 100644
--- a/tools/clang/rewrite_to_chrome_style/tests/functions-original.cc
+++ b/tools/clang/rewrite_to_chrome_style/tests/functions-original.cc
@@ -25,6 +25,11 @@ void begin() {}
void trace() {}
void lock() {}
+class SwapType {};
+
+// swap() functions are not renamed.
+void swap(SwapType& a, SwapType& b) {}
+
// Note: F is already Google style and should not change.
void F() {
// Test referencing a function without calling it.
@@ -37,4 +42,7 @@ using blink::testFunctionThatTakesTwoInts;
void G() {
testFunctionThatTakesTwoInts(1, 2);
+
+ blink::SwapType a, b;
+ swap(a, b);
}