[clang] [Clang][Sema] Fix mismatch of out-of-line definition of template class (PR #102554)
Qizhi Hu via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 8 17:26:27 PDT 2024
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/102554
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
>From 0080b8743a1186d0463e1ff7af73a2a8776b66f1 Mon Sep 17 00:00:00 2001
From: Qizhi Hu <836744285 at qq.com>
Date: Fri, 9 Aug 2024 08:19:09 +0800
Subject: [PATCH] [Clang][Sema] Fix mismatch of out-of-line definition of
template class
---
clang/docs/ReleaseNotes.rst | 1 +
clang/lib/Sema/SemaConcept.cpp | 3 ++-
clang/test/SemaCXX/PR102320.cpp | 18 ++++++++++++++++++
3 files changed, 21 insertions(+), 1 deletion(-)
create mode 100644 clang/test/SemaCXX/PR102320.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cb0a1b25e51c2..ffc7e34f1166f 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 d4c9d044985e3..016dd90b9e95e 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 0000000000000..56973875c7b95
--- /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
+{
+};
More information about the cfe-commits
mailing list