This patch handles default integral non-type template parameters.
After this patch the clang TypePrinter will omit default integral
template arguments when the `PrintingPolicy::SuppressDefaultTemplateArgs`
option is specified and sets us up to be able to re-use
`clang::isSubstitutedDefaultArgument` from the DWARF CodeGen
component.
Differential Revision: https://reviews.llvm.org/D139986
}
}
+ if (Arg.getKind() == TemplateArgument::Integral &&
+ Pattern.getKind() == TemplateArgument::Expression) {
+ Expr const *expr = Pattern.getAsExpr();
+
+ if (!expr->isValueDependent() && expr->isIntegerConstantExpr(Ctx)) {
+ return llvm::APSInt::isSameValue(expr->EvaluateKnownConstInt(Ctx),
+ Arg.getAsIntegral());
+ }
+ }
+
if (Arg.getKind() != Pattern.getKind())
return false;
eval<B<int, float>> eB;
eval<C<17>> eC; // expected-error{{implicit instantiation of undefined template 'eval<C<17>>'}}
eval<D<int, 17>> eD; // expected-error{{implicit instantiation of undefined template 'eval<D<int, 17>>'}}
-eval<E<int, float>> eE; // expected-error{{implicit instantiation of undefined template 'eval<E<int, float, 17>>}}
+eval<E<int, float>> eE; // expected-error{{implicit instantiation of undefined template 'eval<E<int, float>>}}
template<template <int ...N> class TT> struct X0 { }; // expected-note{{previous non-type template parameter with type 'int' is here}}
template<int I, int J, int ...Rest> struct X0a;
typedef vector< float, fixed<4> > vector4f;
// FIXME: This difference is due to D76801. It was probably an unintentional change. Maybe we want to undo it?
- // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] c"{vector<float, rdar9357400::fixed<4, -1> >=[4f]}\00"
- // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] c"{vector<float, rdar9357400::fixed<4, -1>>=[4f]}\00"
+ // @encoding for C++ is dependent on the TypePrinter implementation, which is a known issue. But since there
+ // are currently no system frameworks that vend Objective-C++ types, a potential ABI break caused by changes
+ // to the TypePrinter should not be a concern.
+ // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] c"{vector<float, rdar9357400::fixed<4> >=[4f]}\00"
+ // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] c"{vector<float, rdar9357400::fixed<4>>=[4f]}\00"
extern const char gg[] = @encode(vector4f);
}
B<const A<>> b4 = B<>();
// CHECK-ELIDE-NOTREE: error: no viable conversion from 'A<(default) 0>' to 'A<1>'
// CHECK-ELIDE-NOTREE: error: no viable conversion from 'A<1>' to 'A<(default) 0>'
-// CHECK-ELIDE-NOTREE: error: no viable conversion from 'B<int>' to 'B<(default) ZeroArgs::A<0>>'
-// CHECK-ELIDE-NOTREE: error: no viable conversion from 'B<(default) ZeroArgs::A<0>>' to 'B<int>'
+// CHECK-ELIDE-NOTREE: error: no viable conversion from 'B<int>' to 'B<(default) ZeroArgs::A<>>'
+// CHECK-ELIDE-NOTREE: error: no viable conversion from 'B<(default) ZeroArgs::A<>>' to 'B<int>'
// CHECK-ELIDE-NOTREE: error: no viable conversion from 'B<const A<...>>' to 'B<A<...>>'
// CHECK-ELIDE-NOTREE: error: no viable conversion from 'B<A<...>>' to 'B<const A<...>>'
}
f(ups).f(); // expected-note {{in instantiation of member function 'default_args::unique_ptr<default_args::basic_string<char>>::f' requested here}}
}
- template<int A, int B = A> struct Z { int error[B]; }; // expected-error {{negative size}}
+ template<int A, int B = A, int C = 42> struct Z { int error[B]; }; // expected-error {{negative size}}
Z<-1> z; // expected-note {{in instantiation of template class 'default_args::Z<-1>' requested here}}
template<template<typename> class A = allocator, template<typename> class B = A> struct Q {};
__device__ void test_not_a_texture() {
not_a_texture<int> inst;
- inst.c(); // dev-note {{in instantiation of member function 'not_a_texture<int, 1, 1>::c' requested here}}
+ inst.c(); // dev-note {{in instantiation of member function 'not_a_texture<int>::c' requested here}}
}
// Test static variable in host function used by device function.
ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
Range<T> R;
for co_await (auto i : R) {}
- // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag<Iter<int>, false>'}}
+ // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag<Iter<int>>'}}
}
template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note {{requested here}}
ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
Range<T> R;
for co_await(auto i : R) {} // expected-warning {{'for co_await' belongs to CoroutineTS instead of C++20, which is deprecated}}
- // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag<Iter<int>, false>'}}
+ // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag<Iter<int>>'}}
}
template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note {{requested here}}
};
template <class T, class U>
void test_dependent_param(T t, U) {
- // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+ // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
// expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
((void)t);
co_return 42;
};
template <class T, class U>
void test_dependent_param(T t, U) {
- // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+ // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
// expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
((void)t);
co_return 42;
{
Matrix<double> winI(0, 3);
RGBFValue* inputPreL;
- winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix<double, 0, 0> &&'}}
+ winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix<double> &&'}}
}
}
// CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
// CHECK: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for F> 'auto (type-parameter-0-1) -> F<>'
// CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1'
-// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for F> 'auto (int) -> F<'x'>'
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for F> 'auto (int) -> F<>'
// CHECK: |-TemplateArgument integral 120
// CHECK: |-TemplateArgument type 'int'
// CHECK: | `-BuiltinType {{.*}} 'int'
struct Y: Y<dim> { }; // expected-error{{circular inheritance between 'Y<dim>' and 'Y<dim>'}}
};
typedef X<3> X3;
-X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<3>'}}
+X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<>'}}
}
namespace rdar12629723 {