[PATCH] D65926: [clangd] Fixed printTemplateSpecializationArgs not printing partial variable specialization arguments.
Johan Vikström via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 8 00:35:31 PDT 2019
jvikstrom created this revision.
jvikstrom added reviewers: hokein, ilya-biryukov.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.
printTemplateSpecializationArgs was not printing partial variable specialization args. This adds an additional If clause where we check if it's a VariableTemplatePartialSpecializationDecl and returns the ArgumentLocs if that's the case.
Also adds tests for printTemplateSpecializationArgs in ASTTests.cpp.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D65926
Files:
clang-tools-extra/clangd/AST.cpp
clang-tools-extra/clangd/unittests/ASTTests.cpp
clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
Index: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
@@ -188,7 +188,7 @@
AllOf(DeclNamed("foo"), WithTemplateArgs("")),
AllOf(DeclNamed("i"), WithTemplateArgs("")),
AllOf(DeclNamed("d"), WithTemplateArgs("")),
- AllOf(DeclNamed("foo"), WithTemplateArgs("<>")),
+ AllOf(DeclNamed("foo"), WithTemplateArgs("<T *>")),
AllOf(DeclNamed("foo"), WithTemplateArgs("<bool>"))}));
}
Index: clang-tools-extra/clangd/unittests/ASTTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/ASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ASTTests.cpp
@@ -8,6 +8,7 @@
#include "AST.h"
#include "gtest/gtest.h"
+#include "TestTU.h"
namespace clang {
namespace clangd {
@@ -36,6 +37,44 @@
"testns1::TestClass<testns1::OtherClass>", "testns1"));
}
+TEST(PrintTemplateSpecializationArgs, PrintsTemplateArgs) {
+ TestTU TU;
+ TU.Code = R"cpp(
+ template<class T>
+ void foo(T) {}
+ template<>
+ void foo<int>(int) {}
+
+ template<class T, class U>
+ struct K {};
+ template<class J>
+ struct K<int, J> {};
+ template<>
+ struct K<int, double> {};
+
+ template<class T>
+ T S = T(10);
+
+ template <class T>
+ int S<T*> = 0;
+ template <>
+ int S<double> = 0;
+ )cpp";
+
+ // The expected template args string representation for every top level decl
+ // in the TU.
+ std::vector<std::string> ExpectedTemplateDeclArgs{
+ "", "<int>", "", "<int, J>", "<int, double>", "", "<T *>", "<double>"};
+
+ std::vector<Decl *> TopLevel = TU.build().getLocalTopLevelDecls();
+ std::vector<std::string> ActualTemplateArgs;
+ for (const Decl *D : TopLevel) {
+ if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
+ ActualTemplateArgs.push_back(printTemplateSpecializationArgs(*ND));
+ }
+
+ EXPECT_EQ(ExpectedTemplateDeclArgs, ActualTemplateArgs);
+}
} // namespace
} // namespace clangd
Index: clang-tools-extra/clangd/AST.cpp
===================================================================
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -36,6 +36,10 @@
llvm::dyn_cast<ClassTemplatePartialSpecializationDecl>(&ND)) {
if (auto *Args = Cls->getTemplateArgsAsWritten())
return Args->arguments();
+ } else if (auto *Var =
+ llvm::dyn_cast<VarTemplatePartialSpecializationDecl>(&ND)) {
+ if (auto *Args = Var->getTemplateArgsAsWritten())
+ return Args->arguments();
} else if (auto *Var = llvm::dyn_cast<VarTemplateSpecializationDecl>(&ND))
return Var->getTemplateArgsInfo().arguments();
// We return None for ClassTemplateSpecializationDecls because it does not
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65926.214077.patch
Type: text/x-patch
Size: 3034 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190808/9dc2504e/attachment.bin>
More information about the cfe-commits
mailing list