[clang] [Clang] support friend declarations with a dependent nested-name-specifier (PR #191268)
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 30 02:56:02 PDT 2026
================
@@ -191,9 +129,10 @@ class FriendDecl final
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
- static bool classofKind(Kind K) { return K == Decl::Friend; }
+ static bool classofKind(Kind K) {
+ return K == Decl::Friend || K == Decl::FriendTemplate;
+ }
----------------
cor3ntin wrote:
Hum, I think we are both wrong.
Having FriendDecl and FriendTemplateDecl form a hierarchy makes sense. Im just commenting on your implementation of `classofKind`.
But my feedback was wrong.
So, take 2.
You forgot to modify `DeclNodes.td`
```cpp
def Friend : DeclNode<Decl>;
def FriendTemplate : DeclNode<Decl>;
```
should be
```
def Friend : DeclNode<Decl>;
def FriendTemplate : DeclNode<Friend>;
```
I'm not sure what the implication of not doing that are but it can't be anything good!
Once you do that, and after rebuilding, you should have `Decl::firstFriend` and `Decl::lastFriend` enumerators. The implementation can then be
```cpp
static bool classofKind(Kind K) { return K >= firstFriend && K <= lastFriend; }
```
Which is a bit more robust.
see `firstNamed` or `firstFunction` for examples
https://github.com/llvm/llvm-project/pull/191268
More information about the cfe-commits
mailing list