[PATCH] D157684: [clang][ASTImporter] Repeated friend templates are partially imported

Ding Fei via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 22 08:04:33 PDT 2023


danix800 added inline comments.


================
Comment at: clang/lib/AST/ASTImporter.cpp:4114
   SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
-
-  while (ImportedFriend) {
-    bool Match = false;
-    if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) {
-      Match =
-          IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(),
-                            /*Complain=*/false);
-    } else if (D->getFriendType() && ImportedFriend->getFriendType()) {
-      Match = Importer.IsStructurallyEquivalent(
-          D->getFriendType()->getType(),
-          ImportedFriend->getFriendType()->getType(), /*Complain=*/false);
-    }
-    if (Match)
+  for (auto *ImportedFriend : RD->friends())
+    if (IsEquivalentFriend(Importer, D, ImportedFriend))
----------------
balazske wrote:
> `auto` should not be used here, this loop could be replaced by some generic "algorithm" function call (`llvm::copy_if`).
There's no trivial predicate so the result code might be:
```
  llvm::copy_if(RD->friends(), std::back_inserter(ImportedEquivalentFriends),
                [&](FriendDecl *ImportedFriend) {
                  return IsEquivalentFriend(Importer, D, ImportedFriend);
                });
```
which is not that 'intuitive' as the for-range version.

I'll pertain to the original one with `auto` replaced with explicit type. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157684/new/

https://reviews.llvm.org/D157684



More information about the cfe-commits mailing list