xref: /aosp_15_r20/external/clang/test/CXX/temp/temp.param/p11-0x.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2*67e74705SXin Li 
3*67e74705SXin Li // If a template-parameter of a class template or alias template has a default
4*67e74705SXin Li // template-argument, each subsequent template-parameter shall either have a
5*67e74705SXin Li // default template-argument supplied or be a template parameter pack.
6*67e74705SXin Li template<typename> struct vector;
7*67e74705SXin Li 
8*67e74705SXin Li template<typename T = int, typename> struct X3t; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
9*67e74705SXin Li template<typename T = int, typename> using A3t = int; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
10*67e74705SXin Li template<int V = 0, int> struct X3nt; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
11*67e74705SXin Li template<int V = 0, int> using A3nt = int; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
12*67e74705SXin Li template<template<class> class M = vector, template<class> class> struct X3tt; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
13*67e74705SXin Li template<template<class> class M = vector, template<class> class> using A3tt = int; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}}
14*67e74705SXin Li 
15*67e74705SXin Li template<typename T = int, typename ...Types> struct X2t;
16*67e74705SXin Li template<typename T = int, typename ...Types> using A2t = X2t<T, Types...>;
17*67e74705SXin Li template<int V = 0, int ...Values> struct X2nt;
18*67e74705SXin Li template<int V = 0, int ...Values> using A2nt = X2nt<V, Values...>;
19*67e74705SXin Li template<template<class> class M = vector, template<class> class... Metas>
20*67e74705SXin Li   struct X2tt;
21*67e74705SXin Li template<template<class> class M = vector, template<class> class... Metas>
22*67e74705SXin Li   using A2tt = X2tt<M, Metas...>;
23*67e74705SXin Li 
24*67e74705SXin Li // If a template-parameter of a primary class template or alias template is a
25*67e74705SXin Li // template parameter pack, it shall be the last template-parameter.
26*67e74705SXin Li template<typename ...Types, // expected-error{{template parameter pack must be the last template parameter}}
27*67e74705SXin Li          int After, int After2>
28*67e74705SXin Li struct X0t;
29*67e74705SXin Li X0t<int> pr9789();
30*67e74705SXin Li template<typename ...Types, // expected-error{{template parameter pack must be the last template parameter}}
31*67e74705SXin Li          int After>
32*67e74705SXin Li using A0t = int;
33*67e74705SXin Li 
34*67e74705SXin Li template<int ...Values, // expected-error{{template parameter pack must be the last template parameter}}
35*67e74705SXin Li          int After>
36*67e74705SXin Li struct X0nt;
37*67e74705SXin Li template<int ...Values, // expected-error{{template parameter pack must be the last template parameter}}
38*67e74705SXin Li          int After>
39*67e74705SXin Li using A0nt = int;
40*67e74705SXin Li 
41*67e74705SXin Li template<template<typename> class ...Templates, // expected-error{{template parameter pack must be the last template parameter}}
42*67e74705SXin Li          int After>
43*67e74705SXin Li struct X0tt;
44*67e74705SXin Li template<template<typename> class ...Templates, // expected-error{{template parameter pack must be the last template parameter}}
45*67e74705SXin Li          int After>
46*67e74705SXin Li using A0tt = int;
47*67e74705SXin Li 
48*67e74705SXin Li // [ Note: These are not requirements for function templates or class
49*67e74705SXin Li // template partial specializations because template arguments can be
50*67e74705SXin Li // deduced (14.8.2). -- end note]
51*67e74705SXin Li template<typename... Types> struct X1t;
52*67e74705SXin Li template<typename ...Types, typename T> struct X1t<T, Types...> { };
53*67e74705SXin Li 
54*67e74705SXin Li template<int... Values> struct X1nt;
55*67e74705SXin Li template<int ...Values, int V> struct X1nt<V, Values...> { };
56*67e74705SXin Li 
57*67e74705SXin Li template<template<int> class... Meta> struct X1tt;
58*67e74705SXin Li template<template<int> class... Meta, template<int> class M>
59*67e74705SXin Li   struct X1tt<M, Meta...> { };
60*67e74705SXin Li 
61*67e74705SXin Li template<typename ...Types, typename T>
62*67e74705SXin Li void f1t(X1t<T, Types...>);
63*67e74705SXin Li 
64*67e74705SXin Li template<int ...Values, int V>
65*67e74705SXin Li void f1nt(X1nt<V, Values...>);
66*67e74705SXin Li 
67*67e74705SXin Li template<template<int> class... Meta, template<int> class M>
68*67e74705SXin Li void f1tt(X1tt<M, Meta...>);
69*67e74705SXin Li 
70*67e74705SXin Li namespace DefaultTemplateArgsInFunction {
f0(U)71*67e74705SXin Li   template<typename T = int, typename U>  T &f0(U) { T *x = 0; return *x; }
72*67e74705SXin Li 
test_f0()73*67e74705SXin Li   void test_f0() {
74*67e74705SXin Li     int &ir0 = f0(3.14159);
75*67e74705SXin Li     int &ir1 = f0<int>(3.14159);
76*67e74705SXin Li     float &fr0 = f0<float>(3.14159);
77*67e74705SXin Li   }
78*67e74705SXin Li 
79*67e74705SXin Li   template<> int &f0(int*);
80*67e74705SXin Li   template int &f0(double&);
81*67e74705SXin Li }
82