[cfe-dev] [clang-tidy] using isInTemplateInstantiation asserts

Piotr Padlewski via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 12 11:32:03 PDT 2016


yep, the same assert on most recent build. Are you sure your assertions are
enabled?

2016-04-12 20:26 GMT+02:00 Piotr Padlewski <piotr.padlewski at gmail.com>:

> I am building most recent debug build right now, but what I saw in the
> code, there was no chanes in ASTTypeTraits.* files since so I don't excpect
> it will make a difference.
>
> 2016-04-12 20:23 GMT+02:00 Alexander Kornienko <alexfh at google.com>:
>
>> I use an assertions-enabled build of clang-query built just a few hours
>> ago.
>>
>> On Tue, Apr 12, 2016 at 8:00 PM, Piotr Padlewski <
>> piotr.padlewski at gmail.com> wrote:
>>
>>> Are you using debug build?
>>> when I use the second matcher that you have send I got core dump.
>>>
>>> http://pastebin.com/Z6V3jC3X
>>>
>>> I am not using the most recent clang trunk, but someting about 2 weeks
>>> old, but I don't think it is the case.
>>> BTW on other build it works perfectly, it doesn;t crash etc, but it has
>>> asserts disabled.
>>>
>>>
>>>
>>>
>>> 2016-04-12 19:50 GMT+02:00 Alexander Kornienko <alexfh at google.com>:
>>>
>>>> FWIW, a larger part of your matcher also works fine in clang-query:
>>>> $ cat /tmp/q.cc
>>>> namespace boost {
>>>> template <typename T, typename C>
>>>> T lexical_cast(const C&) {
>>>>   return T();
>>>> }
>>>> }
>>>>
>>>> namespace std {
>>>> template <typename T>
>>>> class basic_string {};
>>>> using string = basic_string<char>;
>>>> }
>>>>
>>>> int g();
>>>> long long f(int p);
>>>> using namespace boost;
>>>>
>>>> template <typename T>
>>>> void string_as_T() {
>>>>   boost::lexical_cast<T>(42);
>>>> }
>>>>
>>>> int main() {
>>>>   string_as_T<std::string>();
>>>>   boost::lexical_cast<std::string>(24);
>>>> }
>>>>
>>>> $ clang-query /tmp/q.cc -- -std=c++11
>>>> clang-query> m
>>>> callExpr(hasDeclaration(functionDecl(returns(hasDeclaration(classTemplateSpecializationDecl(hasName("std::basic_string"),hasTemplateArgument(0,templateArgument().bind("char_type"))))),hasName("boost::lexical_cast"),hasParameter(0,
>>>> hasType(qualType())))),argumentCountIs(1))
>>>>
>>>> Match #1:
>>>>
>>>> /tmp/q.cc:20:3: note: "root" binds here
>>>>   boost::lexical_cast<T>(42);
>>>>   ^~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>
>>>> Match #2:
>>>>
>>>> /tmp/q.cc:25:3: note: "root" binds here
>>>>   boost::lexical_cast<std::string>(24);
>>>>   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>> 2 matches.
>>>> clang-query> m
>>>> callExpr(hasDeclaration(functionDecl(returns(hasDeclaration(classTemplateSpecializationDecl(hasName("std::basic_string"),hasTemplateArgument(0,templateArgument().bind("char_type"))))),hasName("boost::lexical_cast"),hasParameter(0,
>>>> hasType(qualType())))),argumentCountIs(1),unless(isInTemplateInstantiation()))
>>>>
>>>> Match #1:
>>>>
>>>> /tmp/q.cc:25:3: note: "root" binds here
>>>>   boost::lexical_cast<std::string>(24);
>>>>   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>> 1 match.
>>>> clang-query> ^D
>>>>
>>>>
>>>> (the first matcher lacks the `unless(isInTemplateInstantiation())`
>>>> part, the second one has it, hence it skips the match in a template
>>>> instantiation).
>>>>
>>>> The only part of your matcher that is missing from this example is
>>>> `has(substTemplateTypeParmType(isStrictlyInteger()))` that needs a
>>>> locally-defined matcher `isStrictlyInteger()`.
>>>>
>>>>
>>>> On Tue, Apr 12, 2016 at 7:44 PM, Piotr Padlewski <
>>>> piotr.padlewski at gmail.com> wrote:
>>>>
>>>>> It requires this patch:
>>>>> http://reviews.llvm.org/D18274
>>>>>
>>>>> I am trying to reproduce it right now with clang-query
>>>>>
>>>>> 2016-04-12 19:27 GMT+02:00 Alexander Kornienko <alexfh at google.com>:
>>>>>
>>>>>> I can't reproduce the issue (how I understand it) using clang-query,
>>>>>> and http://reviews.llvm.org/D18136 doesn't apply cleanly, since it
>>>>>> depends on some other patch.
>>>>>>
>>>>>> $ cat /tmp/q.cc
>>>>>> namespace boost {
>>>>>> template <typename T, typename C>
>>>>>> T lexical_cast(const C&) {
>>>>>>   return T();
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> namespace std {
>>>>>> template <typename T>
>>>>>> class basic_string {};
>>>>>> using string = basic_string<char>;
>>>>>> }
>>>>>>
>>>>>> int g();
>>>>>> long long f(int p);
>>>>>> using namespace boost;
>>>>>>
>>>>>> template <typename T>
>>>>>> void string_as_T() {
>>>>>>   boost::lexical_cast<T>(42);
>>>>>> }
>>>>>>
>>>>>> int main() { string_as_T<std::string>(); }
>>>>>>
>>>>>> $ clang-query /tmp/q.cc -- -std=c++11
>>>>>> clang-query> m callExpr()
>>>>>>
>>>>>> Match #1:
>>>>>>
>>>>>> /tmp/q.cc:20:3: note: "root" binds here
>>>>>>   boost::lexical_cast<T>(42);
>>>>>>   ^~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>>
>>>>>> Match #2:
>>>>>>
>>>>>> /tmp/q.cc:20:3: note: "root" binds here
>>>>>>   boost::lexical_cast<T>(42);
>>>>>>   ^~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>>
>>>>>> Match #3:
>>>>>>
>>>>>> /tmp/q.cc:23:14: note: "root" binds here
>>>>>> int main() { string_as_T<std::string>(); }
>>>>>>              ^~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>> 3 matches.
>>>>>> clang-query> m callExpr(unless(isInTemplateInstantiation()))
>>>>>>
>>>>>> Match #1:
>>>>>>
>>>>>> /tmp/q.cc:20:3: note: "root" binds here
>>>>>>   boost::lexical_cast<T>(42);
>>>>>>   ^~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>>
>>>>>> Match #2:
>>>>>>
>>>>>> /tmp/q.cc:23:14: note: "root" binds here
>>>>>> int main() { string_as_T<std::string>(); }
>>>>>>              ^~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>> 2 matches.
>>>>>> clang-query>
>>>>>>
>>>>>>
>>>>>> On Thu, Apr 7, 2016 at 8:25 PM, Piotr Padlewski <
>>>>>> piotr.padlewski at gmail.com> wrote:
>>>>>>
>>>>>>> This should be enough to break this matcher
>>>>>>> http://pastebin.com/CH7a3hur
>>>>>>>
>>>>>>> 2016-04-07 18:56 GMT+02:00 Alexander Kornienko <alexfh at google.com>:
>>>>>>>
>>>>>>>> Can you provide a minimal test for this?
>>>>>>>>
>>>>>>>> On Thu, Apr 7, 2016 at 4:04 PM, Piotr Padlewski <
>>>>>>>> piotr.padlewski at gmail.com> wrote:
>>>>>>>>
>>>>>>>>> bump.
>>>>>>>>>
>>>>>>>>> 2016-04-04 20:48 GMT+02:00 Piotr Padlewski <
>>>>>>>>> piotr.padlewski at gmail.com>:
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Hi guys,
>>>>>>>>>> I am having trobles with isInTemplateInstantiation matcher. When
>>>>>>>>>> I run my matcher (http://reviews.llvm.org/D18136), it fails on
>>>>>>>>>> the assert in ASTTypeTraits.h:299, when KindId is
>>>>>>>>>> NodeKindId::NKI_TemplateArgument.
>>>>>>>>>>
>>>>>>>>>> I think my matcher is fine, and there is bug somewhere. Can
>>>>>>>>>> someone please tell me if I am doing something wrong, and if not, why it
>>>>>>>>>> doesn't work and what I should fix?
>>>>>>>>>>
>>>>>>>>>> Here is my backtrace http://4programmers.net/Pastebin/5347
>>>>>>>>>>
>>>>>>>>>> Best
>>>>>>>>>> Piotr
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160412/afbf0bab/attachment.html>


More information about the cfe-dev mailing list