Skip to content

Conversation

@a-tarasyuk
Copy link
Member

Fixes #144775


This patch addresses a false-positive -Wdocumentation warning on @tparam comments attached to variable template partial specializations

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 6, 2025

@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)

Changes

Fixes #144775


This patch addresses a false-positive -Wdocumentation warning on @<!-- -->tparam comments attached to variable template partial specializations


Full diff: https://github.com/llvm/llvm-project/pull/147219.diff

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+2)
  • (modified) clang/lib/AST/Comment.cpp (+7)
  • (modified) clang/test/Sema/warn-documentation.cpp (+12)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9a94c4bcd9980..d85c592b6d8bc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -671,6 +671,8 @@ Improvements to Clang's diagnostics
   false positives in exception-heavy code, though only simple patterns
   are currently recognized.
 
+- Clang now accepts ``@tparam`` comments on variable template partial
+  specializations. (#GH144775)
 
 Improvements to Clang's time-trace
 ----------------------------------
diff --git a/clang/lib/AST/Comment.cpp b/clang/lib/AST/Comment.cpp
index d022c5c845ae6..9fd4cc942e7b7 100644
--- a/clang/lib/AST/Comment.cpp
+++ b/clang/lib/AST/Comment.cpp
@@ -291,6 +291,13 @@ void DeclInfo::fill() {
     TemplateParameters = CTPSD->getTemplateParameters();
     break;
   }
+  case Decl::VarTemplatePartialSpecialization: {
+    const VarTemplatePartialSpecializationDecl *VTPSD = cast<VarTemplatePartialSpecializationDecl>(CommentDecl);
+    Kind = VariableKind;
+    TemplateKind = TemplatePartialSpecialization;
+    TemplateParameters = VTPSD->getTemplateParameters();
+    break;
+  }
   case Decl::ClassTemplateSpecialization:
     Kind = ClassKind;
     TemplateKind = TemplateSpecialization;
diff --git a/clang/test/Sema/warn-documentation.cpp b/clang/test/Sema/warn-documentation.cpp
index 4839bdff61795..0d1faa1b562fe 100644
--- a/clang/test/Sema/warn-documentation.cpp
+++ b/clang/test/Sema/warn-documentation.cpp
@@ -1524,3 +1524,15 @@ F &f = FF; ///< \return none
 // expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}}
 
 } // namespace PR42844
+
+#if __cplusplus >= 201402L
+namespace GH144775 {
+/// @brief primary template
+/// @tparam T type
+template <class T, class = void> constexpr auto var = T{};
+
+/// @brief variable template partial specialization
+/// @tparam T type
+template <typename T> constexpr auto var<T> = T{};
+} // namespace GH144775
+#endif

@github-actions
Copy link

github-actions bot commented Jul 6, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@a-tarasyuk a-tarasyuk requested a review from AaronBallman July 7, 2025 09:23
Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with a small nit. (Feel free to land once addressed, additional review not required.)

@a-tarasyuk a-tarasyuk merged commit 28649f2 into llvm:main Jul 7, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-Wdocumentation misleading diagnostic with template specialzation

4 participants