llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Oleksandr Tarasiuk (a-tarasyuk)

<details>
<summary>Changes</summary>

Fixes #<!-- -->216694

---

This patch addresses an assertion failure that occurs when instantiating an 
invalid friend function template by marking its `FriendDecl` wrapper as invalid.

---
Full diff: https://github.com/llvm/llvm-project/pull/216727.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+1-2) 
- (modified) clang/test/CXX/temp/temp.decls/temp.friend/p6.cpp (+9) 


``````````diff
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 8d5ee07c5ad49..d0f63b5df9a01 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -18788,8 +18788,7 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, 
Declarator &D,
     FriendDecl *Friend = FriendDecl::Create(
         Context, CurContext, D.getIdentifierLoc(), ND, DS.getFriendSpecLoc());
     Friend->setAccess(AS_public);
-    if (!isa<FunctionTemplateDecl>(ND))
-      Friend->setInvalidDecl();
+    Friend->setInvalidDecl();
     CurContext->addDecl(Friend);
     return ND;
   }
diff --git a/clang/test/CXX/temp/temp.decls/temp.friend/p6.cpp 
b/clang/test/CXX/temp/temp.decls/temp.friend/p6.cpp
index f60f3dd42445c..673fce425572b 100644
--- a/clang/test/CXX/temp/temp.decls/temp.friend/p6.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.friend/p6.cpp
@@ -25,3 +25,12 @@ void t3() {
     // expected-error@-1 {{templates cannot be declared inside of a local 
class}}
   };
 }
+
+template <class T> void t4() {
+  struct S {
+    template <class U> friend void f(T);
+    // expected-error@-1 {{templates can only be declared in namespace or 
class scope}}
+  };
+}
+
+template void t4<int>();

``````````

</details>


https://github.com/llvm/llvm-project/pull/216727
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to