Skip to content

Commit

Permalink
Fixed #108: Two different matchers did match the same statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Fertig committed Jan 10, 2019
1 parent afb5024 commit 9cf81c9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
11 changes: 3 additions & 8 deletions AutoStmtHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,18 @@ using namespace clang;
using namespace clang::ast_matchers;
//-----------------------------------------------------------------------------

namespace clang::ast_matchers {

// XXX: recent clang source has a declType matcher. Try to figure out a migration path.
const internal::VariadicDynCastAllOfMatcher<Type, DecltypeType> myDecltypeType;
//-----------------------------------------------------------------------------
} // namespace clang::ast_matchers

namespace clang::insights {

AutoStmtHandler::AutoStmtHandler(Rewriter& rewrite, MatchFinder& matcher)
: InsightsBase(rewrite)
{

static const auto isAutoAncestor =
hasAncestor(varDecl(anyOf(hasType(autoType().bind("autoType")),
hasType(qualType(hasDescendant(autoType().bind("autoType")))),
/* decltype and decltype(auto) */
hasType(myDecltypeType().bind("dt")),
hasType(qualType(hasDescendant(myDecltypeType().bind("dt")))))));

matcher.addMatcher(varDecl(unless(anyOf(isExpansionInSystemHeader(),
isMacroOrInvalidLocation(),
isAutoAncestor,
Expand Down
1 change: 1 addition & 0 deletions ImplicitCastHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ImplicitCastHandler::ImplicitCastHandler(Rewriter& rewrite, MatchFinder& matcher
anyOf(isExpansionInSystemHeader(),
isMacroOrInvalidLocation(),
isTemplate,
isAutoAncestor,
hasAncestor(functionDecl()),
hasAncestor(userDefinedLiteral()),
hasAncestor(implicitCastExpr(hasMatchingCast())), /* will be catch by the walk down */
Expand Down
12 changes: 12 additions & 0 deletions InsightsMatchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@
namespace clang {
namespace ast_matchers {

// XXX: recent clang source has a declType matcher. Try to figure out a migration path.
extern const internal::VariadicDynCastAllOfMatcher<Type, DecltypeType> myDecltypeType;
//-----------------------------------------------------------------------------

/* don't replace stuff in template definitions */
static const auto isTemplate = anyOf(hasAncestor(classTemplateDecl()),
hasAncestor(functionTemplateDecl()),
hasAncestor(classTemplateSpecializationDecl()));
//-----------------------------------------------------------------------------

static const auto isAutoAncestor =
hasAncestor(varDecl(anyOf(hasType(autoType().bind("autoType")),
hasType(qualType(hasDescendant(autoType().bind("autoType")))),
/* decltype and decltype(auto) */
hasType(myDecltypeType().bind("dt")),
hasType(qualType(hasDescendant(myDecltypeType().bind("dt")))))));
//-----------------------------------------------------------------------------

/// \brief Shut up a unused variable warnings
#define SILENCE \
(void)Finder; \
Expand Down
7 changes: 3 additions & 4 deletions tests/Issue106.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
int main()
{
auto p = new int[2][3][4];
auto p = new int[3][3][4];

// auto z = new int[1];
auto z = new int[1];

// auto x = new int;
auto x = new int;
}

5 changes: 3 additions & 2 deletions tests/Issue106.expect
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
int main()
{
int (*p)[3][4] = new int [2][3][4];
int (*p)[3][4] = new int [3][3][4];
int * z = new int[1];
int * x = new int;
}


11 changes: 11 additions & 0 deletions tests/Issue108.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
auto gp = new int[2][3][4];

auto gz = new int[1];

auto gx = new int;

auto gu = new int[0x2][0x3][0x4];

int main()
{
}

0 comments on commit 9cf81c9

Please sign in to comment.