Problem to match a break in a for loop

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problem to match a break in a for loop

Xin Wang via cfe-dev
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

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem to match a break in a for loop

Xin Wang via cfe-dev
Hello,

There is missing closing ')' in your snippet (I think it is a typo).

The following works fine in clang query

breakStmt(hasAncestor(anyOf(forStmt().bind("breakForParent"),doStmt(),
whileStmt(),cxxForRangeStmt(),switchStmt())))

On

int main(int argc, char *argv[])
{
   for(int i = 0 ;i < 10;++i){
   if(i == 5){break;}
}


it outputs

/home/david/code/d.cpp:118:3: note: "breakForParent" binds here
   for(int i = 0 ;i < 10;++i){
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/david/code/d.cpp:119:13: note: "root" binds here
  if(i == 5){break;}

David Come
On 05/07/2017 00:54, Loïc Joly via cfe-dev wrote:

> 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
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...