[clang] [Clang][Sema] Fix a bug on type constraint checking (PR #84671)

via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 10 00:14:44 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Qizhi Hu (jcsxky)

<details>
<summary>Changes</summary>

Try to fix https://github.com/llvm/llvm-project/issues/84368
[temp.friend]p1:
Similarly, each specialization of the `task` class template has the class template
specialization `task<int>` as a friend, and has all specializations of the class template `frd` as friends.

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+1) 
- (added) clang/test/Sema/PR84368.cpp (+16) 


``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3b89d5a8720785..b32e739288dbc5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -259,6 +259,8 @@ Bug Fixes in This Version
   operator.
   Fixes (#GH83267).
 
+- Fix a bug on type constraint checking (#GH84368). 
+
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 20c2c93ac9c7b4..765c5bc689ae1e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1698,6 +1698,7 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
     assert(!Owner->isDependentContext());
     Inst->setLexicalDeclContext(Owner);
     RecordInst->setLexicalDeclContext(Owner);
+    Inst->setObjectOfFriendDecl();
 
     if (PrevClassTemplate) {
       Inst->setCommonPtr(PrevClassTemplate->getCommonPtr());
diff --git a/clang/test/Sema/PR84368.cpp b/clang/test/Sema/PR84368.cpp
new file mode 100644
index 00000000000000..073530ffd8abea
--- /dev/null
+++ b/clang/test/Sema/PR84368.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// RUN: %clang_cc1 -std=c++23 -verify %s
+// expected-no-diagnostics
+
+template<class T> concept IsOk = requires() { typename T::Float; };
+
+template<IsOk T> struct Thing;
+
+template<IsOk T> struct Foobar {
+	template<int> struct Inner {
+		template<IsOk T2> friend struct Thing;
+	};
+};
+
+struct MyType { using Float=float; };
+Foobar<MyType>::Inner<0> foobar;

``````````

</details>


https://github.com/llvm/llvm-project/pull/84671


More information about the cfe-commits mailing list