[clang] 6b50bfc - [clang] Store the template param list of an explicit variable template specialization
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 14 00:03:53 PDT 2023
Author: Nathan Ridge
Date: 2023-03-14T03:03:30-04:00
New Revision: 6b50bfc8f25a4d78a17a9134c3e2e26c19bb7dff
URL: https://github.com/llvm/llvm-project/commit/6b50bfc8f25a4d78a17a9134c3e2e26c19bb7dff
DIFF: https://github.com/llvm/llvm-project/commit/6b50bfc8f25a4d78a17a9134c3e2e26c19bb7dff.diff
LOG: [clang] Store the template param list of an explicit variable template specialization
VarTemplateSpecializationDecl does not store a template param list,
so the "template<>" needs to be stored in the ExtInfo.
Differential Revision: https://reviews.llvm.org/D142692
Added:
Modified:
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
clang/lib/Sema/SemaDecl.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index f5174979a8d6e..cba318df3d2fe 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -892,7 +892,7 @@ sizeof...($TemplateParameter[[Elements]]);
template $Bracket[[<]]typename $TemplateParameter_def[[T]]$Bracket[[>]]
$TemplateParameter[[T]] $Variable_def[[x]] = {};
- template <>
+ template $Bracket[[<]]$Bracket[[>]]
int $Variable_def[[x]]$Bracket[[<]]int$Bracket[[>]] = (int)sizeof($Class[[Base]]);
)cpp",
// operator calls in template
@@ -977,7 +977,7 @@ sizeof...($TemplateParameter[[Elements]]);
}
template $Bracket[[<]]typename $TemplateParameter_def[[T]]$Bracket[[>]] constexpr int $Variable_def_readonly[[V]] = 42;
constexpr int $Variable_def_readonly[[Y]] = $Variable_readonly[[V]]$Bracket[[<]]char$Bracket[[>]];
- template <>
+ template $Bracket[[<]]$Bracket[[>]]
constexpr int $Variable_def_readonly[[V]]$Bracket[[<]]int$Bracket[[>]] = 5;
template $Bracket[[<]]typename $TemplateParameter_def[[T]]$Bracket[[>]]
constexpr int $Variable_def_readonly[[V]]$Bracket[[<]]$TemplateParameter[[T]]*$Bracket[[>]] = 6;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b9cea8bbf42cf..0abf67f0d62d2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7674,7 +7674,12 @@ NamedDecl *Sema::ActOnVariableDeclarator(
// If we have any template parameter lists that don't directly belong to
// the variable (matching the scope specifier), store them.
- unsigned VDTemplateParamLists = TemplateParams ? 1 : 0;
+ // An explicit variable template specialization does not own any template
+ // parameter lists.
+ bool IsExplicitSpecialization =
+ IsVariableTemplateSpecialization && !IsPartialSpecialization;
+ unsigned VDTemplateParamLists =
+ (TemplateParams && !IsExplicitSpecialization) ? 1 : 0;
if (TemplateParamLists.size() > VDTemplateParamLists)
NewVD->setTemplateParameterListsInfo(
Context, TemplateParamLists.drop_back(VDTemplateParamLists));
More information about the cfe-commits
mailing list