[cfe-dev] Problem to match a break in a for loop

Loïc Joly via cfe-dev cfe-dev at lists.llvm.org
Tue Jul 4 15:54:09 PDT 2017


This is a repost, my initial post seems to be lost... Sorry if you 
already received it...

Hello,

I’m trying to write a matcher for a break in a for loop. I’m writing it 
that way:
         breakStmt(
             hasAncestor(anyOf(
                 forStmt().bind(breakForParent), // A break can happen 
in a for
                 doStmt(), // or in another loop
                 whileStmt(),
                 cxxForRangeStmt(),
                 switchStmt() // or in a switch
             ))


The goal is to match the closest ancestor that can have some meaning for 
a break statement, and detect if it is a for loop or another statement.

This looks to work fine when I’m in clang-query, but when I try to 
compile the code (with visual C++), I have the following error:

1>xxx.cpp(149): error C2784: 
'clang::ast_matchers::internal::ArgumentAdaptingMatcherFunc<clang::ast_matchers::internal::HasAncestorMatcher,clang::ast_matchers::internal::TypeList<clang::Decl,clang::NestedNameSpecifierLoc,clang::Stmt,clang::TypeLoc>,clang::ast_matchers::internal::TypeList<clang::Decl,clang::NestedNameSpecifierLoc,clang::Stmt,clang::TypeLoc>>::Adaptor<T> 
clang::ast_matchers::internal::ArgumentAdaptingMatcherFunc<clang::ast_matchers::internal::HasAncestorMatcher,clang::ast_matchers::internal::TypeList<clang::Decl,clang::NestedNameSpecifierLoc,clang::Stmt,clang::TypeLoc>,clang::ast_matchers::internal::TypeList<clang::Decl,clang::NestedNameSpecifierLoc,clang::Stmt,clang::TypeLoc>>::operator 
()(const clang::ast_matchers::internal::Matcher<From> &) const' : could 
not deduce template argument for 'const 
clang::ast_matchers::internal::Matcher<From> &' from 
'clang::ast_matchers::internal::VariadicOperatorMatcher<clang::ast_matchers::internal::Matcher<clang::Stmt>,ResultT,ResultT,ResultT,ResultT>'
1>        with
1>        [
1> ResultT=clang::ast_matchers::internal::BindableMatcher<clang::Stmt>
1>        ]
1>        include\clang\astmatchers\astmatchersinternal.h(1054) : see 
declaration of 
'clang::ast_matchers::internal::ArgumentAdaptingMatcherFunc<clang::ast_matchers::internal::HasAncestorMatcher,clang::ast_matchers::internal::TypeList<clang::Decl,clang::NestedNameSpecifierLoc,clang::Stmt,clang::TypeLoc>,clang::ast_matchers::internal::TypeList<clang::Decl,clang::NestedNameSpecifierLoc,clang::Stmt,clang::TypeLoc>>::operator 
()'

Is this something I’m not supposed to do, or is it more something like a 
bug in clang or in my compiler?

Thank you,

---
Loïc Joly




More information about the cfe-dev mailing list