[cfe-dev] getLocation() for a friend type declaration

Manuel Klimek klimek at google.com
Mon Apr 7 03:12:53 PDT 2014


On Mon, Apr 7, 2014 at 11:51 AM, Дмитрий Борисенков
<stackoverflow at xakep.ru>wrote:

> Hello Manuel,
>
> I've implemented RecursiveASTVisitor with the following VisitXXX method:
>
>    bool VisitFriendDecl(FriendDecl *Declaration) {
>       FullSourceLoc FullLocation =
> Context->getFullLoc(Declaration->getLocation());
>       if (FullLocation.isValid()){
>         llvm::outs() << "Found friend declaration at "
>                      << FullLocation.getSpellingLineNumber() << ":"
>                      << FullLocation.getSpellingColumnNumber() << "\n";
>       }
>       return true;
>     }
>
> Then I run a tool which contains my visitor on the following (incorrect)
> code
>
>   1 template<typename T>
>   2 class F{};
>   3 class F1{};
>   4 void f(){};
>   5
>   6 class classX
>   7 {
>   8   friend class classXfriend;
>   9   friend class F<int>;
>  10   friend class F1;
>  11   friend void f();
>  12 };
>
> Tool displayed the following:
>
> Found friend declaration at 8:3
> Found friend declaration at 9:3
> Found friend declaration at 10:3
> Found friend declaration at 11:15
>
> As you can see getLocation() refers to a friend keyword token in the case
> of a friend type declaration. Tool works with compilable code in the same
> way.
>

After a short conversation with Richard Smith, we think this is a bug.
Filed http://llvm.org/bugs/show_bug.cgi?id=19352. Patches welcome :o)

Cheers,
/Manuel


>
> --
> Kind regards, Dmitry
>
>
>
> On Fri, Apr 4, 2014 at 9:50 PM, Manuel Klimek <klimek at google.com> wrote:
>
>> On Thu, Apr 3, 2014 at 11:41 AM, Дмитрий Борисенков <
>> stackoverflow at xakep.ru> wrote:
>>
>>> Hello,
>>>
>>> I'm trying to get a source location for a type name identifier in
>>> FriendDecl, but getLocation() method returns source location of keyword
>>> 'friend'. Such behavior confused me a bit, because usually getLocation()
>>> returns an identifier location. I've released I can get location which I
>>> need through DeclSpec::getTypeSpecTypeNameLoc(). But could you explain me
>>> why getLocation() behavior differs from expected one (at least expected by
>>> me) in this case?
>>>
>>
>> From the code this shouldn't be the case. Unless you're calling
>> getFriendLoc() instead of getLocation().
>>
>> Cheers,
>> /Manuel
>>
>>
>>>
>>>
>>> --
>>> Kind regards, Dmitry Borisenkov
>>>
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>>
>>>
>>
>
>
> --
> С уважением, Борисенков Дмитрий
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140407/c0bc2498/attachment.html>


More information about the cfe-dev mailing list