Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: tools/clang/rewrite_to_chrome_style/tests/template-expected.cc

Issue 1806903003: Don't rename references to functions that originate from template args. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a period and GetType Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 namespace not_blink {
6
7 void notBlinkFunction(int x) {}
8
9 class NotBlinkClass {
10 public:
11 void notBlinkMethod() {}
12 };
13
14 template <typename T>
15 void notBlinkFunctionTemplate(T x) {}
16
17 } // not_blink
18
5 namespace blink { 19 namespace blink {
6 20
7 template <typename T, int number> 21 template <typename T, int number>
8 void F() { 22 void F() {
9 // We don't assert on this, and we don't end up considering it a const for 23 // We don't assert on this, and we don't end up considering it a const for
10 // now. 24 // now.
11 const int maybe_a_const = sizeof(T); 25 const int maybe_a_const = sizeof(T);
12 const int is_a_const = number; 26 const int is_a_const = number;
13 } 27 }
14 28
15 template <int number, typename... T> 29 template <int number, typename... T>
16 void F() { 30 void F() {
17 // We don't assert on this, and we don't end up considering it a const for 31 // We don't assert on this, and we don't end up considering it a const for
18 // now. 32 // now.
19 const int maybe_a_const = sizeof...(T); 33 const int maybe_a_const = sizeof...(T);
20 const int is_a_const = number; 34 const int is_a_const = number;
21 } 35 }
22 36
37 namespace test_template_arg_is_function {
38
39 void F(int x) {}
40
41 template <typename T, void g(T)>
42 void H(T x) {
43 g(x);
44 }
45
46 void Test() {
47 // f should be rewritten.
48 H<int, F>(0);
49 // notBlinkFunction should stay the same.
50 H<int, not_blink::notBlinkFunction>(1);
51 }
52
53 } // namespace test_template_arg_is_function
54
55 namespace test_template_arg_is_method {
56
57 class BlinkClass {
58 public:
59 void Method() {}
60 };
61
62 template <typename T, void (T::*g)()>
63 void H(T&& x) {
64 (x.*g)();
65 }
66
67 void Test() {
68 // method should be rewritten.
69 H<BlinkClass, &BlinkClass::Method>(BlinkClass());
70 H<not_blink::NotBlinkClass, &not_blink::NotBlinkClass::notBlinkMethod>(
71 not_blink::NotBlinkClass());
72 }
73
74 } // namespace test_template_arg_is_method
75
76 // Test template arguments that are function templates.
77 template <typename T, char converter(T)>
78 unsigned ReallyBadHash(const T* data, unsigned length) {
79 unsigned hash = 1;
80 for (unsigned i = 0; i < length; ++i) {
81 hash *= converter(data[i]);
82 }
83 return hash;
84 }
85
86 struct StringHasher {
87 static unsigned Hash(const char* data, unsigned length) {
88 // TODO(dcheng): For some reason, brokenFoldCase gets parsed as an
89 // UnresolvedLookupExpr, so this doesn't get rewritten. Meh. See
90 // https://crbug.com/584408.
91 return ReallyBadHash<char, brokenFoldCase<char>>(data, length);
92 }
93
94 private:
95 template <typename T>
96 static char BrokenFoldCase(T input) {
97 return input - ('a' - 'A');
98 }
99 };
100
23 } // namespace blink 101 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698