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
3 // found in the LICENSE file.
4
5 namespace not_blink {
6
function(int x)7 void function(int x) {}
8
9 class Class {
10 public:
method()11 void method() {}
12 template <typename T>
methodTemplate(T)13 void methodTemplate(T) {}
14 template <typename T>
staticMethodTemplate(T)15 static void staticMethodTemplate(T) {}
16 };
17
18 template <typename T>
functionTemplate(T x)19 void functionTemplate(T x) {}
20
21 } // not_blink
22
23 namespace blink {
24
25 template <typename T, int number>
F()26 void F() {
27 // We don't assert on this, and we don't end up considering it a const for
28 // now.
29 const int maybe_a_const = sizeof(T);
30 const int is_a_const = number;
31 }
32
33 template <int number, typename... T>
F()34 void F() {
35 // We don't assert on this, and we don't end up considering it a const for
36 // now.
37 const int maybe_a_const = sizeof...(T);
38 const int is_a_const = number;
39 }
40
41 namespace test_template_arg_is_function {
42
f(int x)43 void f(int x) {}
44
45 template <typename T, void g(T)>
h(T x)46 void h(T x) {
47 g(x);
48 }
49
test()50 void test() {
51 // f should be rewritten.
52 h<int, f>(0);
53 // Non-Blink should stay the same.
54 h<int, not_blink::function>(1);
55 }
56
57 } // namespace test_template_arg_is_function
58
59 namespace test_template_arg_is_method {
60
61 class Class {
62 public:
method()63 void method() {}
64 };
65
66 template <typename T, void (T::*g)()>
h(T && x)67 void h(T&& x) {
68 (x.*g)();
69 }
70
test()71 void test() {
72 // method should be rewritten.
73 h<Class, &Class::method>(Class());
74 // Non-Blink should stay the same.
75 h<not_blink::Class, ¬_blink::Class::method>(not_blink::Class());
76 }
77
78 } // namespace test_template_arg_is_method
79
80 namespace test_template_arg_is_function_template {
81
82 namespace nested {
83 template <typename T>
f(T)84 void f(T) {}
85 }
86
87 template <typename T, void g(T)>
h(T x)88 void h(T x) {
89 g(x);
90 }
91
test()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 {
104 template <typename T>
fblink::test_template_arg_is_method_template_in_non_member_context::Class105 static void f(T) {}
106 };
107
108 template <typename T, void g(T)>
h(T x)109 void h(T x) {
110 g(x);
111 }
112
test()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>
fblink::test_template_arg_is_method_template_in_member_context::Class126 static void f(T) {}
127 };
128
129 struct Class2 {
130 template <typename T>
fblink::test_template_arg_is_method_template_in_member_context::Class2131 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);
138 }
139 };
140
141 } // namespace test_template_arg_is_method_template_in_member_context
142
143 namespace test_unnamed_arg {
144
145 template <typename T>
146 class Class {
147 public:
148 // Test for https://crbug.com/598141 - shouldn't rewrite
149 // ...int);
150 // into
151 // ...intdata_size;
152 void f(int);
153 };
154
155 template <typename T>
f(int dataSize)156 void Class<T>::f(int dataSize){};
157
foo()158 void foo() {
159 Class<char>().f(123);
160 };
161
162 } // namespace test_unnamed_arg
163
164 } // namespace blink
165