[PATCH] D155705: [clang] Fix specialization of non-templated member classes of class templates

Mariya Podchishchaeva via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 24 09:37:21 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGdcb8911316be: [clang] Fix specialization of non-templated member classes of class templates (authored by Fznamznon).

Changed prior to commit:
  https://reviews.llvm.org/D155705?vs=543478&id=543598#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155705/new/

https://reviews.llvm.org/D155705

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaTemplate/gh61159.cpp


Index: clang/test/SemaTemplate/gh61159.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaTemplate/gh61159.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+namespace GH61159 {
+template <typename T> struct X {
+  struct I;
+};
+
+template <> struct X<int>::I {
+  template <int ct> constexpr int f() { return ct; };
+
+  int data = 3;
+};
+
+template <typename T> struct X<T>::I {
+  template <T ct> constexpr T f() { return ct + 1; };
+  T data = 7;
+};
+
+static_assert(X<int>::I{}.f<17>() == 17);
+static_assert(X<int>::I{}.data == 3);
+static_assert(X<short>::I{}.data == 7);
+static_assert(X<short>::I{}.f<18>() == 19);
+
+template <typename T> struct Y {
+  struct I;
+};
+
+template <> struct Y<int> {
+  struct I {
+    template <int ct> constexpr int f() { return ct; };
+    int data = 3;
+  };
+};
+
+static_assert(Y<int>::I{}.f<17>() == 17);
+static_assert(Y<int>::I{}.data == 3);
+
+} // namespace GH61159
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -258,6 +258,11 @@
                                        /*Final=*/false);
   }
 
+  if (const MemberSpecializationInfo *MSInfo =
+          Rec->getMemberSpecializationInfo())
+    if (MSInfo->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+      return Response::Done();
+
   bool IsFriend = Rec->getFriendObjectKind() ||
                   (Rec->getDescribedClassTemplate() &&
                    Rec->getDescribedClassTemplate()->getFriendObjectKind());
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -677,6 +677,8 @@
 - Invalidate BlockDecl with invalid ParmVarDecl. Remove redundant dump of
   BlockDecl's ParmVarDecl
   (`#64005 <https://github.com/llvm/llvm-project/issues/64005>_`)
+- Fix crash on nested templated class with template function call.
+  (`#61159 <https://github.com/llvm/llvm-project/issues/61159>_`)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155705.543598.patch
Type: text/x-patch
Size: 2279 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230724/f813f092/attachment.bin>


More information about the cfe-commits mailing list