[clang] [Clang][Sema] Fix mismatch of out-of-line definition of template class (PR #102554)

via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 8 17:26:58 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Qizhi Hu (jcsxky)

<details>
<summary>Changes</summary>

Skip adding template instantiation arguments when the declaration is a nested class template when instantiating constraint expression.
attempt to fix https://github.com/llvm/llvm-project/issues/102320

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Sema/SemaConcept.cpp (+2-1) 
- (added) clang/test/SemaCXX/PR102320.cpp (+18) 


``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cb0a1b25e51c2a..ffc7e34f1166fd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -212,6 +212,7 @@ Bug Fixes to C++ Support
 - Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667),
   (#GH99877).
 - Fixed a bug when diagnosing ambiguous explicit specializations of constrained member functions.
+- Fix a bug in out-of-line definition of constrained class template nested in a class template. (GH102320).
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index d4c9d044985e34..016dd90b9e95e2 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -951,7 +951,8 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction(
       DeclInfo.getDecl(), DeclInfo.getLexicalDeclContext(), /*Final=*/false,
       /*Innermost=*/std::nullopt,
       /*RelativeToPrimary=*/true,
-      /*Pattern=*/nullptr, /*ForConstraintInstantiation=*/true,
+      /*Pattern=*/nullptr,
+      !isa_and_present<ClassTemplateDecl>(DeclInfo.getDecl()),
       /*SkipForSpecialization*/ false);
 
   if (MLTAL.getNumSubstitutedLevels() == 0)
diff --git a/clang/test/SemaCXX/PR102320.cpp b/clang/test/SemaCXX/PR102320.cpp
new file mode 100644
index 00000000000000..56973875c7b953
--- /dev/null
+++ b/clang/test/SemaCXX/PR102320.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+template<typename>
+concept Constrained = true;
+
+template <typename T>
+class C
+{
+    template<Constrained>
+    class D;
+};
+
+template <typename T>
+template <Constrained>
+class C<T>::D
+{
+};

``````````

</details>


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


More information about the cfe-commits mailing list