194 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx17 %std_cxx98-14 %s2// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx17 -std=c++17 %s3 4template<template<typename T> class X> struct A; // #A5// expected-note@-1 2{{previous template template parameter is here}}6 7template<template<typename T, int I> class X> struct B; // expected-note{{previous template template parameter is here}}8 9template<template<int I> class X> struct C;10// expected-error@-1 {{conversion from 'int' to 'const int &' in converted constant expression would bind reference to a temporary}}11// expected-note@-2 {{previous template template parameter is here}}12 13template<class> struct X; // expected-note {{template is declared here}}14template<int N> struct Y; // expected-note {{template parameter is declared here}}15template<long N> struct Ylong;16template<const int &N> struct Yref; // expected-note {{template parameter is declared here}}17 18namespace N {19 template<class> struct Z;20}21template<class, class> struct TooMany; // expected-note{{template is declared here}}22 23 24A<X> *a1;25A<N::Z> *a2;26A< ::N::Z> *a3;27 28A<Y> *a4; // expected-error@#A {{template argument for non-type template parameter must be an expression}}29 // expected-note@-1 {{different template parameters}}30A<TooMany> *a5; // expected-error {{too few template arguments for class template 'TooMany'}}31 // expected-note@-1 {{different template parameters}}32B<X> *a6; // expected-error {{too many template arguments for class template 'X'}}33 // expected-note@-1 {{different template parameters}}34C<Y> *a7;35C<Ylong> *a8;36C<Yref> *a9; // expected-note {{different template parameters}}37 38template<typename T> void f(int);39 40A<f> *a9; // expected-error{{must be a class template}}41 42// Evil digraph '<:' is parsed as '[', expect error.43A<::N::Z> *a10;44#if __cplusplus <= 199711L45// expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}46#endif47 48// Do not do a digraph correction here.49A<: :N::Z> *a11; // expected-error{{expected expression}} \50 precxx17-error{{a type specifier is required for all declarations}} \51 cxx17-error{{expected unqualified-id}}52 53// PR780754namespace N {55 template <typename, typename = int>56 struct X57 { };58 59 template <typename ,int>60 struct Y61 { X<int> const_ref(); };62 63 template <template<typename,int> class TT, typename T, int N>64 int operator<<(int, TT<T, N> a) { // expected-note{{candidate template ignored}}65 0 << a.const_ref(); // expected-error{{invalid operands to binary expression ('int' and 'X<int>')}}66 }67 68 void f0( Y<int,1> y){ 1 << y; } // expected-note{{in instantiation of function template specialization 'N::operator<<<N::Y, int, 1>' requested here}}69}70 71// PR1217972template <typename Primitive, template <Primitive...> class F>73#if __cplusplus <= 199711L74// expected-warning@-2 {{variadic templates are a C++11 extension}}75#endif76 77struct unbox_args {78 typedef typename Primitive::template call<F> x;79};80 81template <template <typename> class... Templates>82#if __cplusplus <= 199711L83// expected-warning@-2 {{variadic templates are a C++11 extension}}84#endif85 86struct template_tuple {87#if __cplusplus >= 201103L88 static constexpr int N = sizeof...(Templates);89#endif90};91template <typename T>92struct identity {};93template <template <typename> class... Templates>94#if __cplusplus <= 199711L95// expected-warning@-2 {{variadic templates are a C++11 extension}}96#endif97 98template_tuple<Templates...> f7() {}99 100#if __cplusplus >= 201103L101struct S : public template_tuple<identity, identity> {102 static_assert(N == 2, "Number of template arguments incorrect");103};104#endif105 106void foo() {107 f7<identity>();108}109 110namespace CheckDependentNonTypeParamTypes {111 template<template<typename T, typename U, T v> class X> struct A {112 // expected-note@-1 {{previous template template parameter is here}}113 void f() {114 X<int, void*, 3> x;115 }116 void g() {117 X<int, long, 3> x;118 }119 void h() {120 X<unsigned char, int, 1234> x;121 // expected-error@-1 {{evaluates to 1234, which cannot be narrowed to type 'unsigned char'}}122 }123 };124 125 template<typename T, typename U, U v> struct B {126 // expected-error@-1 {{conflicting deduction 'U' against 'T' for parameter}}127 static const U value = v;128 };129 130 // FIXME: This should probably be rejected, but the rules are at best unclear.131 A<B> ab; // expected-note {{different template parameters}}132 133 void use() {134 ab.f();135 ab.g();136 ab.h();137 }138 139 template<class> struct C {140 template<class T, T V> struct D {};141 using T = D<char, 1234>;142 // expected-error@-1 {{evaluates to 1234, which cannot be narrowed to type 'char'}}143 };144 145 template<class T> struct E {146 template <template <T V> class TT> struct F {147 using X = TT<1234>;148 };149 };150 // FIXME: This should be rejected, as there are no valid instantiations for E<char>::F151 template struct E<char>;152 153#if __cplusplus >= 201703L154 template<template<auto> class TT, class V> struct G {155 using type = TT<((void)0, V::value)>;156 };157#endif158}159 160namespace PR32185 {161 template<template<typename T, T> class U> struct A {};162 template<template<typename T, T> class U> struct B : A<U> {};163}164 165namespace PR10147 {166 template<typename T> struct A {};167 template<typename T = int> struct A;168 template<template<typename...> class A> void f(A<int>*) { A<> a; } // expected-warning 0-1{{extension}}169 void g() { f((A<>*)0); }170}171 172#if __cplusplus >= 201703L173namespace multiple_conversions {174 constexpr int g = 1;175 struct Z {176 constexpr operator const int&() const { return g; }177 constexpr operator int() { return 2; }178 } z;179 180 template<template<const int&> class TT> struct A {181 static constexpr int value = TT<z>::value;182 };183 184 template<int I> struct B {185 static constexpr int value = I;186 };187 // FIXME: This should probably convert z to (const int &) first, then188 // convert that to int.189 static_assert(A<B>::value == 1);190 // cxx17-error@-1 {{static assertion failed}}191 // cxx17-note@-2 {{expression evaluates to '2 == 1'}}192} // namespace multiple_conversions193#endif194