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