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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: tools/clang/rewrite_to_chrome_style/tests/template-expected.cc
diff --git a/tools/clang/rewrite_to_chrome_style/tests/template-expected.cc b/tools/clang/rewrite_to_chrome_style/tests/template-expected.cc
index c62e8d0e76d5bc3afbb47b988a139e744b930901..dc46c19a3aa345014db984d2128b1f13d9cf8c86 100644
--- a/tools/clang/rewrite_to_chrome_style/tests/template-expected.cc
+++ b/tools/clang/rewrite_to_chrome_style/tests/template-expected.cc
@@ -36,20 +36,44 @@ class TemplatedClass {
namespace blink {
+bool FunctionNotMarkedConstexpr(int a) {
+ return a == 4 || a == 10;
+}
+
+template <typename T>
+bool TemplatedFunctionNotMarkedConstexpr(T t) {
+ return !!t;
+}
+
+int g_global_number;
+
template <typename T, int number>
void F() {
- // We don't assert on this, and we don't end up considering it a const for
- // now.
+ // These are const but hacker_case so we leave them alone.
const int maybe_a_const = sizeof(T);
const int is_a_const = number;
+ // These are const expressions so they get a k prefix.
+ const int kMaybeAConstToo = sizeof(T);
+ const int kIsAConstToo = number;
+ // These are built from calls to functions which produces inconsistent
+ // results so they should not be considered const to be safe.
+ const bool from_a_method = FunctionNotMarkedConstexpr(number);
+ const bool from_a_templated_method =
+ TemplatedFunctionNotMarkedConstexpr(number);
+ // A complex statement of const things is const.
+ const bool kComplexConst = number || (number + 1);
+ // A complex statement with a non-const thing is not const.
+ const bool complex_not_const = number || (g_global_number + 1);
}
template <int number, typename... T>
void F() {
- // We don't assert on this, and we don't end up considering it a const for
- // now.
+ // These are const but hacker_case so we leave them alone.
const int maybe_a_const = sizeof...(T);
const int is_a_const = number;
+ // These are const expressions so they get a k prefix.
+ const int kMaybeAConstToo = sizeof...(T);
+ const int kIsAConstToo = number;
}
namespace test_template_arg_is_function {
@@ -66,6 +90,15 @@ void Test() {
H<int, F>(0);
// Non-Blink should stay the same.
H<int, not_blink::function>(1);
+
+ // The int one makes the methods called from F() considered as constexpr, and
+ // can be collapsed to not have template arguments before it reaches the AST.
+ F<int, 10>();
+ // The enum one makes them not constexpr, as it doesn't collapse away the
+ // template stuff as much. This can lead to conflicting decisions about
+ // the names inside F() vs the above instantiation.
+ enum E { A };
+ F<E, 11>();
}
} // namespace test_template_arg_is_function

Powered by Google App Engine
This is Rietveld 408576698