summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compilerplugins/clang/conststringvar.cxx27
1 files changed, 17 insertions, 10 deletions
diff --git a/compilerplugins/clang/conststringvar.cxx b/compilerplugins/clang/conststringvar.cxx
index c5e83722ac47..99cfb01c06f7 100644
--- a/compilerplugins/clang/conststringvar.cxx
+++ b/compilerplugins/clang/conststringvar.cxx
@@ -27,17 +27,24 @@ public:
explicit ConstStringVar(loplugin::InstantiationData const & data):
FilteringPlugin(data) {}
+ bool preRun() override {
+ return compiler.getLangOpts().CPlusPlus;
+ // clang::Expr::isCXX11ConstantExpr only works for C++
+ }
+
+ void postRun() override {
+ for (auto v: vars_) {
+ report(
+ DiagnosticsEngine::Warning,
+ "variable is only used as rvalue, should be const",
+ v->getLocation())
+ << v->getSourceRange();
+ }
+ }
+
void run() override {
- if (compiler.getLangOpts().CPlusPlus) {
- // clang::Expr::isCXX11ConstantExpr only works for C++
- TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
- for (auto v: vars_) {
- report(
- DiagnosticsEngine::Warning,
- "variable is only used as rvalue, should be const",
- v->getLocation())
- << v->getSourceRange();
- }
+ if (preRun() && TraverseDecl(compiler.getASTContext().getTranslationUnitDecl())) {
+ postRun();
}
}