Matcher working in clang-query, but not in LibTooling

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Matcher working in clang-query, but not in LibTooling

David Blaikie via cfe-dev
Hello everyone,

Why is it that the following matcher 

cxxRecordDecl(has(unless(cxxRecordDecl())))

works in clang-query, but when copied to to a .cpp file, it won't compile the matcher:

../lib/UsingAnalysis.cpp:46:29: error: no matching function for call to object of type 'const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher>'
    auto m = cxxRecordDecl(has(unless(cxxRecordDecl())));
                           ^~~
/usr/local/include/clang/ASTMatchers/ASTMatchersInternal.h:1183:3: note: candidate template ignored: could not match 'Matcher' against 'VariadicOperatorMatcher'
  operator()(const Matcher<T> &InnerMatcher) const {

Tried on macOS 10.13 & Ubuntu 20.04 with LLVM 11.0.0.

Best,
Siegfried

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

Re: Matcher working in clang-query, but not in LibTooling

David Blaikie via cfe-dev
A minimal code sample to trigger the error:

#include "clang/ASTMatchers/ASTMatchers.h"

using namespace clang::ast_matchers;

int main(int argc, char** argv){
    auto m = cxxRecordDecl(has(unless(cxxRecordDecl())));
    return 0;

}

Best, Siegfried

On 16Nov, 2020, at 16:57, Hartogs Siegfried <[hidden email]> wrote:

Hello everyone,

Why is it that the following matcher 

cxxRecordDecl(has(unless(cxxRecordDecl())))

works in clang-query, but when copied to to a .cpp file, it won't compile the matcher:

../lib/UsingAnalysis.cpp:46:29: error: no matching function for call to object of type 'const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher>'
    auto m = cxxRecordDecl(has(unless(cxxRecordDecl())));
                           ^~~
/usr/local/include/clang/ASTMatchers/ASTMatchersInternal.h:1183:3: note: candidate template ignored: could not match 'Matcher' against 'VariadicOperatorMatcher'
  operator()(const Matcher<T> &InnerMatcher) const {

Tried on macOS 10.13 & Ubuntu 20.04 with LLVM 11.0.0.

Best,
Siegfried


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

Re: Matcher working in clang-query, but not in LibTooling

David Blaikie via cfe-dev


clang-query parsing is less strict than the c++ language, so there are probably a few of these differences.

I assume you realize that you should instead use either

unless(has())

or

has(decl(unless(cxxRecordDecl())))

depending on what you are trying to achieve?


On 16/11/2020 17:33, Hartogs Siegfried via cfe-dev wrote:
A minimal code sample to trigger the error:

#include "clang/ASTMatchers/ASTMatchers.h"

using namespace clang::ast_matchers;

int main(int argc, char** argv){
    auto m = cxxRecordDecl(has(unless(cxxRecordDecl())));
    return 0;

}

Best, Siegfried

On 16Nov, 2020, at 16:57, Hartogs Siegfried <[hidden email]> wrote:

Hello everyone,

Why is it that the following matcher 

cxxRecordDecl(has(unless(cxxRecordDecl())))

works in clang-query, but when copied to to a .cpp file, it won't compile the matcher:

../lib/UsingAnalysis.cpp:46:29: error: no matching function for call to object of type 'const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher>'
    auto m = cxxRecordDecl(has(unless(cxxRecordDecl())));
                           ^~~
/usr/local/include/clang/ASTMatchers/ASTMatchersInternal.h:1183:3: note: candidate template ignored: could not match 'Matcher' against 'VariadicOperatorMatcher'
  operator()(const Matcher<T> &InnerMatcher) const {

Tried on macOS 10.13 & Ubuntu 20.04 with LLVM 11.0.0.

Best,
Siegfried


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

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

Re: Matcher working in clang-query, but not in LibTooling

David Blaikie via cfe-dev
Hi, thanks for your answer!
Your second matcher proposal captures the right behavior: I want to match 
declarations that are of any kind but that specific one.
On the internet I read to use clang-query to prototype matchers, so I was pretty surprised
that it didn't work when I copied it over.
Best,
Siegfried

On 17Nov, 2020, at 13:01, Stephen Kelly <[hidden email]> wrote:

clang-query parsing is less strict than the c++ language, so there are probably a few of these differences.

I assume you realize that you should instead use either

unless(has())

or

has(decl(unless(cxxRecordDecl())))

depending on what you are trying to achieve?


On 16/11/2020 17:33, Hartogs Siegfried via cfe-dev wrote:
A minimal code sample to trigger the error:

#include "clang/ASTMatchers/ASTMatchers.h"

using namespace clang::ast_matchers;

int main(int argc, char** argv){
    auto m = cxxRecordDecl(has(unless(cxxRecordDecl())));
    return 0;

}

Best, Siegfried

On 16Nov, 2020, at 16:57, Hartogs Siegfried <[hidden email]> wrote:

Hello everyone,

Why is it that the following matcher 

cxxRecordDecl(has(unless(cxxRecordDecl())))

works in clang-query, but when copied to to a .cpp file, it won't compile the matcher:

../lib/UsingAnalysis.cpp:46:29: error: no matching function for call to object of type 'const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher>'
    auto m = cxxRecordDecl(has(unless(cxxRecordDecl())));
                           ^~~
/usr/local/include/clang/ASTMatchers/ASTMatchersInternal.h:1183:3: note: candidate template ignored: could not match 'Matcher' against 'VariadicOperatorMatcher'
  operator()(const Matcher<T> &InnerMatcher) const {

Tried on macOS 10.13 & Ubuntu 20.04 with LLVM 11.0.0.

Best,
Siegfried


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


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