xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/temp_arg_template.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc template<template<typename T> class X> struct A; // expected-note 2{{previous template template parameter is here}}
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc template<template<typename T, int I> class X> struct B; // expected-note{{previous template template parameter is here}}
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc template<template<int I> class X> struct C;  // expected-note{{previous non-type template parameter with type 'int' is here}}
8*f4a2713aSLionel Sambuc 
9*f4a2713aSLionel Sambuc template<class> struct X; // expected-note{{too few template parameters in template template argument}}
10*f4a2713aSLionel Sambuc template<int N> struct Y; // expected-note{{template parameter has a different kind in template argument}}
11*f4a2713aSLionel Sambuc template<long N> struct Ylong; // expected-note{{template non-type parameter has a different type 'long' in template argument}}
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc namespace N {
14*f4a2713aSLionel Sambuc   template<class> struct Z;
15*f4a2713aSLionel Sambuc }
16*f4a2713aSLionel Sambuc template<class, class> struct TooMany; // expected-note{{too many template parameters in template template argument}}
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc A<X> *a1;
20*f4a2713aSLionel Sambuc A<N::Z> *a2;
21*f4a2713aSLionel Sambuc A< ::N::Z> *a3;
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc A<Y> *a4; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
24*f4a2713aSLionel Sambuc A<TooMany> *a5; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
25*f4a2713aSLionel Sambuc B<X> *a6; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
26*f4a2713aSLionel Sambuc C<Y> *a7;
27*f4a2713aSLionel Sambuc C<Ylong> *a8; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc template<typename T> void f(int);
30*f4a2713aSLionel Sambuc 
31*f4a2713aSLionel Sambuc A<f> *a9; // expected-error{{must be a class template}}
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc // Evil digraph '<:' is parsed as '[', expect error.
34*f4a2713aSLionel Sambuc A<::N::Z> *a10; // expected-error{{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
35*f4a2713aSLionel Sambuc 
36*f4a2713aSLionel Sambuc // Do not do a digraph correction here.
37*f4a2713aSLionel Sambuc A<: :N::Z> *a11;  // expected-error{{expected expression}} \
38*f4a2713aSLionel Sambuc           expected-error{{C++ requires a type specifier for all declarations}}
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc // PR7807
41*f4a2713aSLionel Sambuc namespace N {
42*f4a2713aSLionel Sambuc   template <typename, typename = int>
43*f4a2713aSLionel Sambuc   struct X
44*f4a2713aSLionel Sambuc   { };
45*f4a2713aSLionel Sambuc 
46*f4a2713aSLionel Sambuc   template <typename ,int>
47*f4a2713aSLionel Sambuc   struct Y
48*f4a2713aSLionel Sambuc   { X<int> const_ref(); };
49*f4a2713aSLionel Sambuc 
50*f4a2713aSLionel Sambuc   template <template<typename,int> class TT, typename T, int N>
51*f4a2713aSLionel Sambuc   int operator<<(int, TT<T, N> a) { // expected-note{{candidate template ignored}}
52*f4a2713aSLionel Sambuc     0 << a.const_ref(); // expected-error{{invalid operands to binary expression ('int' and 'X<int>')}}
53*f4a2713aSLionel Sambuc   }
54*f4a2713aSLionel Sambuc 
55*f4a2713aSLionel Sambuc   void f0( Y<int,1> y){ 1 << y; } // expected-note{{in instantiation of function template specialization 'N::operator<<<Y, int, 1>' requested here}}
56*f4a2713aSLionel Sambuc }
57*f4a2713aSLionel Sambuc 
58*f4a2713aSLionel Sambuc // PR12179
59*f4a2713aSLionel Sambuc template <typename Primitive, template <Primitive...> class F> // expected-warning {{variadic templates are a C++11 extension}}
60*f4a2713aSLionel Sambuc struct unbox_args {
61*f4a2713aSLionel Sambuc   typedef typename Primitive::template call<F> x;
62*f4a2713aSLionel Sambuc };
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc template <template <typename> class... Templates> // expected-warning {{variadic templates are a C++11 extension}}
65*f4a2713aSLionel Sambuc struct template_tuple {};
66*f4a2713aSLionel Sambuc template <typename T>
67*f4a2713aSLionel Sambuc struct identity {};
68*f4a2713aSLionel Sambuc template <template <typename> class... Templates> // expected-warning {{variadic templates are a C++11 extension}}
69*f4a2713aSLionel Sambuc template_tuple<Templates...> f7() {}
70*f4a2713aSLionel Sambuc 
71*f4a2713aSLionel Sambuc void foo() {
72*f4a2713aSLionel Sambuc   f7<identity>();
73*f4a2713aSLionel Sambuc }
74