[cfe-dev] Template instantiation in Clang checker

Valentin Tolmer via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 16 08:46:06 PDT 2019


Hi,

I'm working on a clang-tidy checker, and I want to be able to evaluate a
static condition on a class I'm matching, do you know if that's possible?
I have a templated integral_constant<bool, my_condition<T>>, and I want to
know the value for a given T. In more accurate details, here's the code:

In the application code:
typedef std::integral_constant<bool, sizeof(MyCondition<T>(
                                             static_cast<const T*>(0))) ==
                                             sizeof(char)>
        my_great_condition;

In the clang checker:

bool IsTypeWithMyCondition(const clang::QualType &type,
                       const MatchFinder::MatchResult &result) {
  return !ast_matchers::match(
              qualType(
                  hasUnqualifiedDesugaredType(recordType(hasDeclaration(
                      cxxRecordDecl(isDerivedFrom("::MyBaseClass"))))))
                  .bind("type"),
              type, *result.Context)
              .empty();
}

I would like to additionally match that my_great_condition<type> evaluates
to true. Do you know how I can achieve that?

Thanks,

-- 
Valentin Tolmer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190416/b8dd23e3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4845 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190416/b8dd23e3/attachment.bin>


More information about the cfe-dev mailing list