[clang] [clang] Fix @tparam warnings for concept template parameters (PR #199800)
Erick Velez via cfe-commits
cfe-commits at lists.llvm.org
Wed May 27 08:20:24 PDT 2026
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/199800
>From 9268d433a28678edb08b4fe29a3e3d9fbd405f33 Mon Sep 17 00:00:00 2001
From: Erick Velez <erickvelez7 at gmail.com>
Date: Tue, 26 May 2026 17:32:39 -0700
Subject: [PATCH 1/2] [clang] Fix @tparam warnings for concept template
parameters
`-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.
---
clang/lib/AST/CommentSema.cpp | 12 +++++++++---
clang/test/Sema/warn-documentation.cpp | 8 ++++++++
2 files changed, 17 insertions(+), 3 deletions(-)
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
>From 9713ed53e7e92da9c2e9fed0ee260167527f59da Mon Sep 17 00:00:00 2001
From: Erick Velez <erickvelez7 at gmail.com>
Date: Wed, 27 May 2026 08:20:08 -0700
Subject: [PATCH 2/2] add concept support to DeclInfo instead
---
clang/include/clang/AST/Comment.h | 4 +++-
clang/lib/AST/Comment.cpp | 6 ++++++
clang/lib/AST/CommentSema.cpp | 10 ++--------
clang/lib/Index/CommentToXML.cpp | 4 ++++
4 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/clang/include/clang/AST/Comment.h b/clang/include/clang/AST/Comment.h
index 5ba95c8291d38..9ea86089373d5 100644
--- a/clang/include/clang/AST/Comment.h
+++ b/clang/include/clang/AST/Comment.h
@@ -1044,7 +1044,9 @@ struct DeclInfo {
TypedefKind,
/// An enumeration or scoped enumeration.
- EnumKind
+ EnumKind,
+
+ ConceptKind
};
/// What kind of template specialization \c CommentDecl is.
diff --git a/clang/lib/AST/Comment.cpp b/clang/lib/AST/Comment.cpp
index 3ea7288231c97..a1c73f9ec179b 100644
--- a/clang/lib/AST/Comment.cpp
+++ b/clang/lib/AST/Comment.cpp
@@ -350,6 +350,12 @@ void DeclInfo::fill() {
case Decl::Enum:
Kind = EnumKind;
break;
+ case Decl::Concept:
+ const ConceptDecl *Concept = cast<ConceptDecl>(CommentDecl);
+ Kind = ConceptKind;
+ TemplateKind = Template;
+ TemplateParameters = Concept->getTemplateParameters();
+ break;
}
// If the type is a typedef / using to something we consider a function,
diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp
index 156307e7abfd5..efe53d294f1f9 100644
--- a/clang/lib/AST/CommentSema.cpp
+++ b/clang/lib/AST/CommentSema.cpp
@@ -317,12 +317,7 @@ void Sema::actOnTParamCommandParamNameArg(TParamCommandComment *Command,
return;
}
- const TemplateParameterList *TemplateParameters;
- if (const auto *Concept =
- dyn_cast_or_null<ConceptDecl>(ThisDeclInfo->CommentDecl))
- TemplateParameters = Concept->getTemplateParameters();
- else
- TemplateParameters = ThisDeclInfo->TemplateParameters;
+ const TemplateParameterList *TemplateParameters = ThisDeclInfo->TemplateParameters;
SmallVector<unsigned, 2> Position;
if (resolveTParamReference(Arg, TemplateParameters, &Position)) {
@@ -862,8 +857,7 @@ bool Sema::isTemplateOrSpecialization() {
return false;
if (!ThisDeclInfo->IsFilled)
inspectThisDecl();
- return ThisDeclInfo->getTemplateKind() != DeclInfo::NotTemplate ||
- isa<ConceptDecl>(ThisDeclInfo->CommentDecl);
+ return ThisDeclInfo->getTemplateKind() != DeclInfo::NotTemplate;
}
bool Sema::isExplicitFunctionTemplateInstantiation() {
diff --git a/clang/lib/Index/CommentToXML.cpp b/clang/lib/Index/CommentToXML.cpp
index f17c0ff868314..2c5c13d67c3cf 100644
--- a/clang/lib/Index/CommentToXML.cpp
+++ b/clang/lib/Index/CommentToXML.cpp
@@ -893,6 +893,10 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) {
RootEndTag = "</Enum>";
Result << "<Enum";
break;
+ case DeclInfo::ConceptKind:
+ RootEndTag = "</Concept";
+ Result << "<Concept";
+ break;
}
{
More information about the cfe-commits
mailing list