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

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

Issue 2616213003: Get more consistent decisions if a statement is constant in templates (Closed)
Patch Set: consistant-consts Created 3 years, 11 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 #include <type_traits> 5 #include <type_traits>
6 6
7 namespace not_blink { 7 namespace not_blink {
8 8
9 void function(int x) {} 9 void function(int x) {}
10 10
(...skipping 18 matching lines...) Expand all
29 template <typename T = Class> 29 template <typename T = Class>
30 class TemplatedClass { 30 class TemplatedClass {
31 public: 31 public:
32 void anotherMethod() { T::staticMethodTemplate(123); } 32 void anotherMethod() { T::staticMethodTemplate(123); }
33 }; 33 };
34 34
35 } // not_blink 35 } // not_blink
36 36
37 namespace blink { 37 namespace blink {
38 38
39 bool FunctionNotMarkedConstexpr(int a) {
40 return a == 4 || a == 10;
41 }
42
43 template <typename T>
44 bool TemplatedFunctionNotMarkedConstexpr(T t) {
45 return !!t;
46 }
47
48 int g_global_number;
49
39 template <typename T, int number> 50 template <typename T, int number>
40 void F() { 51 void F() {
41 // We don't assert on this, and we don't end up considering it a const for 52 // These are const but hacker_case so we leave them alone.
42 // now.
43 const int maybe_a_const = sizeof(T); 53 const int maybe_a_const = sizeof(T);
44 const int is_a_const = number; 54 const int is_a_const = number;
55 // These are const expressions so they get a k prefix.
56 const int kMaybeAConstToo = sizeof(T);
57 const int kIsAConstToo = number;
58 // These are built from calls to functions which produces inconsistent
59 // results so they should not be considered const to be safe.
60 const bool from_a_method = FunctionNotMarkedConstexpr(number);
61 const bool from_a_templated_method =
62 TemplatedFunctionNotMarkedConstexpr(number);
63 // A complex statement of const things is const.
64 const bool kComplexConst = number || (number + 1);
65 // A complex statement with a non-const thing is not const.
66 const bool complex_not_const = number || (g_global_number + 1);
45 } 67 }
46 68
47 template <int number, typename... T> 69 template <int number, typename... T>
48 void F() { 70 void F() {
49 // We don't assert on this, and we don't end up considering it a const for 71 // These are const but hacker_case so we leave them alone.
50 // now.
51 const int maybe_a_const = sizeof...(T); 72 const int maybe_a_const = sizeof...(T);
52 const int is_a_const = number; 73 const int is_a_const = number;
74 // These are const expressions so they get a k prefix.
75 const int kMaybeAConstToo = sizeof...(T);
76 const int kIsAConstToo = number;
53 } 77 }
54 78
55 namespace test_template_arg_is_function { 79 namespace test_template_arg_is_function {
56 80
57 void F(int x) {} 81 void F(int x) {}
58 82
59 template <typename T, void g(T)> 83 template <typename T, void g(T)>
60 void H(T x) { 84 void H(T x) {
61 g(x); 85 g(x);
62 } 86 }
63 87
64 void Test() { 88 void Test() {
65 // f should be rewritten. 89 // f should be rewritten.
66 H<int, F>(0); 90 H<int, F>(0);
67 // Non-Blink should stay the same. 91 // Non-Blink should stay the same.
68 H<int, not_blink::function>(1); 92 H<int, not_blink::function>(1);
93
94 // The int one makes the methods called from F() considered as constexpr, and
95 // can be collapsed to not have template arguments before it reaches the AST.
96 F<int, 10>();
97 // The enum one makes them not constexpr, as it doesn't collapse away the
98 // template stuff as much. This can lead to conflicting decisions about
99 // the names inside F() vs the above instantiation.
100 enum E { A };
101 F<E, 11>();
69 } 102 }
70 103
71 } // namespace test_template_arg_is_function 104 } // namespace test_template_arg_is_function
72 105
73 namespace test_template_arg_is_method { 106 namespace test_template_arg_is_method {
74 107
75 class Class { 108 class Class {
76 public: 109 public:
77 void Method() {} 110 void Method() {}
78 }; 111 };
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // Need to rewrite |f| to |F| below (because this method name 335 // Need to rewrite |f| to |F| below (because this method name
303 // does get rewritten when processing blink::test_unnamed_arg::Class). 336 // does get rewritten when processing blink::test_unnamed_arg::Class).
304 // See also https://crbug.com/670434. 337 // See also https://crbug.com/670434.
305 output->F(123); 338 output->F(123);
306 } 339 }
307 }; 340 };
308 341
309 } // namespace blink_methods_called_from_mojo_traits_are_not_rewritten 342 } // namespace blink_methods_called_from_mojo_traits_are_not_rewritten
310 343
311 } // namespace not_blink 344 } // namespace not_blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698