llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)

<details>
<summary>Changes</summary>

We were using the lexical DC as the starting point of template argument 
collection when comparing declarations. This caused an issue that template 
arguments from out-of-line declarations are ignored when substituting into the 
constraints, which in turn led to expression mismatching.

Fixes https://github.com/llvm/llvm-project/issues/145521


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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Sema/SemaConcept.cpp (+1-1) 
- (modified) clang/test/SemaTemplate/concepts-out-of-line-def.cpp (+25) 


``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 96477ef6ddc9a..ef1f2a7f42355 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -857,6 +857,7 @@ Bug Fixes to C++ Support
 - Clang now correctly parses arbitrary order of ``[[]]``, ``__attribute__`` 
and ``alignas`` attributes for declarations (#GH133107)
 - Fixed a crash when forming an invalid function type in a dependent context. 
(#GH138657) (#GH115725) (#GH68852)
 - Fixed a function declaration mismatch that caused inconsistencies between 
concepts and variable template declarations. (#GH139476)
+- Fixed an out-of-line declaration mismatch involving nested template 
parameters. (#GH145521)
 - Clang no longer segfaults when there is a configuration mismatch between 
modules and their users (http://crbug.com/400353616).
 - Fix an incorrect deduction when calling an explicit object member function 
template through an overload set address.
 - Fixed bug in constant evaluation that would allow using the value of a
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 1594b4423e4d2..19d6eb1513095 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -898,7 +898,7 @@ static const Expr 
*SubstituteConstraintExpressionWithoutSatisfaction(
     Sema &S, const Sema::TemplateCompareNewDeclInfo &DeclInfo,
     const Expr *ConstrExpr) {
   MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
-      DeclInfo.getDecl(), DeclInfo.getLexicalDeclContext(), /*Final=*/false,
+      DeclInfo.getDecl(), DeclInfo.getDeclContext(), /*Final=*/false,
       /*Innermost=*/std::nullopt,
       /*RelativeToPrimary=*/true,
       /*Pattern=*/nullptr, /*ForConstraintInstantiation=*/true,
diff --git a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp 
b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
index bf505dec0ca14..9811b18f4301b 100644
--- a/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ b/clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -868,3 +868,28 @@ template <typename T> requires moo::baa<T>
 void moo::caw() {}
 
 }
+
+namespace GH145521 {
+
+template <typename X>
+concept is_valid = true;
+
+template<typename T>
+class Nesting
+{
+public:
+    template<typename Q> requires is_valid<Q>
+    class Inner;
+
+    template<typename Q> requires is_valid<Q>
+    friend class Inner2;
+};
+
+template<typename T>
+template<typename Q> requires is_valid<Q>
+class Nesting<T>::Inner {};
+
+template<typename Q> requires is_valid<Q>
+class Inner2 {};
+
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/147463
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to