Skip to content

Commit 626d0f5

Browse files
committed
[Concepts] Dump template arguments for immediately declared constraint.
The template arguments were dumped as part of the TemplateTypeParmDecl, which was incorrect. Differential Revision: https://reviews.llvm.org/D85282
1 parent b1c7f84 commit 626d0f5

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

clang/include/clang/AST/ASTNodeTraverser.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,7 @@ class ASTNodeTraverser
543543

544544
void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
545545
if (const auto *TC = D->getTypeConstraint())
546-
if (TC->hasExplicitTemplateArgs())
547-
for (const auto &ArgLoc : TC->getTemplateArgsAsWritten()->arguments())
548-
dumpTemplateArgumentLoc(ArgLoc);
546+
Visit(TC->getImmediatelyDeclaredConstraint());
549547
if (D->hasDefaultArgument())
550548
Visit(D->getDefaultArgument(), SourceRange(),
551549
D->getDefaultArgStorage().getInheritedFrom(),
@@ -574,6 +572,12 @@ class ASTNodeTraverser
574572
Visit(D->getConstraintExpr());
575573
}
576574

575+
void VisitConceptSpecializationExpr(const ConceptSpecializationExpr *CSE) {
576+
if (CSE->hasExplicitTemplateArgs())
577+
for (const auto &ArgLoc : CSE->getTemplateArgsAsWritten()->arguments())
578+
dumpTemplateArgumentLoc(ArgLoc);
579+
}
580+
577581
void VisitUsingShadowDecl(const UsingShadowDecl *D) {
578582
if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
579583
Visit(TD->getTypeForDecl());

clang/lib/AST/TextNodeDumper.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1999,7 +1999,6 @@ void TextNodeDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
19991999
dumpBareDeclRef(TC->getFoundDecl());
20002000
OS << ")";
20012001
}
2002-
AddChild([=] { Visit(TC->getImmediatelyDeclaredConstraint()); });
20032002
} else if (D->wasDeclaredWithTypename())
20042003
OS << " typename";
20052004
else

clang/test/AST/ast-dump-concepts.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ concept binary_concept = true;
1515
template <typename T>
1616
struct Foo {
1717
// CHECK: TemplateTypeParmDecl {{.*}} referenced Concept {{.*}} 'binary_concept'
18-
// CHECK-NEXT: |-ConceptSpecializationExpr {{.*}} <col:13, col:31> 'bool' Concept {{.*}} 'binary_concept'
19-
// CHECK-NEXT: `-TemplateArgument {{.*}} type 'int'
18+
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} <col:13, col:31> 'bool' Concept {{.*}} 'binary_concept'
19+
// CHECK-NEXT: |-TemplateArgument {{.*}} type 'R'
20+
// CHECK-NEXT: | `-TemplateTypeParmType {{.*}} 'R'
21+
// CHECK-NEXT: | `-TemplateTypeParm {{.*}} 'R'
22+
// CHECK-NEXT: `-TemplateArgument {{.*}} type 'int'
23+
// CHECK-NEXT: `-BuiltinType {{.*}} 'int'
2024
template <binary_concept<int> R>
2125
Foo(R);
2226

@@ -25,11 +29,11 @@ struct Foo {
2529
template <unary_concept R>
2630
Foo(R);
2731

28-
// CHECK: FunctionTemplateDecl {{.*}} <line:29:3, line:30:39> {{.*}} Foo<T>
32+
// CHECK: FunctionTemplateDecl {{.*}} <line:[[@LINE+1]]:3, line:[[@LINE+2]]:39> {{.*}} Foo<T>
2933
template <typename R>
3034
Foo(R, int) requires unary_concept<R>;
3135

32-
// CHECK: FunctionTemplateDecl {{.*}} <line:33:3, line:35:3> {{.*}} Foo<T>
36+
// CHECK: FunctionTemplateDecl {{.*}} <line:[[@LINE+1]]:3, line:[[@LINE+3]]:3> {{.*}} Foo<T>
3337
template <typename R>
3438
Foo(R, char) requires unary_concept<R> {
3539
}

0 commit comments

Comments
 (0)