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

Unified Diff: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp

Issue 2622003002: rewrite_to_chrome_style: Make is-const decisions more consistent (Closed)
Patch Set: consistant-consts-2 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
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/template-expected.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
diff --git a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
index 945c686519381461e28dbd1838ec5c86ad7e836f..5141ccf6bda64f71f78f291fa5f2cba57a88a038 100644
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
@@ -391,15 +391,36 @@ bool CanBeEvaluatedAtCompileTime(const clang::Stmt* stmt,
return false;
}
- // If the expression is a template input then its coming at compile time so
- // we consider it const. And we can't check isEvaluatable() in this case as
- // it will do bad things/crash.
- if (expr->isInstantiationDependent())
- return true;
+ // If the expression depends on template input, we can not call
+ // isEvaluatable() on it as it will do bad things/crash.
+ if (!expr->isInstantiationDependent()) {
+ // If the expression can be evaluated at compile time, then it should have a
+ // kFoo style name. Otherwise, not.
+ return expr->isEvaluatable(context);
+ }
- // If the expression can be evaluated at compile time, then it should have a
- // kFoo style name. Otherwise, not.
- return expr->isEvaluatable(context);
+ // We do our best to figure out special cases as we come across them here, for
+ // template dependent situations. Some cases in code are only considered
+ // instantiation dependent for some template instantiations! Which is
+ // terrible! So most importantly we try to match isEvaluatable in those cases.
+ switch (expr->getStmtClass()) {
+ case clang::Stmt::CXXThisExprClass:
+ return false;
+ case clang::Stmt::DeclRefExprClass: {
+ auto* declref = clang::dyn_cast<clang::DeclRefExpr>(expr);
+ auto* decl = declref->getDecl();
+ if (clang::dyn_cast<clang::VarDecl>(decl))
dcheng 2017/01/11 17:03:12 Nit: use isa... except I guess the followup CL cha
+ return false;
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ // Otherwise, we consider depending on template parameters to not interfere
+ // with being const.. with exceptions hopefully covered above.
+ return true;
}
bool IsProbablyConst(const clang::VarDecl& decl,
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/template-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698