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 data_size)156 void Class<T>::F(int data_size){};
157
Foo()158 void Foo() {
159 Class<char>().F(123);
160 };
161
162 } // namespace test_unnamed_arg
163
164 } // namespace blink
165