https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/89862

>From 242b88a37f08bb66bcdde5e5b30c43553107d29c Mon Sep 17 00:00:00 2001
From: huqizhi <huqi...@feysh.com>
Date: Wed, 24 Apr 2024 09:37:53 +0800
Subject: [PATCH] [Clang][Sema] fix a bug on template partial specialization

---
 clang/docs/ReleaseNotes.rst                         |  1 +
 clang/lib/Sema/SemaTemplate.cpp                     |  2 +-
 ...dentical-type-primary-partial-specialization.cpp | 13 +++++++++++++
 3 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/SemaCXX/identical-type-primary-partial-specialization.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4c0fe5bcf6b122..98c80b6017f604 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -611,6 +611,7 @@ Bug Fixes to C++ Support
   immediate function context.
 - Fix CTAD for ``std::initializer_list``. This allows 
``std::initializer_list{1, 2, 3}`` to be deduced as
   ``std::initializer_list<int>`` as intended.
+- Fix a bug on template partial specialization whose template parameter is 
`decltype(auto)`.
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index bbcb7c33a98579..ed5507c0ec0100 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -7706,7 +7706,7 @@ ExprResult 
Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
     // FIXME: The language rules don't say what happens in this case.
     // FIXME: We get an opaque dependent type out of decltype(auto) if the
     // expression is merely instantiation-dependent; is this enough?
-    if (CTAK == CTAK_Deduced && Arg->isTypeDependent()) {
+    if (Arg->isTypeDependent()) {
       auto *AT = dyn_cast<AutoType>(DeducedT);
       if (AT && AT->isDecltypeAuto()) {
         SugaredConverted = TemplateArgument(Arg);
diff --git 
a/clang/test/SemaCXX/identical-type-primary-partial-specialization.cpp 
b/clang/test/SemaCXX/identical-type-primary-partial-specialization.cpp
new file mode 100644
index 00000000000000..ad51ca8252ef50
--- /dev/null
+++ b/clang/test/SemaCXX/identical-type-primary-partial-specialization.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+template <decltype(auto) a>
+struct S { // expected-note {{previous definition is here}}
+    static constexpr int i = 42;
+};
+
+template <decltype(auto) a>
+struct S<a> { // expected-error {{class template partial specialization does 
not specialize any template argument; to define the primary template, remove 
the template argument list}} \
+              // expected-error {{redefinition of 'S'}}
+    static constexpr int i = 0;
+};

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to