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