-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang][Sema] Fix a bug on type constraint checking #84671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: Qizhi Hu (jcsxky) ChangesTry to fix #84368 Full diff: https://github.com/llvm/llvm-project/pull/84671.diff 3 Files Affected:
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;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit message and release note needs to be MUCH more detailed. Else I think this looks like an acceptable patch.
Thanks for you remind! I have updated commit message and release note to make it more clear. |
|
||
template<IsOk T> struct Thing; | ||
|
||
template<IsOk T> struct Foobar { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indenting here doesn't match our clang-format rules. Please fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
1b71ce0
to
fd1711b
Compare
Try to fix #84368
When visiting class members in
TemplateDeclInstantiator::VisitClassTemplateDecl
duringSema::InstantiateClass
, we miss to set attribute of friend declaration if it is(isFriend
is true). This will lead toSema::AreConstraintExpressionsEqual
return false when invoked inMatchTemplateParameterKind
. Because it makesSema::getTemplateInstantiationArgs
returns incorrect template argument(MultiLevelTemplateArgumentList
). When we handleCXXRecordDecl
InSema::getTemplateInstantiationArgs
, friend declaration(its parent context isFileContext
) makes us to chooseLexicalDeclContext
notDeclContext
and this is what we want.