[cfe-dev] How to compare Attr location with Decl location?

Jacob Bandes-Storch via cfe-dev cfe-dev at lists.llvm.org
Sat May 5 13:33:38 PDT 2018


I am using an AST matcher and would like to prevent an annotation attribute
from being placed on an out-of-line constructor definition.

    class Foo {
        explicit Foo(int);  // ok
        [[clang::annotate("implicit")]] Foo(int);  // ok
    };

    explicit Foo::Foo() {}  // *disallowed*
    [[clang::annotate("implicit")]] Foo::Foo(int) {}  // *should be
disallowed*


However it seems that when I match the out-of-line decl,
`decl->specific_attrs<AnnotateAttr>()` contains the attribute *even if it
was placed on the original in-class declaration* and not on the out-of-line
definition.

How can I determine whether an Attr* was written on the out-of-line decl?

I tried checking (!(attr->getLocation() < decl->getLocStart()) &&
!(decl->getLocEnd() < attr->getLocation())), however it seems the two
locations are not comparable. When I look at their getRawEncoding()s, the
attribute has values in ranges like 2147587494-2147587527 while the decl's
values are more reasonable, such as 3049-3079. I couldn't find any
documentation about attribute source locations being negative.


Thanks,
Jacob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180505/34990282/attachment.html>


More information about the cfe-dev mailing list