[PATCH] D149009: [Sema]Select correct lexical context during template instantiate

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 24 07:33:37 PDT 2023


erichkeane added a comment.





================
Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:3597
+  if (FD->getFriendObjectKind() == Decl::FriendObjectKind::FOK_None &&
+      FD->isDefined(FDFriend, true) &&
+      FDFriend->getFriendObjectKind() != Decl::FriendObjectKind::FOK_None) {
----------------
I was originally REALLY suspicious about this function call here (and the setup with the out parameter/2nd variable here).  but it seems that the 'true' argument (which, needs a `/*ParamName */` comment) is specifically designed for this situation.


================
Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:3598
+      FD->isDefined(FDFriend, true) &&
+      FDFriend->getFriendObjectKind() != Decl::FriendObjectKind::FOK_None) {
+    // if Function defined by inline friend, use inline fried as DeclContext
----------------
So in what case would the currently-instantiated definition NOT also be a friend?  I would think this last condition should be able to be an assert instead.


================
Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:3601
+    FD = const_cast<FunctionDecl *>(FDFriend);
+    Owner = FD->getDescribedFunctionTemplate()->getLexicalDeclContext();
+  }
----------------
I THINK this should just be:
`Owner = FD->getLexicalDeclContext()` here.  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149009



More information about the cfe-commits mailing list