| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s |
| 2 |
|
| 3 |
// expected-note@temp_arg_template_p0522.cpp:* 1+{{template is declared here}} |
| 4 |
// expected-note@temp_arg_template_p0522.cpp:* 1+{{template parameter is declared here}} |
| 5 |
// expected-note@temp_arg_template_p0522.cpp:* 1+{{previous template template parameter is here}} |
| 6 |
|
| 7 |
template<template<int> typename> struct Ti; // #Ti |
| 8 |
template<template<int...> typename> struct TPi; // #TPi |
| 9 |
template<template<int, int...> typename> struct TiPi; |
| 10 |
template<template<int..., int...> typename> struct TPiPi; |
| 11 |
// expected-error@-1 {{template parameter pack must be the last template parameter}} |
| 12 |
|
| 13 |
template<typename T, template<T> typename> struct tT0; // #tT0 |
| 14 |
template<template<typename T, T> typename> struct Tt0; // #Tt0 |
| 15 |
|
| 16 |
template<template<typename> typename> struct Tt; |
| 17 |
template<template<typename, typename...> typename> struct TtPt; |
| 18 |
|
| 19 |
template<int> struct i; |
| 20 |
template<int, int = 0> struct iDi; |
| 21 |
template<int, int> struct ii; |
| 22 |
template<int...> struct Pi; |
| 23 |
template<int, int, int...> struct iiPi; |
| 24 |
|
| 25 |
template<int, typename = int> struct iDt; // #iDt |
| 26 |
template<int, typename> struct it; // #it |
| 27 |
|
| 28 |
template<typename T, T v> struct t0; |
| 29 |
|
| 30 |
template<typename...> struct Pt; |
| 31 |
|
| 32 |
namespace IntParam { |
| 33 |
using ok = Pt<Ti<i>, |
| 34 |
Ti<iDi>, |
| 35 |
Ti<Pi>, |
| 36 |
Ti<iDt>>; |
| 37 |
using err1 = Ti<ii>; // expected-error {{too few template arguments for class template 'ii'}} |
| 38 |
// expected-note@-1 {{different template parameters}} |
| 39 |
using err2 = Ti<iiPi>; // expected-error {{too few template arguments for class template 'iiPi'}} |
| 40 |
// expected-note@-1 {{different template parameters}} |
| 41 |
using err3 = Ti<t0>; // expected-error@#Ti {{template argument for template type parameter must be a type}} |
| 42 |
// expected-note@-1 {{different template parameters}} |
| 43 |
using err4 = Ti<it>; // expected-error {{too few template arguments for class template 'it'}} |
| 44 |
// expected-note@-1 {{different template parameters}} |
| 45 |
} |
| 46 |
|
| 47 |
// These are accepted by the backwards-compatibility "parameter pack in |
| 48 |
// parameter matches any number of parameters in arguments" rule. |
| 49 |
namespace IntPackParam { |
| 50 |
using ok = TPi<Pi>; |
| 51 |
using ok_compat = Pt<TPi<i>, TPi<iDi>, TPi<ii>, TPi<iiPi>>; |
| 52 |
using err1 = TPi<t0>; // expected-error@#TPi {{template argument for template type parameter must be a type}} |
| 53 |
// expected-note@-1 {{different template parameters}} |
| 54 |
using err2 = TPi<iDt>; // expected-error@#TPi {{template argument for template type parameter must be a type}} |
| 55 |
// expected-note@-1 {{different template parameters}} |
| 56 |
using err3 = TPi<it>; // expected-error@#TPi {{template argument for template type parameter must be a type}} |
| 57 |
// expected-note@-1 {{different template parameters}} |
| 58 |
} |
| 59 |
|
| 60 |
namespace IntAndPackParam { |
| 61 |
using ok = TiPi<Pi>; |
| 62 |
using ok_compat = Pt<TiPi<ii>, TiPi<iDi>, TiPi<iiPi>>; |
| 63 |
using err = TiPi<iDi>; |
| 64 |
} |
| 65 |
|
| 66 |
namespace DependentType { |
| 67 |
using ok = Pt<tT0<int, i>, tT0<int, iDi>>; |
| 68 |
using err1 = tT0<int, ii>; // expected-error {{too few template arguments for class template 'ii'}} |
| 69 |
// expected-note@-1 {{different template parameters}} |
| 70 |
using err2 = tT0<short, i>; |
| 71 |
using err2a = tT0<long long, i>; // expected-error@#tT0 {{cannot be narrowed from type 'long long' to 'int'}} |
| 72 |
// expected-note@-1 {{different template parameters}} |
| 73 |
using err2b = tT0<void*, i>; // expected-error@#tT0 {{value of type 'void *' is not implicitly convertible to 'int'}} |
| 74 |
// expected-note@-1 {{different template parameters}} |
| 75 |
using err3 = tT0<short, t0>; // expected-error@#tT0 {{template argument for template type parameter must be a type}} |
| 76 |
// expected-note@-1 {{different template parameters}} |
| 77 |
|
| 78 |
using ok2 = Tt0<t0>; |
| 79 |
using err4 = Tt0<it>; // expected-error@#Tt0 {{template argument for non-type template parameter must be an expression}} |
| 80 |
// expected-note@-1 {{different template parameters}} |
| 81 |
} |
| 82 |
|
| 83 |
namespace Auto { |
| 84 |
template<template<int> typename T> struct TInt {}; // #TInt |
| 85 |
template<template<int*> typename T> struct TIntPtr {}; // #TIntPtr |
| 86 |
template<template<auto> typename T> struct TAuto {}; // #TAuto |
| 87 |
template<template<auto*> typename T> struct TAutoPtr {}; |
| 88 |
template<template<decltype(auto)> typename T> struct TDecltypeAuto {}; // #TDecltypeAuto |
| 89 |
template<auto> struct Auto; |
| 90 |
template<auto*> struct AutoPtr; |
| 91 |
template<decltype(auto)> struct DecltypeAuto; |
| 92 |
template<int> struct Int; |
| 93 |
template<int*> struct IntPtr; |
| 94 |
|
| 95 |
TInt<Auto> ia; |
| 96 |
TInt<AutoPtr> iap; // expected-error@#TInt {{non-type template parameter '' with type 'auto *' has incompatible initializer of type 'int'}} |
| 97 |
// expected-note@-1 {{different template parameters}} |
| 98 |
TInt<DecltypeAuto> ida; |
| 99 |
TInt<Int> ii; |
| 100 |
TInt<IntPtr> iip; // expected-error@#TInt {{conversion from 'int' to 'int *' is not allowed in a converted constant expression}} |
| 101 |
// expected-note@-1 {{different template parameters}} |
| 102 |
|
| 103 |
TIntPtr<Auto> ipa; |
| 104 |
TIntPtr<AutoPtr> ipap; |
| 105 |
TIntPtr<DecltypeAuto> ipda; |
| 106 |
TIntPtr<Int> ipi; // expected-error@#TIntPtr {{value of type 'int *' is not implicitly convertible to 'int'}} |
| 107 |
// expected-note@-1 {{different template parameters}} |
| 108 |
TIntPtr<IntPtr> ipip; |
| 109 |
|
| 110 |
TAuto<Auto> aa; |
| 111 |
TAuto<AutoPtr> aap; // expected-error@#TAuto {{non-type template parameter '' with type 'auto *' has incompatible initializer of type 'auto'}} |
| 112 |
// expected-note@-1 {{different template parameters}} |
| 113 |
TAuto<Int> ai; // FIXME: ill-formed (?) |
| 114 |
TAuto<IntPtr> aip; // FIXME: ill-formed (?) |
| 115 |
|
| 116 |
TAutoPtr<Auto> apa; |
| 117 |
TAutoPtr<AutoPtr> apap; |
| 118 |
TAutoPtr<Int> api; // FIXME: ill-formed (?) |
| 119 |
TAutoPtr<IntPtr> apip; // FIXME: ill-formed (?) |
| 120 |
|
| 121 |
TDecltypeAuto<DecltypeAuto> dada; |
| 122 |
TDecltypeAuto<Int> dai; // FIXME: ill-formed (?) |
| 123 |
TDecltypeAuto<IntPtr> daip; // FIXME: ill-formed (?) |
| 124 |
|
| 125 |
// FIXME: It's completely unclear what should happen here, but these results |
| 126 |
// seem at least plausible: |
| 127 |
TAuto<DecltypeAuto> ada; |
| 128 |
TAutoPtr<DecltypeAuto> apda; |
| 129 |
// Perhaps this case should be invalid, as there are valid 'decltype(auto)' |
| 130 |
// parameters (such as 'user-defined-type &') that are not valid 'auto' |
| 131 |
// parameters. |
| 132 |
TDecltypeAuto<Auto> daa; |
| 133 |
TDecltypeAuto<AutoPtr> daap; // expected-error@#TDecltypeAuto {{non-type template parameter '' with type 'auto *' has incompatible initializer of type 'decltype(auto)'}} |
| 134 |
// expected-note@-1 {{different template parameters}} |
| 135 |
|
| 136 |
int n; |
| 137 |
template<auto A, decltype(A) B = &n> struct SubstFailure; |
| 138 |
TInt<SubstFailure> isf; // FIXME: this should be ill-formed |
| 139 |
TIntPtr<SubstFailure> ipsf; |
| 140 |
} |
| 141 |
|
| 142 |
namespace GH62529 { |
| 143 |
// Note: the constraint here is just for bypassing a fast-path. |
| 144 |
template<class T1> requires(true) using A = int; |
| 145 |
template<template<class ...T2s> class TT1, class T3> struct B {}; |
| 146 |
template<class T4> B<A, T4> f(); |
| 147 |
auto t = f<int>(); |
| 148 |
} // namespace GH62529 |
| 149 |
|
| 150 |
namespace GH101394 { |
| 151 |
struct X {}; // #X |
| 152 |
struct Y { |
| 153 |
constexpr Y(const X &) {} |
| 154 |
}; |
| 155 |
|
| 156 |
namespace t1 { |
| 157 |
template<template<X> class> struct A {}; |
| 158 |
template<Y> struct B; |
| 159 |
template struct A<B>; |
| 160 |
} // namespace t1 |
| 161 |
namespace t2 { |
| 162 |
template<template<Y> class> struct A {}; // #A |
| 163 |
template<X> struct B; // #B |
| 164 |
template struct A<B>; |
| 165 |
// expected-error@#A {{no viable conversion from 'const Y' to 'X'}} |
| 166 |
// expected-note@-2 {{different template parameters}} |
| 167 |
// expected-note@#X 2{{not viable}} |
| 168 |
// expected-note@#B {{passing argument to parameter here}} |
| 169 |
} // namespace t2 |
| 170 |
} // namespace GH101394 |
| 171 |
|
| 172 |
namespace GH181166 { |
| 173 |
template <template <class...> class> struct A; |
| 174 |
template <template <class...> class... TT1> A<TT1...> f(); |
| 175 |
template <class ...Ts> struct B {}; |
| 176 |
using T = decltype(f<B>()); |
| 177 |
} // namespace GH181166 |