[clang] Fix @tparam warnings for concept template parameters#199800
Open
evelez7 wants to merge 1 commit into
Open
[clang] Fix @tparam warnings for concept template parameters#199800evelez7 wants to merge 1 commit into
evelez7 wants to merge 1 commit into
Conversation
`-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.
|
@llvm/pr-subscribers-clang Author: Erick Velez (evelez7) Changes
Fixes #64087 Full diff: https://github.com/llvm/llvm-project/pull/199800.diff 2 Files Affected:
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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
-Wdocumentationwould warn on@tparamcommands for concepts even if the namedparameter existed. This patch fixes that by explicitly checking the
concept decl for template declarations.
Fixes #64087