| OLD | NEW |
| 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 { | 5 namespace not_blink { |
| 6 | 6 |
| 7 void notBlinkFunction(int x) {} | 7 void function(int x) {} |
| 8 | 8 |
| 9 class NotBlinkClass { | 9 class Class { |
| 10 public: | 10 public: |
| 11 void notBlinkMethod() {} | 11 void method() {} |
| 12 template <typename T> |
| 13 void methodTemplate(T) {} |
| 14 template <typename T> |
| 15 static void staticMethodTemplate(T) {} |
| 12 }; | 16 }; |
| 13 | 17 |
| 14 template <typename T> | 18 template <typename T> |
| 15 void notBlinkFunctionTemplate(T x) {} | 19 void functionTemplate(T x) {} |
| 16 | 20 |
| 17 } // not_blink | 21 } // not_blink |
| 18 | 22 |
| 19 namespace blink { | 23 namespace blink { |
| 20 | 24 |
| 21 template <typename T, int number> | 25 template <typename T, int number> |
| 22 void F() { | 26 void F() { |
| 23 // We don't assert on this, and we don't end up considering it a const for | 27 // We don't assert on this, and we don't end up considering it a const for |
| 24 // now. | 28 // now. |
| 25 const int maybe_a_const = sizeof(T); | 29 const int maybe_a_const = sizeof(T); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 39 void F(int x) {} | 43 void F(int x) {} |
| 40 | 44 |
| 41 template <typename T, void g(T)> | 45 template <typename T, void g(T)> |
| 42 void H(T x) { | 46 void H(T x) { |
| 43 g(x); | 47 g(x); |
| 44 } | 48 } |
| 45 | 49 |
| 46 void Test() { | 50 void Test() { |
| 47 // f should be rewritten. | 51 // f should be rewritten. |
| 48 H<int, F>(0); | 52 H<int, F>(0); |
| 49 // notBlinkFunction should stay the same. | 53 // Non-Blink should stay the same. |
| 50 H<int, not_blink::notBlinkFunction>(1); | 54 H<int, not_blink::function>(1); |
| 51 } | 55 } |
| 52 | 56 |
| 53 } // namespace test_template_arg_is_function | 57 } // namespace test_template_arg_is_function |
| 54 | 58 |
| 55 namespace test_template_arg_is_method { | 59 namespace test_template_arg_is_method { |
| 56 | 60 |
| 57 class BlinkClass { | 61 class Class { |
| 58 public: | 62 public: |
| 59 void Method() {} | 63 void Method() {} |
| 60 }; | 64 }; |
| 61 | 65 |
| 62 template <typename T, void (T::*g)()> | 66 template <typename T, void (T::*g)()> |
| 63 void H(T&& x) { | 67 void H(T&& x) { |
| 64 (x.*g)(); | 68 (x.*g)(); |
| 65 } | 69 } |
| 66 | 70 |
| 67 void Test() { | 71 void Test() { |
| 68 // method should be rewritten. | 72 // method should be rewritten. |
| 69 H<BlinkClass, &BlinkClass::Method>(BlinkClass()); | 73 H<Class, &Class::Method>(Class()); |
| 70 H<not_blink::NotBlinkClass, ¬_blink::NotBlinkClass::notBlinkMethod>( | 74 // Non-Blink should stay the same. |
| 71 not_blink::NotBlinkClass()); | 75 H<not_blink::Class, ¬_blink::Class::method>(not_blink::Class()); |
| 72 } | 76 } |
| 73 | 77 |
| 74 } // namespace test_template_arg_is_method | 78 } // namespace test_template_arg_is_method |
| 75 | 79 |
| 76 // Test template arguments that are function templates. | 80 namespace test_template_arg_is_function_template { |
| 77 template <typename T, char converter(T)> | 81 |
| 78 unsigned ReallyBadHash(const T* data, unsigned length) { | 82 namespace nested { |
| 79 unsigned hash = 1; | 83 template <typename T> |
| 80 for (unsigned i = 0; i < length; ++i) { | 84 void F(T) {} |
| 81 hash *= converter(data[i]); | |
| 82 } | |
| 83 return hash; | |
| 84 } | 85 } |
| 85 | 86 |
| 86 struct StringHasher { | 87 template <typename T, void g(T)> |
| 87 static unsigned Hash(const char* data, unsigned length) { | 88 void H(T x) { |
| 88 return ReallyBadHash<char, BrokenFoldCase<char>>(data, length); | 89 g(x); |
| 89 } | 90 } |
| 90 | 91 |
| 91 private: | 92 void Test() { |
| 93 // f should be rewritten. |
| 94 H<int, nested::F>(0); |
| 95 // Non-Blink should stay the same. |
| 96 H<int, not_blink::functionTemplate>(1); |
| 97 } |
| 98 |
| 99 } // namespace test_template_arg_is_function_template |
| 100 |
| 101 namespace test_template_arg_is_method_template_in_non_member_context { |
| 102 |
| 103 struct Class { |
| 92 template <typename T> | 104 template <typename T> |
| 93 static char BrokenFoldCase(T input) { | 105 static void F(T) {} |
| 94 return input - ('a' - 'A'); | 106 }; |
| 107 |
| 108 template <typename T, void g(T)> |
| 109 void H(T x) { |
| 110 g(x); |
| 111 } |
| 112 |
| 113 void Test() { |
| 114 // f should be rewritten. |
| 115 H<int, Class::F>(0); |
| 116 // Non-Blink should stay the same. |
| 117 H<int, not_blink::Class::staticMethodTemplate>(1); |
| 118 } |
| 119 |
| 120 } // test_template_arg_is_method_template_in_non_member_context |
| 121 |
| 122 namespace test_template_arg_is_method_template_in_member_context { |
| 123 |
| 124 struct Class { |
| 125 template <typename T> |
| 126 static void F(T) {} |
| 127 }; |
| 128 |
| 129 struct Class2 { |
| 130 template <typename T> |
| 131 void F(T x) { |
| 132 // f should be rewritten. |
| 133 Class c; |
| 134 c.F(x); |
| 135 // Non-Blink should stay the same. |
| 136 not_blink::Class c2; |
| 137 c2.method(x); |
| 95 } | 138 } |
| 96 }; | 139 }; |
| 97 | 140 |
| 141 } // namespace test_template_arg_is_method_template_in_member_context |
| 142 |
| 98 } // namespace blink | 143 } // namespace blink |
| OLD | NEW |