[clang] 9f57b65 - [clangd] Include "final" when printing class declaration
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 11 03:22:12 PDT 2022
Author: Tom Praschan
Date: 2022-07-11T12:20:23+02:00
New Revision: 9f57b65a272817752aa00e2fb94154e6eed1d0ec
URL: https://github.com/llvm/llvm-project/commit/9f57b65a272817752aa00e2fb94154e6eed1d0ec
DIFF: https://github.com/llvm/llvm-project/commit/9f57b65a272817752aa00e2fb94154e6eed1d0ec.diff
LOG: [clangd] Include "final" when printing class declaration
Fixes https://github.com/clangd/clangd/issues/1184
Reviewed By: sammccall
Differential Revision: https://reviews.llvm.org/D128202
Added:
Modified:
clang-tools-extra/clangd/unittests/HoverTests.cpp
clang/lib/AST/DeclPrinter.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 0f149b7242966..949ddbae58b3d 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -198,7 +198,7 @@ TEST(Hover, Structured) {
typename = char,
int = 0,
bool Q = false,
- class... Ts> class Foo {};
+ class... Ts> class Foo final {};
template <template<typename, bool...> class T>
[[F^oo]]<T> foo;
)cpp",
@@ -209,7 +209,7 @@ TEST(Hover, Structured) {
HI.Definition =
R"cpp(template <template <typename, bool...> class C, typename = char, int = 0,
bool Q = false, class... Ts>
-class Foo {})cpp";
+class Foo final {})cpp";
HI.TemplateParameters = {
{{"template <typename, bool...> class"},
std::string("C"),
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index c6a392c9c01b5..3f04d9b4073e9 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -1007,6 +1007,12 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
}
}
+ if (auto *Def = D->getDefinition()) {
+ if (D->hasAttr<FinalAttr>()) {
+ Out << " final";
+ }
+ }
+
if (D->isCompleteDefinition()) {
// Print the base classes
if (D->getNumBases()) {
More information about the cfe-commits
mailing list