Kaydet (Commit) 80a30219 authored tarafından Noel Grandin's avatar Noel Grandin

new loplugin:dodgyswitch

and fix bug in ScriptDocument::getTitle
which has been there since

    commit e304ba66
    Date:   Thu Mar 15 14:59:30 2007 +0000
    INTEGRATION: CWS basmgr02 (1.1.2); FILE ADDED

plugin is off by default since it uses expensive parentStmt() calls

Change-Id: Id0f16baec48e0381e0083594d7e59b58b023da2f
Reviewed-on: https://gerrit.libreoffice.org/43750Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 3fa0fc68
......@@ -1475,6 +1475,7 @@ namespace basctl
case LibraryType::All: aTitle = IDEResId(RID_STR_USERMACROSDIALOGS); break;
default:
break;
}
}
break;
case LIBRARY_LOCATION_SHARE:
......@@ -1494,7 +1495,6 @@ namespace basctl
break;
default:
break;
}
}
return aTitle;
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <cassert>
#include <string>
#include <iostream>
#include <fstream>
#include <set>
#include "plugin.hxx"
namespace {
class DodgySwitch:
public RecursiveASTVisitor<DodgySwitch>, public loplugin::Plugin
{
public:
explicit DodgySwitch(InstantiationData const & data): Plugin(data) {}
virtual void run() override
{
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
bool VisitDefaultStmt(DefaultStmt const * );
bool VisitCaseStmt(CaseStmt const * );
private:
bool IsParentSwitch(Stmt const * );
};
bool DodgySwitch::VisitDefaultStmt(DefaultStmt const * defaultStmt)
{
if (ignoreLocation(defaultStmt))
return true;
if (!IsParentSwitch(defaultStmt))
report(
DiagnosticsEngine::Warning, "default statement not directly under switch",
defaultStmt->getLocStart())
<< defaultStmt->getSourceRange();
return true;
}
bool DodgySwitch::VisitCaseStmt(CaseStmt const * caseStmt)
{
if (ignoreLocation(caseStmt))
return true;
if (!IsParentSwitch(caseStmt))
{
//parentStmt(parentStmt(caseStmt))->dump();
report(
DiagnosticsEngine::Warning, "case statement not directly under switch",
caseStmt->getLocStart())
<< caseStmt->getSourceRange();
}
return true;
}
bool DodgySwitch::IsParentSwitch(Stmt const * stmt)
{
auto parent = parentStmt(stmt);
if (isa<CaseStmt>(parent) || isa<DefaultStmt>(parent)) // daisy chain
return true;
auto compoundStmt = dyn_cast<CompoundStmt>(parent);
if (!compoundStmt)
return false;
return isa<SwitchStmt>(parentStmt(compoundStmt));
}
loplugin::Plugin::Registration< DodgySwitch > X("dodgyswitch", false);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/types.h>
int foo();
int main() {
switch (foo())
{
case 1: { break; }
case 2: {
SAL_FALLTHROUGH;
{
case 3: // expected-error {{case statement not directly under switch [loplugin:dodgyswitch]}}
break;
}
default: // expected-error {{default statement not directly under switch [loplugin:dodgyswitch]}}
break;
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -18,6 +18,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
$(if $(filter-out INTEL,$(CPU)),compilerplugins/clang/test/convertuintptr) \
compilerplugins/clang/test/cppunitassertequals \
compilerplugins/clang/test/datamembershadow \
compilerplugins/clang/test/dodgyswitch \
compilerplugins/clang/test/droplong \
compilerplugins/clang/test/externvar \
compilerplugins/clang/test/expressionalwayszero \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment