[cfe-dev] Type in friend declaration does not refer to the right RecordDecl?

Eric Liu via cfe-dev cfe-dev at lists.llvm.org
Fri Feb 10 05:34:58 PST 2017


Hi all,

I have the following code:
```
namespace a {
class A {};
namespace b { class B { friend class A; };  }  // b

} // a
```
I expect that the friend "class A" refers to CXXRecordDecl "class *a::A*".
However, it refers to an implicit CXXRecordDecl "class *a::b::A*" instead.
Is this expected?

* Node dump of the ElaboratedType "class A" in the friend declaration:
```
ElaboratedType 0x7fbf27d39570 'class A' sugar
`-RecordType 0x7fbf27d39540 'class a::b::A'
  `-CXXRecord 0x7fbf27d394a8 'A'
```

* AST dump:
```
....
`-NamespaceDecl 0x7f1f79f4f050 </home/ioeric/llvm-build/test.cc:1:1,
line:6:1> line:1:11 a
  |-CXXRecordDecl 0x7f1f79f4f0b8 <line:2:1, col:10> col:7 *class A*
definition
  | `-CXXRecordDecl 0x7f1f79f4f1d0 <col:1, col:7> col:7 implicit class A
  `-NamespaceDecl 0x7f1f79f4f288 <line:3:1, line:5:1> line:3:11 b
    `-CXXRecordDecl 0x7f1f79f4f2f0 <line:4:1, col:27> col:7 class B
definition
      |-CXXRecordDecl 0x7f1f79f4f410 <col:1, col:7> col:7 implicit class B
      `-FriendDecl 0x7f1f79f4f5c0 <col:11, col:24> col:18* 'class A':'class
a::b::A'*
```

Thanks,
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170210/0ae3579b/attachment.html>


More information about the cfe-dev mailing list