forked from OSchip/llvm-project
Fix segfault in hasDeclContext for nodes that have no decl context.
Summary: Some declarations do not have a declaration context, like TranslationUnitDecl. Fix hasDeclContext() to not segfault on these nodes. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D6003 llvm-svn: 220719
This commit is contained in:
parent
e9afaf71f7
commit
d93fcc1b28
|
@ -3567,8 +3567,9 @@ AST_MATCHER_P(ElaboratedType, namesType, internal::Matcher<QualType>,
|
|||
/// \c recordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the
|
||||
/// declaration of \c class \c D.
|
||||
AST_MATCHER_P(Decl, hasDeclContext, internal::Matcher<Decl>, InnerMatcher) {
|
||||
return InnerMatcher.matches(*Decl::castFromDeclContext(Node.getDeclContext()),
|
||||
Finder, Builder);
|
||||
const DeclContext *DC = Node.getDeclContext();
|
||||
if (!DC) return false;
|
||||
return InnerMatcher.matches(*Decl::castFromDeclContext(DC), Finder, Builder);
|
||||
}
|
||||
|
||||
/// \brief Matches nested name specifiers.
|
||||
|
|
|
@ -375,6 +375,8 @@ TEST(DeclarationMatcher, hasDeclContext) {
|
|||
"}",
|
||||
recordDecl(hasDeclContext(namespaceDecl(
|
||||
hasName("M"), hasDeclContext(namespaceDecl()))))));
|
||||
|
||||
EXPECT_TRUE(matches("class D{};", decl(hasDeclContext(decl()))));
|
||||
}
|
||||
|
||||
TEST(DeclarationMatcher, LinkageSpecification) {
|
||||
|
|
Loading…
Reference in New Issue