• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4 
5 template<template<typename T> class X> struct A; // expected-note 2{{previous template template parameter is here}}
6 
7 template<template<typename T, int I> class X> struct B; // expected-note{{previous template template parameter is here}}
8 
9 template<template<int I> class X> struct C;  // expected-note{{previous non-type template parameter with type 'int' is here}}
10 
11 template<class> struct X; // expected-note{{too few template parameters in template template argument}}
12 template<int N> struct Y; // expected-note{{template parameter has a different kind in template argument}}
13 template<long N> struct Ylong; // expected-note{{template non-type parameter has a different type 'long' in template argument}}
14 
15 namespace N {
16   template<class> struct Z;
17 }
18 template<class, class> struct TooMany; // expected-note{{too many template parameters in template template argument}}
19 
20 
21 A<X> *a1;
22 A<N::Z> *a2;
23 A< ::N::Z> *a3;
24 
25 A<Y> *a4; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
26 A<TooMany> *a5; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
27 B<X> *a6; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
28 C<Y> *a7;
29 C<Ylong> *a8; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
30 
31 template<typename T> void f(int);
32 
33 A<f> *a9; // expected-error{{must be a class template}}
34 
35 // Evil digraph '<:' is parsed as '[', expect error.
36 A<::N::Z> *a10;
37 #if __cplusplus <= 199711L
38 // expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
39 #endif
40 
41 // Do not do a digraph correction here.
42 A<: :N::Z> *a11;  // expected-error{{expected expression}} \
43           expected-error{{C++ requires a type specifier for all declarations}}
44 
45 // PR7807
46 namespace N {
47   template <typename, typename = int>
48   struct X
49   { };
50 
51   template <typename ,int>
52   struct Y
53   { X<int> const_ref(); };
54 
55   template <template<typename,int> class TT, typename T, int N>
56   int operator<<(int, TT<T, N> a) { // expected-note{{candidate template ignored}}
57     0 << a.const_ref(); // expected-error{{invalid operands to binary expression ('int' and 'X<int>')}}
58   }
59 
60   void f0( Y<int,1> y){ 1 << y; } // expected-note{{in instantiation of function template specialization 'N::operator<<<Y, int, 1>' requested here}}
61 }
62 
63 // PR12179
64 template <typename Primitive, template <Primitive...> class F>
65 #if __cplusplus <= 199711L
66 // expected-warning@-2 {{variadic templates are a C++11 extension}}
67 #endif
68 
69 struct unbox_args {
70   typedef typename Primitive::template call<F> x;
71 };
72 
73 template <template <typename> class... Templates>
74 #if __cplusplus <= 199711L
75 // expected-warning@-2 {{variadic templates are a C++11 extension}}
76 #endif
77 
78 struct template_tuple {
79 #if __cplusplus >= 201103L
80   static constexpr int N = sizeof...(Templates);
81 #endif
82 };
83 template <typename T>
84 struct identity {};
85 template <template <typename> class... Templates>
86 #if __cplusplus <= 199711L
87 // expected-warning@-2 {{variadic templates are a C++11 extension}}
88 #endif
89 
90 template_tuple<Templates...> f7() {}
91 
92 #if __cplusplus >= 201103L
93 struct S : public template_tuple<identity, identity> {
94   static_assert(N == 2, "Number of template arguments incorrect");
95 };
96 #endif
97 
98 void foo() {
99   f7<identity>();
100 }
101