llvm-project/clang/test/AST/constraints-explicit-instantiation.cpp
Matheus Izvekov 1a2f330976
[clang] Improve ast-dumper text printing of TemplateArgument (#93431)
This improves and unifies our approach to printing all template
arguments.

The same approach to printing types is extended to all
TemplateArguments: A sugared version is printed in quotes, followed by
printing the canonical form, unless they would print the same.

Special improvements are done to add more detail to template template
arguments.

It's planned in a future patch to use this improved TemplateName printer
for other places besides TemplateArguments.

Note: The sugared/desugared printing does not show up for TemplateNames
in tests yet, because we do a poor job of preserving their type sugar.
This will be improved in a future patch.
2024-05-29 15:23:44 -03:00

39 lines
906 B
C++

// RUN: %clang_cc1 -std=c++20 -ast-dump %s | FileCheck %s
namespace PR46029 {
template <int N>
void canary1();
template <int N>
void canary2();
template <int N>
struct A {
void f() requires(N == 1) {
static_assert(N == 1);
canary1<N>();
}
void f() requires(N == 2) {
static_assert(N == 2);
canary2<N>();
}
};
// This checks that `canary1<1>` and `canaray2<2>` are instantiated, thus
// indirectly validating that the correct candidates of `A::f` were really
// instantiated each time.
// The `static_assert`s validate we don't instantiate wrong candidates.
// CHECK:{{.*}}FunctionTemplateDecl {{.*}} canary1
// CHECK: {{.*}}TemplateArgument integral
// CHECK-SAME: {{'1'$}}
template struct A<1>;
// CHECK: {{.*}}FunctionTemplateDecl {{.*}} canary2
// CHECK: {{.*}}TemplateArgument integral
// CHECK-SAME: {{'2'$}}
template struct A<2>;
template struct A<3>;
}