Author: Qizhi Hu Date: 2024-04-30T16:09:09+08:00 New Revision: eaee8aa0afe111f9291d54ecef97a3640a0f6ce0
URL: https://github.com/llvm/llvm-project/commit/eaee8aa0afe111f9291d54ecef97a3640a0f6ce0 DIFF: https://github.com/llvm/llvm-project/commit/eaee8aa0afe111f9291d54ecef97a3640a0f6ce0.diff LOG: [Clang][Sema] fix a bug on template partial specialization (#89862) attempt to fix https://github.com/llvm/llvm-project/issues/68885#issuecomment-1764201896 Deduction of NTTP whose type is `decltype(auto)` would create an implicit cast expression to dependent type and makes the type of primary template definition (`InjectedClassNameSpecialization`) and its partial specialization different. Prevent emitting cast expression to make clang knows their types are identical by removing `CTAK == CTAK_Deduced` when the type is `decltype(auto)`. Co-authored-by: huqizhi <836744...@qq.com> Added: clang/test/SemaCXX/identical-type-primary-partial-specialization.cpp Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaTemplate.cpp Removed: ################################################################################ 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