Skip to content

Commit

Permalink
[Concepts] Dump template arguments for immediately declared constraint.
Browse files Browse the repository at this point in the history
The template arguments were dumped as part of the TemplateTypeParmDecl, which
was incorrect.

Differential Revision: https://reviews.llvm.org/D85282
  • Loading branch information
hokein committed Aug 10, 2020
1 parent b1c7f84 commit 626d0f5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
10 changes: 7 additions & 3 deletions clang/include/clang/AST/ASTNodeTraverser.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,7 @@ class ASTNodeTraverser

void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
if (const auto *TC = D->getTypeConstraint())
if (TC->hasExplicitTemplateArgs())
for (const auto &ArgLoc : TC->getTemplateArgsAsWritten()->arguments())
dumpTemplateArgumentLoc(ArgLoc);
Visit(TC->getImmediatelyDeclaredConstraint());
if (D->hasDefaultArgument())
Visit(D->getDefaultArgument(), SourceRange(),
D->getDefaultArgStorage().getInheritedFrom(),
Expand Down Expand Up @@ -574,6 +572,12 @@ class ASTNodeTraverser
Visit(D->getConstraintExpr());
}

void VisitConceptSpecializationExpr(const ConceptSpecializationExpr *CSE) {
if (CSE->hasExplicitTemplateArgs())
for (const auto &ArgLoc : CSE->getTemplateArgsAsWritten()->arguments())
dumpTemplateArgumentLoc(ArgLoc);
}

void VisitUsingShadowDecl(const UsingShadowDecl *D) {
if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
Visit(TD->getTypeForDecl());
Expand Down
1 change: 0 additions & 1 deletion clang/lib/AST/TextNodeDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1999,7 +1999,6 @@ void TextNodeDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
dumpBareDeclRef(TC->getFoundDecl());
OS << ")";
}
AddChild([=] { Visit(TC->getImmediatelyDeclaredConstraint()); });
} else if (D->wasDeclaredWithTypename())
OS << " typename";
else
Expand Down
12 changes: 8 additions & 4 deletions clang/test/AST/ast-dump-concepts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ concept binary_concept = true;
template <typename T>
struct Foo {
// CHECK: TemplateTypeParmDecl {{.*}} referenced Concept {{.*}} 'binary_concept'
// CHECK-NEXT: |-ConceptSpecializationExpr {{.*}} <col:13, col:31> 'bool' Concept {{.*}} 'binary_concept'
// CHECK-NEXT: `-TemplateArgument {{.*}} type 'int'
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} <col:13, col:31> 'bool' Concept {{.*}} 'binary_concept'
// CHECK-NEXT: |-TemplateArgument {{.*}} type 'R'
// CHECK-NEXT: | `-TemplateTypeParmType {{.*}} 'R'
// CHECK-NEXT: | `-TemplateTypeParm {{.*}} 'R'
// CHECK-NEXT: `-TemplateArgument {{.*}} type 'int'
// CHECK-NEXT: `-BuiltinType {{.*}} 'int'
template <binary_concept<int> R>
Foo(R);

Expand All @@ -25,11 +29,11 @@ struct Foo {
template <unary_concept R>
Foo(R);

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

// CHECK: FunctionTemplateDecl {{.*}} <line:33:3, line:35:3> {{.*}} Foo<T>
// CHECK: FunctionTemplateDecl {{.*}} <line:[[@LINE+1]]:3, line:[[@LINE+3]]:3> {{.*}} Foo<T>
template <typename R>
Foo(R, char) requires unary_concept<R> {
}
Expand Down

0 comments on commit 626d0f5

Please sign in to comment.