Skip to content

[clang] Fix @tparam warnings for concept template parameters#199800

Open
evelez7 wants to merge 1 commit into
llvm:mainfrom
evelez7:clang-documentation-concept-tparams
Open

[clang] Fix @tparam warnings for concept template parameters#199800
evelez7 wants to merge 1 commit into
llvm:mainfrom
evelez7:clang-documentation-concept-tparams

Conversation

@evelez7
Copy link
Copy Markdown
Member

@evelez7 evelez7 commented May 27, 2026

-Wdocumentation would warn on @tparam commands for concepts even if the named
parameter existed. This patch fixes that by explicitly checking the
concept decl for template declarations.

Fixes #64087

`-Wdocumentation` would warn on `@tparam` commands for concepts even if the named
parameter existed. This patch fixes that by explicitly checking the
concept decl for template declarations.
@llvmorg-github-actions llvmorg-github-actions Bot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 27, 2026
@llvmorg-github-actions
Copy link
Copy Markdown

@llvm/pr-subscribers-clang

Author: Erick Velez (evelez7)

Changes

-Wdocumentation would warn on @<!-- -->tparam commands for concepts even if the named
parameter existed. This patch fixes that by explicitly checking the
concept decl for template declarations.

Fixes #64087


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

2 Files Affected:

  • (modified) clang/lib/AST/CommentSema.cpp (+9-3)
  • (modified) clang/test/Sema/warn-documentation.cpp (+8)
diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp
index e74c7cb5ce605..156307e7abfd5 100644
--- a/clang/lib/AST/CommentSema.cpp
+++ b/clang/lib/AST/CommentSema.cpp
@@ -317,8 +317,13 @@ void Sema::actOnTParamCommandParamNameArg(TParamCommandComment *Command,
     return;
   }
 
-  const TemplateParameterList *TemplateParameters =
-      ThisDeclInfo->TemplateParameters;
+  const TemplateParameterList *TemplateParameters;
+  if (const auto *Concept =
+          dyn_cast_or_null<ConceptDecl>(ThisDeclInfo->CommentDecl))
+    TemplateParameters = Concept->getTemplateParameters();
+  else
+    TemplateParameters = ThisDeclInfo->TemplateParameters;
+
   SmallVector<unsigned, 2> Position;
   if (resolveTParamReference(Arg, TemplateParameters, &Position)) {
     Command->setPosition(copyArray(ArrayRef(Position)));
@@ -857,7 +862,8 @@ bool Sema::isTemplateOrSpecialization() {
     return false;
   if (!ThisDeclInfo->IsFilled)
     inspectThisDecl();
-  return ThisDeclInfo->getTemplateKind() != DeclInfo::NotTemplate;
+  return ThisDeclInfo->getTemplateKind() != DeclInfo::NotTemplate ||
+         isa<ConceptDecl>(ThisDeclInfo->CommentDecl);
 }
 
 bool Sema::isExplicitFunctionTemplateInstantiation() {
diff --git a/clang/test/Sema/warn-documentation.cpp b/clang/test/Sema/warn-documentation.cpp
index 24a4a22755a36..1076aa61266dc 100644
--- a/clang/test/Sema/warn-documentation.cpp
+++ b/clang/test/Sema/warn-documentation.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wdocumentation -Wdocumentation-pedantic -verify %s
 // RUN: %clang_cc1 -std=c++14 -fsyntax-only -Wdocumentation -Wdocumentation-pedantic -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -Wdocumentation -Wdocumentation-pedantic -verify %s
 
 // This file contains lots of corner cases, so ensure that XML we generate is not invalid.
 // RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng %s | FileCheck %s -check-prefix=WRONG
@@ -1544,5 +1545,12 @@ namespace GH64087
 template <typename T>
 void foo(){}
 
+#if __cplusplus >= 202002L
+/// @tparam T Derived class.
+/// @tparam TBase Base CRTP class.
+template <typename T, typename TBase>
+concept bar = true;
+#endif
+
 template void foo<bool>();
 } // namespace GH64087

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 doesn't work correctly with template parameters

1 participant