[cfe-dev] [clang-tidy] hasParent for CXXCtorInitializer

Piotr Padlewski via cfe-dev cfe-dev at lists.llvm.org
Wed Apr 27 14:29:54 PDT 2016


2016-04-27 10:10 GMT+02:00 Manuel Klimek <klimek at google.com>:

> +sam and benjamin
>
> On Tue, Apr 26, 2016 at 5:51 PM Alexander Kornienko <alexfh at google.com>
> wrote:
>
>> Manuel, do you have an idea what could be wrong here?
>>
>
> Generally, I'd expect this to happen if the CXXCtorInitializer is not in
> the parent map. A patch with a failing test might help to see the problem.
>
>
But I wouldn't expect that the second matcher that uses hasAncestor doesn't
work either.
I will generate the patch for the second matcher tomorrow.


>
>>
>> On Sat, Apr 16, 2016 at 7:22 PM, Piotr Padlewski <
>> piotr.padlewski at gmail.com> wrote:
>>
>>> Hi folks,
>>> I was wondering what is the best way to get to the CXXCtroInitializer
>>> from child.
>>>
>>> In code like this:
>>> struct A {
>>>     A() : a(false), c(false) {}
>>>     unsigned a : 1;
>>>     unsigned c : 3;
>>> };
>>>
>>> I am looking for implicit casts from bool.
>>> I added CXXCtorInitializer into hasParent like this:
>>>
>>> const internal::ArgumentAdaptingMatcherFunc<
>>>     internal::HasParentMatcher,
>>>     internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc,
>>> CXXCtorInitializer>,
>>>     internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc>>
>>>     LLVM_ATTRIBUTE_UNUSED hasParent = {};
>>>
>>> so clang-query doesn't reject matcher:
>>> implicitCastExpr(hasParent(cxxCtorInitializer()))
>>> but it doesn't match with anything.
>>>
>>> I also tried something like this:
>>>
>>>   auto matcher =
>>> hasAncestor(cxxConstructorDecl(hasAnyConstructorInitializer(
>>>     cxxCtorInitializer(forField(isOneBitBitField()),
>>>
>>>  withInitializer(implicitCastExpr(equalsBoundNode("cast")))
>>>                        ))));
>>>
>>> and then
>>> implicitCastExpr(matcher).bind("cast")
>>>
>>> but it doesn't seems to work either.
>>> Any thoughts?
>>>
>>> Piotr
>>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160427/cf7c6d1a/attachment.html>


More information about the cfe-dev mailing list